infusionsoft / infusionsoft-php

PHP client library for the Infusionsoft API.
https://developer.infusionsoft.com/
Other
130 stars 126 forks source link

How to properly extract data from GET /orders API response? #282

Open shaifulborhan opened 3 years ago

shaifulborhan commented 3 years ago

Hi,

I made the following API call to the get a user latest order.

$orders = $infusionsoft->orders()->where([
            'contactId' => 123
])->first();

echo '<pre>'; print_r($orders); echo '</pre>';

However the response came back like this.

Screenshot 2021-05-26 at 1 05 29 AM

To get the clean data I have to do $orders->attributesToArray(). Do I have to do this whenever I am using where()? What is the correct way to extract the orders array out of this response data?

Reason I am asking is because I am familiar with Laravel's Eloquent methods like first() and get() and they just work straightaway without any extra methods to unwrap the results. Since the method naming convention is pretty similar in the PHP-SDK I was expecting it to work similarly.

Thanks.

skeemer commented 3 years ago

Laravel actually works the same, you get an Eloquent model/collection back from first()/get() then have to use ->toArray() to get "clean" data.