Open ranjangoyal opened 6 years ago
This library works for Legacy API but not for latest version
For latest version, I get
200 response and error of "Invalid JSON retured"
I am getting following response. Please check that [body] element... that seems to be causing issue
How can I rectify this?
Invalid JSON returned for https://mysite/wp-json/wc/v2/customers?consumer_key=ck_1111111111111111111111111111111111111111&consumer_secret=cs_222222222222222222222222222222222222222.
200
stdClass Object ( [headers] => Array ( [0] => Accept: application/json [1] => Content-Type: application/json [2] => User-Agent: WooCommerce API Client-PHP/2.0.1 )
[method] => GET [url] => https://mysite/wp-json/wc/v2/customers?consumer_key=ck_1111111111111111111111111111111111111111&consumer_secret=cs_222222222222222222222222222222222222222 [params] => Array ( [consumer_key] => ck_1111111111111111111111111111111111111111 [consumer_secret] => cs_222222222222222222222222222222222222222 ) [data] => Array ( ) [body] => [duration] => 1.06934
) stdClass Object ( [body] =>
[{"id":14,"date_created":"2018-07-12T17:21:48","date_created_gmt":"2018-07-12T17:21:48","date_modified":"2018-07-12T17:21:48","date_modified_gmt":"2018-07-12T17:21:48","email":"ranjangoyal26004@gmail.com","first_name":"Ranjan","last_name":"Goyal","role":"customer","username":"ranjangoyal26004","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1d863dad4ebbf5240e9354e04c56df3a?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/14"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":4,"date_created":"2018-05-30T10:52:38","date_created_gmt":"2018-05-30T10:52:38","date_modified":"2018-06-28T12:36:48","date_modified_gmt":"2018-06-28T12:36:48","email":"testcustomer@gmail.com","first_name":"Test","last_name":"Customer","role":"customer","username":"testcustomer","billing":{"first_name":"Test","last_name":"Customer","company":"","address_1":"124","address_2":"","city":"Los Angeles","state":"CA","postcode":"90005","country":"US","email":"testcustomer@gmail.com","phone":""},"shipping":{"first_name":"Test","last_name":"Customer","company":"","address_1":"124","address_2":"","city":"Los Angeles","state":"CA","postcode":"90005","country":"US"},"is_paying_customer":true,"orders_count":10,"total_spent":"1110.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/64dc070868dfd4098166a1848dc3b2f8?s=96&d=mm&r=g","meta_data":[{"id":164,"key":"wc_last_active","value":"1531094400"},{"id":165,"key":"mailchimp_woocommerce_is_subscribed","value":"0"},{"id":174,"key":"_wcv_shipping","value":{"national":"","national_qty_override":"","national_free":"","national_disable":"","international":"","international_qty_override":"","international_free":"","international_disable":"","product_handling_fee":"","max_charge":"","min_charge":"","free_shipping_order":"","free_shipping_product":"","max_charge_product":"","shipping_policy":"","return_policy":"","shipping_from":"","shipping_address":{"address1":"","address2":"","city":"","state":"","country":"","postcode":""}}},{"id":557,"key":"shipping_method","value":["local_pickup:5"]}],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/4"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":11,"date_created":"2018-07-02T07:42:34","date_created_gmt":"2018-07-02T07:42:34","date_modified":null,"date_modified_gmt":null,"email":"ranjangoyal2004@gmail.com","first_name":"","last_name":"","role":"customer","username":"testing","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/cac84ac86e576f4d0a94be0c38a8e993?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/11"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":15,"date_created":"2018-07-12T17:23:29","date_created_gmt":"2018-07-12T17:23:29","date_modified":"2018-07-12T17:45:45","date_modified_gmt":"2018-07-12T17:45:45","email":"ranjangoyal111@gmail.com","first_name":"Test","last_name":"User","role":"customer","username":"testing111","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/dadf2ab5f31298693d31a5b89abc497e?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/15"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":12,"date_created":"2018-07-02T08:08:38","date_created_gmt":"2018-07-02T08:08:38","date_modified":"2018-07-02T08:55:02","date_modified_gmt":"2018-07-02T08:55:02","email":"testuser2004@gmail.com","first_name":"Test","last_name":"User","role":"customer","username":"testuser2004","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/99ada2642dbef3252625b49b63136c44?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/12"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":5,"date_created":"2018-06-04T06:37:08","date_created_gmt":"2018-06-04T06:37:08","date_modified":"2018-07-03T06:08:07","date_modified_gmt":"2018-07-03T06:08:07","email":"vishal.patel@mytech.com","first_name":"dfgdsf","last_name":"sdfsd","role":"customer","username":"vishal.patel","billing":{"first_name":"dfgdsf","last_name":"sdfsd","company":"dsfasd","address_1":"sdfsad","address_2":"sdfasd","city":"saddfasd","state":"GJ","postcode":"123321312","country":"","email":"vishal.patel@mytech.com","phone":"1232131231221312"},"shipping":{"first_name":"dfgdsf","last_name":"sdfsd","company":"dsfasd","address_1":"sdfsad","address_2":"sdfasd","city":"saddfasd","state":"GJ","postcode":"123321312","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4b6e8f5a15b3c7cbeb7fcf29a5d766a3?s=96&d=mm&r=g","meta_data":[{"id":217,"key":"wc_last_active","value":"1528070400"},{"id":239,"key":"shipping_method","value":["flat_rate:2"]},{"id":240,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":615,"key":"_wcv_shipping","value":{"national":"","national_qty_override":"","national_free":"","national_disable":"","international":"","international_qty_override":"","international_free":"","international_disable":"","product_handling_fee":"","max_charge":"","min_charge":"","free_shipping_order":"","free_shipping_product":"","max_charge_product":"","shipping_policy":"","return_policy":"","shipping_from":"","shipping_address":{"address1":"","address2":"","city":"","state":"","country":"","postcode":""}}}],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/5"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}}] [code] => 200 [headers] => Array ( [Connection] => keep-alive [Access-Control-Allow-Headers] => Authorization, Content-Type [Access-Control-Expose-Headers] => X-WP-Total, X-WP-TotalPages [Allow] => GET, POST [Cache-Control] => public, max-age=600 [Content-Type] => application/json; charset=UTF-8 [Expires] => Wed, 11 Jan 1984 05:00:00 GMT [Link] => https://mysite/wp-json/; rel="https://api.w.org/" [Server] => nginx [Set-Cookie] => Array ( [0] => SESSe61953837b8c92082a6a2fe64ddb9785=1ceee2edf0a29b69e2be05365fe9da64; expires=Fri, 13-Jul-2018 11:46:55 GMT; Max-Age=0 [1] => SSESSe61953837b8c92082a6a2fe64ddb9785=e2075bd46063bc3b972def061c608975; path=/; domain=.mysite; secure; HttpOnly )
[X-Content-Type-Options] => nosniff [X-Pantheon-Styx-Hostname] => styx-fe3-5f44c4b85-slnv2 [X-Styx-Req-Id] => styx-eee026cf59c133088417af52cef2706c [X-Wp-Total] => 6 [X-Wp-Totalpages] => 1 [Accept-Ranges] => Array ( [0] => Array ( [0] => Array ( [0] => bytes [1] => bytes ) [1] => bytes ) [1] => bytes ) [Age] => Array ( [0] => Array ( [0] => Array ( [0] => 0 [1] => 0 ) [1] => 0 ) [1] => 0 ) [Via] => Array ( [0] => 1.1 varnish [1] => 1.1 varnish ) [Date] => Fri, 13 Jul 2018 11:46:55 GMT [X-Served-By] => cache-mdw17347-MDW, cache-sin18027-SIN [X-Cache] => MISS, MISS [X-Cache-Hits] => 0, 0 [X-Timer] => S1531482415.985514,VS0,VE389 [Vary] => Accept-Encoding [X-Robots-Tag] => noindex [transfer-encoding] => chunked )
)
In "class-wc-api-client.php" //$path .= '/wc-api/v3/'; // Default version... for legacy API $path .= '/wp-json/wc/v2/'; // For latest API.... **Is it correct?**
This library works for Legacy API but not for latest version
For latest version, I get
200 response and error of "Invalid JSON retured"
I am getting following response. Please check that [body] element... that seems to be causing issue
How can I rectify this?
Invalid JSON returned for https://mysite/wp-json/wc/v2/customers?consumer_key=ck_1111111111111111111111111111111111111111&consumer_secret=cs_222222222222222222222222222222222222222.
200
stdClass Object ( [headers] => Array ( [0] => Accept: application/json [1] => Content-Type: application/json [2] => User-Agent: WooCommerce API Client-PHP/2.0.1 )
) stdClass Object ( [body] =>
[{"id":14,"date_created":"2018-07-12T17:21:48","date_created_gmt":"2018-07-12T17:21:48","date_modified":"2018-07-12T17:21:48","date_modified_gmt":"2018-07-12T17:21:48","email":"ranjangoyal26004@gmail.com","first_name":"Ranjan","last_name":"Goyal","role":"customer","username":"ranjangoyal26004","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1d863dad4ebbf5240e9354e04c56df3a?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/14"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":4,"date_created":"2018-05-30T10:52:38","date_created_gmt":"2018-05-30T10:52:38","date_modified":"2018-06-28T12:36:48","date_modified_gmt":"2018-06-28T12:36:48","email":"testcustomer@gmail.com","first_name":"Test","last_name":"Customer","role":"customer","username":"testcustomer","billing":{"first_name":"Test","last_name":"Customer","company":"","address_1":"124","address_2":"","city":"Los Angeles","state":"CA","postcode":"90005","country":"US","email":"testcustomer@gmail.com","phone":""},"shipping":{"first_name":"Test","last_name":"Customer","company":"","address_1":"124","address_2":"","city":"Los Angeles","state":"CA","postcode":"90005","country":"US"},"is_paying_customer":true,"orders_count":10,"total_spent":"1110.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/64dc070868dfd4098166a1848dc3b2f8?s=96&d=mm&r=g","meta_data":[{"id":164,"key":"wc_last_active","value":"1531094400"},{"id":165,"key":"mailchimp_woocommerce_is_subscribed","value":"0"},{"id":174,"key":"_wcv_shipping","value":{"national":"","national_qty_override":"","national_free":"","national_disable":"","international":"","international_qty_override":"","international_free":"","international_disable":"","product_handling_fee":"","max_charge":"","min_charge":"","free_shipping_order":"","free_shipping_product":"","max_charge_product":"","shipping_policy":"","return_policy":"","shipping_from":"","shipping_address":{"address1":"","address2":"","city":"","state":"","country":"","postcode":""}}},{"id":557,"key":"shipping_method","value":["local_pickup:5"]}],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/4"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":11,"date_created":"2018-07-02T07:42:34","date_created_gmt":"2018-07-02T07:42:34","date_modified":null,"date_modified_gmt":null,"email":"ranjangoyal2004@gmail.com","first_name":"","last_name":"","role":"customer","username":"testing","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/cac84ac86e576f4d0a94be0c38a8e993?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/11"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":15,"date_created":"2018-07-12T17:23:29","date_created_gmt":"2018-07-12T17:23:29","date_modified":"2018-07-12T17:45:45","date_modified_gmt":"2018-07-12T17:45:45","email":"ranjangoyal111@gmail.com","first_name":"Test","last_name":"User","role":"customer","username":"testing111","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/dadf2ab5f31298693d31a5b89abc497e?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/15"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":12,"date_created":"2018-07-02T08:08:38","date_created_gmt":"2018-07-02T08:08:38","date_modified":"2018-07-02T08:55:02","date_modified_gmt":"2018-07-02T08:55:02","email":"testuser2004@gmail.com","first_name":"Test","last_name":"User","role":"customer","username":"testuser2004","billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","email":"","phone":""},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/99ada2642dbef3252625b49b63136c44?s=96&d=mm&r=g","meta_data":[],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/12"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}},{"id":5,"date_created":"2018-06-04T06:37:08","date_created_gmt":"2018-06-04T06:37:08","date_modified":"2018-07-03T06:08:07","date_modified_gmt":"2018-07-03T06:08:07","email":"vishal.patel@mytech.com","first_name":"dfgdsf","last_name":"sdfsd","role":"customer","username":"vishal.patel","billing":{"first_name":"dfgdsf","last_name":"sdfsd","company":"dsfasd","address_1":"sdfsad","address_2":"sdfasd","city":"saddfasd","state":"GJ","postcode":"123321312","country":"","email":"vishal.patel@mytech.com","phone":"1232131231221312"},"shipping":{"first_name":"dfgdsf","last_name":"sdfsd","company":"dsfasd","address_1":"sdfsad","address_2":"sdfasd","city":"saddfasd","state":"GJ","postcode":"123321312","country":""},"is_paying_customer":false,"orders_count":0,"total_spent":"0.00","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4b6e8f5a15b3c7cbeb7fcf29a5d766a3?s=96&d=mm&r=g","meta_data":[{"id":217,"key":"wc_last_active","value":"1528070400"},{"id":239,"key":"shipping_method","value":["flat_rate:2"]},{"id":240,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":615,"key":"_wcv_shipping","value":{"national":"","national_qty_override":"","national_free":"","national_disable":"","international":"","international_qty_override":"","international_free":"","international_disable":"","product_handling_fee":"","max_charge":"","min_charge":"","free_shipping_order":"","free_shipping_product":"","max_charge_product":"","shipping_policy":"","return_policy":"","shipping_from":"","shipping_address":{"address1":"","address2":"","city":"","state":"","country":"","postcode":""}}}],"_links":{"self":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers\/5"}],"collection":[{"href":"https:\/\/mysite\/wp-json\/wc\/v2\/customers"}]}}] [code] => 200 [headers] => Array ( [Connection] => keep-alive [Access-Control-Allow-Headers] => Authorization, Content-Type [Access-Control-Expose-Headers] => X-WP-Total, X-WP-TotalPages [Allow] => GET, POST [Cache-Control] => public, max-age=600 [Content-Type] => application/json; charset=UTF-8 [Expires] => Wed, 11 Jan 1984 05:00:00 GMT [Link] => https://mysite/wp-json/; rel="https://api.w.org/" [Server] => nginx [Set-Cookie] => Array ( [0] => SESSe61953837b8c92082a6a2fe64ddb9785=1ceee2edf0a29b69e2be05365fe9da64; expires=Fri, 13-Jul-2018 11:46:55 GMT; Max-Age=0 [1] => SSESSe61953837b8c92082a6a2fe64ddb9785=e2075bd46063bc3b972def061c608975; path=/; domain=.mysite; secure; HttpOnly )
)