Get Image using API

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • joostk
    replied
    Works great! Thanks

    Leave a comment:


  • rabii
    replied
    Originally posted by joostk
    Dear,

    Im trying to get the image of an record via the API. All data comes in except the image:

    I have tried: https://docs.espocrm.com/development/api/attachment/ without success.

    This is the script:

    Code:
    // Fetch product information
    $response = $client->request('GET', 'Product');
    
    if (!$response || !isset($response['list'][0])) {
    die("Failed to retrieve product information.");
    }
    
    $product = $response['list'][0];
    
    $imageUrl = $url . "/api/v1/Attachment/file/" . $product['id'];
    You should provide the id of the image to the endpoint like below:

    PHP Code:
    // Fetch product information
    $response $client->request('GET''Product');

    if (!
    $response || !isset($response['list'][0])) {
    die(
    "Failed to retrieve product information.");
    }

    $product $response['list'][0];

    $imageUrl $url "/api/v1/Attachment/file/" $product['image_id']; // replace image with name of the field where you store the product image. ​ 
    Also it is much easier to espocrm/php-espo-api-client in your project.

    Leave a comment:


  • Jakub Grufik
    commented on 's reply
    The request in your code will basically look similar to this: $imageUrl = $url . "/api/v1/Attachment/file/" . $product['imageId']; where "imageId" is the name of the field you have added to upload the photo of the product make sure you will use imageId not just image
    Last edited by Jakub Grufik; 09-13-2023, 01:22 PM.

  • Jakub Grufik
    commented on 's reply
    Aight, then go to random product open its detail and then change the URL to this one https://your_crm_url.eu/api/v1/Produ...of_the_product and over there you will find the id of the image you are looking for and then you can use this ID in the API request to get the attachment

  • joostk
    replied
    Thanks for your reply.

    The entity i want to get an image from is the Product entity from the salespack extension. I have added an field in the entity to upload an image with the product.

    Again thanks!

    Leave a comment:


  • Jakub Grufik
    replied
    Hello, what exactly do you mean by image of an record? What is the records entity type? Also in the code where you are trying to get an attechment via API you need to use ID of the attachment not the ID of the product itself.

    Leave a comment:


  • joostk
    started a topic Get Image using API

    Get Image using API

    Dear,

    Im trying to get the image of an record via the API. All data comes in except the image:

    I have tried: https://docs.espocrm.com/development/api/attachment/ without success.

    This is the script:

    Code:
    // Fetch product information
    $response = $client->request('GET', 'Product');
    
    if (!$response || !isset($response['list'][0])) {
    die("Failed to retrieve product information.");
    }
    
    $product = $response['list'][0];
    
    $imageUrl = $url . "/api/v1/Attachment/file/" . $product['id'];
Working...