I think I'm missing a basic concept of this api. How to get the items out of this call?

I’m trying to get the catalog objects out of these calls.

I’ve tried things like $response->getItems() and $response->getObjects() which don’t work because those methods don’t exist in this version. So, how do I get the goods from the response?

            $response = $this->client->catalog->list(
                new ListCatalogRequest([
                    'types' => 'CATEGORY',
                ]),
            );
            $response2 = $this->client->catalog->list(
                new ListCatalogRequest([]),
            );

:waving_hand: 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:

Additional Documentation

Call the SearchCatalogObjects Endpoint
Catalog API
Delete Catalog Objects and Query Deleted Objects

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.

To access the catalog objects from the response, you can use the getObjects() method on the response object. Here’s how you can do it:

$categories = $response->getResult()->getObjects();
$allObjects = $response2->getResult()->getObjects();

In this code, $categories and $allObjects will be arrays containing the catalog objects returned by the API calls. Each element in these arrays will be an instance of CatalogObject.

This answer was reviewed by @Bryan-Square.

I couldn’t get that to work so I did this.


      $response = $this->client->catalog->list(
                new ListCatalogRequest([
                    'types' => 'CATEGORY',
                ]),
            );
            foreach ($pager as $response) {
                $data = json_decode(json_encode($response));
                if ($data->type == 'CATEGORY') {
                    array_push($categories, $data->category_data);
                }
            }

Glad to hear that you got it to work. :slight_smile: