Announcement

Collapse
No announcement yet.

Get Image using API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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'];

  • #2
    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.

    Comment


    • #3
      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!

      Comment


      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        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

      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        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.

    • #4
      Originally posted by joostk View Post
      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.

      Comment


      • #5
        Works great! Thanks

        Comment

        Working...
        X