# PHP SDK usage - json response

**URL:** <https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850>\
**Category:** Questions\
**Tags:** catalog-api\
**Created:** [September 23, 2024, 7:50am UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850 "2024-09-23T07:50:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![verdant\_spark](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/verdant_spark/32/7535_2.png) [@verdant\_spark](https://developer.squareup.com/forums/u/verdant_spark)\
**Post date:** [September 23, 2024, 7:50am UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850/1 "2024-09-23T07:50:10Z")

</div>

I’m trying to create a basic app which can pull image URLs for catalog items. I have the PHP SDK running and can successfully query the API for a catalog item, but the response I’m getting is (a) not json (I’d like to know how to get json data instead of all the objects returned), and (b) doesn’t seem to have imageData for items which definitely have images.

Any pointers on how to just grab image URLs for items and get the response as json?!

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [September 23, 2024, 7:50am UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850/2 "2024-09-23T07:50:33Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Work with Images](https://developer.squareup.com/docs/catalog-api/cookbook/create-catalog-image)**
>
> Use the Catalog API to upload images for your product catalog.

> **[Manage Images in a Square Catalog](https://developer.squareup.com/docs/catalog-api/manage-images)**
>
> Learn how to manage uploaded images using the Square Catalog API.

> **Additional Documentation**
>
> [Catalog API](https://developer.squareup.com/docs/catalog-api/what-it-does)  
> [Upload and Attach Images](https://developer.squareup.com/docs/catalog-api/upload-and-attach-images)  
> [Search for Items and Objects](https://developer.squareup.com/docs/catalog-api/search-catalog)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [September 23, 2024, 4:35pm UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850/3 "2024-09-23T16:35:56Z")

</div>

To retrieve image URLs for catalog items using the PHP SDK, you need to use the Catalog API’s `RetrieveCatalogObject` endpoint. This endpoint allows you to retrieve a catalog object along with all of its associated information, including images.

However, the PHP SDK returns data as PHP objects, not JSON. If you want to convert the response to JSON, you can use PHP’s built-in `json_encode` function. Here’s a basic example:

```php
$api_response = $client->getCatalogApi()->retrieveCatalogObject($object_id, true);
$json_response = json_encode($api_response->getResult());

```

In this example, `$object_id` is the ID of the catalog object you want to retrieve. The second parameter `true` is for the `include_related_objects` option, which tells the API to include all related objects in the response, including images.

The image URLs can be found in the `image_data` field of the `CatalogImage` objects associated with the catalog object. You can access them like this:

```php
$catalog_object = $api_response->getResult()->getObject();
if ($catalog_object->getType() == 'IMAGE') {
    $image_url = $catalog_object->getImageData()->getUrl();
}

```

Remember to replace `$object_id` with the actual ID of the catalog object you want to retrieve. Also, ensure that the catalog object has images associated with it, otherwise the `getImageData()` method will return `null`.

_This answer was reviewed by @Bryan-Square._

---

<div class="post-metadata">

**Author:** ![verdant\_spark](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/verdant_spark/32/7535_2.png) [@verdant\_spark](https://developer.squareup.com/forums/u/verdant_spark)\
**Post date:** [November 16, 2024, 8:30pm UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850/4 "2024-11-16T20:30:57Z")

</div>

I’m picking this back up again - still no joy here.

I have a method to make a request to the API like this:

```auto
public function getSquareProps( $client, $square_token ) {

    try {

      $apiResponse = $client->getCatalogApi()->retrieveCatalogObject( $square_token, true, null, true );

      if ( $apiResponse->isSuccess() ) {
        return $apiResponse->getResult();
      }
      else {
        $errors = $apiResponse->getErrors();
        log_message( 'error', json_encode( $errors ) );
        return false;
      }

    }
    catch ( ApiException $e ) {
      echo "ApiException occurred: <b/>";
      echo $e->getMessage() . "<p/>";
      return false;
    }

  }

```

This seems to be working, **but** , I’m not getting any image URLs in the responses, even when the catalogue item has images in Square.

Example response:

```auto
{
    "object": {
        "type": "ITEM_VARIATION",
        "id": "OC3RKNHZRVUT327ZQD5T27XK",
        "updated_at": "2024-11-05T10:34:31.285Z",
        "version": 1730802871285,
        "is_deleted": false,
        "present_at_all_locations": true,
        "item_variation_data": {
            "item_id": "RBLOQQDBTU3YDB525OKQKFCM",
            "name": "",
            "sku": "8260626",
            "upc": "9783740814762",
            "ordinal": 1,
            "pricing_type": "FIXED_PRICING",
            "price_money": {
                "amount": 1399,
                "currency": "GBP"
            },
            "location_overrides": [
                {
                    "location_id": "LC045GCPXTEQY",
                    "track_inventory": true
                }
            ],
            "track_inventory": true,
            "inventory_alert_type": "NONE",
            "sellable": true,
            "stockable": true
        }
    },
    "related_objects": [
        {
            "type": "ITEM",
            "id": "RBLOQQDBTU3YDB525OKQKFCM",
            "updated_at": "2024-11-05T10:34:31.285Z",
            "version": 1730802871285,
            "is_deleted": false,
            "custom_attribute_values": {
                "sq0idp-w46nJ_NCNDMSOywaCY0mwA:ecom_gifting_enabled": {
                    "name": "Ecom Gifting Enabled",
                    "custom_attribute_definition_id": "SUVNEPWVWH523WZMJKNAXCHB",
                    "type": "BOOLEAN",
                    "boolean_value": true,
                    "key": "sq0idp-w46nJ_NCNDMSOywaCY0mwA:ecom_gifting_enabled"
                }
            },
            "present_at_all_locations": true,
            "item_data": {
                "name": "111 Places in Edinburgh",
                "description": "This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique",
                "is_taxable": true,
                "available_online": false,
                "available_for_pickup": false,
                "available_electronically": false,
                "variations": [
                    {
                        "type": "ITEM_VARIATION",
                        "id": "OC3RKNHZRVUT327ZQD5T27XK",
                        "updated_at": "2024-11-05T10:34:31.285Z",
                        "version": 1730802871285,
                        "is_deleted": false,
                        "present_at_all_locations": true,
                        "item_variation_data": {
                            "item_id": "RBLOQQDBTU3YDB525OKQKFCM",
                            "name": "",
                            "sku": "8260626",
                            "upc": "9783740814762",
                            "ordinal": 1,
                            "pricing_type": "FIXED_PRICING",
                            "price_money": {
                                "amount": 1399,
                                "currency": "GBP"
                            },
                            "location_overrides": [
                                {
                                    "location_id": "LC045GCPXTEQY",
                                    "track_inventory": true
                                }
                            ],
                            "track_inventory": true,
                            "inventory_alert_type": "NONE",
                            "sellable": true,
                            "stockable": true
                        }
                    }
                ],
                "product_type": "REGULAR",
                "skip_modifier_screen": true,
                "image_ids": [
                    "77KD5QJNYUTHKSKYILYHCAWZ",
                    "5MFLTBJZEIF4PMBJSQ3DRUGT",
                    "7HJFHNSJ32PUECPGGWMFOU4T",
                    "2WYGJEXYFZSVDURFWOH5Y25C"
                ],
                "categories": [
                    {
                        "id": "M23PYY6GTR73PGF7V25WMLKN",
                        "ordinal": 2954937499648
                    },
                    {
                        "id": "2F6THZBNTAWBGV5RXB7QA5M4",
                        "ordinal": 120316
                    },
                    {
                        "id": "HLSK5ZVI5YWZOCXX6J456QDV",
                        "ordinal": 2810162
                    }
                ],
                "description_html": "<p>This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique <\/p>",
                "description_plaintext": "This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique",
                "channels": [
                    "CH_wYG80B8Mc4XMb3VHdzF4iPGPzVWtApTTwwvfYRlQuYC",
                    "CH_DbRkdm8P1PgFUo8YHzF4iPGPzVWtApTTwwvfYRlQuYC"
                ],
                "is_archived": false,
                "ecom_seo_data": {
                    "page_title": "111 Places in Edinburgh Book | Gift Shop Edinburgh",
                    "page_description": "The 111 places in Edinburgh book is a guide to some of the best places to see in Edinburgh.",
                    "permalink": "111-places-in-edinburgh-travel-guide-book"
                },
                "reporting_category": {
                    "id": "M23PYY6GTR73PGF7V25WMLKN",
                    "ordinal": 2954937499648
                }
            }
        }
    ]
}

```

Compare the above to the same request being made using the API explorer:

```auto
{
  "object": {
    "type": "ITEM_VARIATION",
    "id": "OC3RKNHZRVUT327ZQD5T27XK",
    "updated_at": "2024-11-05T10:34:31.285Z",
    "created_at": "2022-03-23T18:30:27.298Z",
    "version": 1730802871285,
    "is_deleted": false,
    "present_at_all_locations": true,
    "item_variation_data": {
      "item_id": "RBLOQQDBTU3YDB525OKQKFCM",
      "name": "",
      "sku": "8260626",
      "upc": "9783740814762",
      "ordinal": 1,
      "pricing_type": "FIXED_PRICING",
      "price_money": {
        "amount": 1399,
        "currency": "GBP"
      },
      "location_overrides": [
        {
          "location_id": "LC045GCPXTEQY",
          "track_inventory": true
        }
      ],
      "track_inventory": true,
      "inventory_alert_type": "NONE",
      "sellable": true,
      "stockable": true,
      "default_unit_cost": {
        "amount": 839,
        "currency": "GBP"
      },
      "channels": [
        "CH_DbRkdm8P1PgFUo8YHzF4iPGPzVWtApTTwwvfYRlQuYC",
        "CH_wYG80B8Mc4XMb3VHdzF4iPGPzVWtApTTwwvfYRlQuYC"
      ],
      "item_variation_vendor_info_ids": [
        "E25LRO2ZSLFCTOIPJH26XLMU"
      ],
      "item_variation_vendor_infos": [
        {
          "type": "ITEM_VARIATION_VENDOR_INFO",
          "id": "E25LRO2ZSLFCTOIPJH26XLMU",
          "updated_at": "2024-11-05T10:34:31.285Z",
          "created_at": "2022-03-23T18:32:00.71Z",
          "version": 1730802871285,
          "is_deleted": false,
          "present_at_all_locations": true,
          "item_variation_vendor_info_data": {
            "ordinal": 0,
            "price_money": {
              "amount": 839,
              "currency": "GBP"
            },
            "item_variation_id": "OC3RKNHZRVUT327ZQD5T27XK",
            "vendor_id": "DFOH472UUZENRPZW"
          }
        }
      ]
    }
  },
  "related_objects": [
    {
      "type": "ITEM",
      "id": "RBLOQQDBTU3YDB525OKQKFCM",
      "updated_at": "2024-11-05T10:34:31.285Z",
      "created_at": "2022-03-23T18:30:27.298Z",
      "version": 1730802871285,
      "is_deleted": false,
      "custom_attribute_values": {
        "sq0idp-w46nJ_NCNDMSOywaCY0mwA:ecom_gifting_enabled": {
          "name": "Ecom Gifting Enabled",
          "custom_attribute_definition_id": "SUVNEPWVWH523WZMJKNAXCHB",
          "type": "BOOLEAN",
          "boolean_value": true,
          "key": "sq0idp-w46nJ_NCNDMSOywaCY0mwA:ecom_gifting_enabled"
        }
      },
      "present_at_all_locations": true,
      "item_data": {
        "name": "111 Places in Edinburgh",
        "description": "This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique",
        "is_taxable": true,
        "visibility": "PRIVATE",
        "available_online": false,
        "available_for_pickup": false,
        "available_electronically": false,
        "variations": [
          {
            "type": "ITEM_VARIATION",
            "id": "OC3RKNHZRVUT327ZQD5T27XK",
            "updated_at": "2024-11-05T10:34:31.285Z",
            "created_at": "2022-03-23T18:30:27.298Z",
            "version": 1730802871285,
            "is_deleted": false,
            "present_at_all_locations": true,
            "item_variation_data": {
              "item_id": "RBLOQQDBTU3YDB525OKQKFCM",
              "name": "",
              "sku": "8260626",
              "upc": "9783740814762",
              "ordinal": 1,
              "pricing_type": "FIXED_PRICING",
              "price_money": {
                "amount": 1399,
                "currency": "GBP"
              },
              "location_overrides": [
                {
                  "location_id": "LC045GCPXTEQY",
                  "track_inventory": true
                }
              ],
              "track_inventory": true,
              "inventory_alert_type": "NONE",
              "sellable": true,
              "stockable": true,
              "default_unit_cost": {
                "amount": 839,
                "currency": "GBP"
              },
              "channels": [
                "CH_DbRkdm8P1PgFUo8YHzF4iPGPzVWtApTTwwvfYRlQuYC",
                "CH_wYG80B8Mc4XMb3VHdzF4iPGPzVWtApTTwwvfYRlQuYC"
              ],
              "item_variation_vendor_info_ids": [
                "E25LRO2ZSLFCTOIPJH26XLMU"
              ],
              "item_variation_vendor_infos": [
                {
                  "type": "ITEM_VARIATION_VENDOR_INFO",
                  "id": "E25LRO2ZSLFCTOIPJH26XLMU",
                  "updated_at": "2024-11-05T10:34:31.285Z",
                  "created_at": "2022-03-23T18:32:00.71Z",
                  "version": 1730802871285,
                  "is_deleted": false,
                  "present_at_all_locations": true,
                  "item_variation_vendor_info_data": {
                    "ordinal": 0,
                    "price_money": {
                      "amount": 839,
                      "currency": "GBP"
                    },
                    "item_variation_id": "OC3RKNHZRVUT327ZQD5T27XK",
                    "vendor_id": "DFOH472UUZENRPZW"
                  }
                }
              ]
            }
          }
        ],
        "product_type": "REGULAR",
        "skip_modifier_screen": true,
        "ecom_uri": "https://www.example.com/product/111-places-in-edinburgh-travel-guide-book/21",
        "ecom_image_uris": [
          "https://www.example.com/uploads/1/4/1/2/141295149/s482407285242066437_p21_i6_w1279.jpeg",
          "https://www.example.com/uploads/1/4/1/2/141295149/s482407285242066437_p21_i7_w1594.jpeg",
          "https://www.example.com/uploads/1/4/1/2/141295149/s482407285242066437_p21_i8_w1594.jpeg",
          "https://www.example.com/uploads/1/4/1/2/141295149/s482407285242066437_p21_i9_w1594.jpeg"
        ],
        "ecom_available": true,
        "ecom_visibility": "VISIBLE",
        "image_ids": [
          "77KD5QJNYUTHKSKYILYHCAWZ",
          "5MFLTBJZEIF4PMBJSQ3DRUGT",
          "7HJFHNSJ32PUECPGGWMFOU4T",
          "2WYGJEXYFZSVDURFWOH5Y25C"
        ],
        "categories": [
          {
            "id": "M23PYY6GTR73PGF7V25WMLKN",
            "ordinal": 2954937499648
          },
          {
            "id": "2F6THZBNTAWBGV5RXB7QA5M4",
            "ordinal": 120316
          },
          {
            "id": "HLSK5ZVI5YWZOCXX6J456QDV",
            "ordinal": 2810162
          }
        ],
        "pickup_fulfillment_preferences_id": "fprefs_127cj2koz85ya0z0vzjkm2fhd",
        "delivery_fulfillment_preferences_id": "fprefs_127k2et792iachyxqqbglolo5",
        "description_html": "<p>This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique </p>",
        "description_plaintext": "This book takes the discerning visitor to hidden corners and secret sights in this city of contrasts, exploring fascinating locations unknown even to most residents, and revealing unexpected aspects of some familiar local landmarks. Marvel at a unique",
        "channels": [
          "CH_wYG80B8Mc4XMb3VHdzF4iPGPzVWtApTTwwvfYRlQuYC",
          "CH_DbRkdm8P1PgFUo8YHzF4iPGPzVWtApTTwwvfYRlQuYC"
        ],
        "shipping_fulfillment_preferences_id": "fprefs_127kfdiun899e3m2e23i3u98j",
        "dine_in_fulfillment_preferences_id": "fprefs_127tnhil7mj6bm56mbrnsowxg",
        "is_archived": false,
        "ecom_seo_data": {
          "page_title": "111 Places in Edinburgh Book | Gift Shop Edinburgh",
          "page_description": "The 111 places in Edinburgh book is a guide to some of the best places to see in Edinburgh.",
          "permalink": "111-places-in-edinburgh-travel-guide-book"
        },
        "reporting_category": {
          "id": "M23PYY6GTR73PGF7V25WMLKN",
          "ordinal": 2954937499648
        }
      }
    }
  ]
}

```

Why does the explorer return the ecom\_image\_uris but the API doesn’t?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [November 18, 2024, 4:52pm UTC](https://developer.squareup.com/forums/t/php-sdk-usage-json-response/18850/5 "2024-11-18T16:52:28Z")

</div>

The `ecom_image_uris` aren’t a documented and supported field which is why they aren’t included in the SDK. We don’t recommend coding anything to the `ecom_image_uris`. If you’d like the image of a catalog object you’ll use the `image_id` to get the images. 🙂
