Trying to get all customers in my store through API

emojobike
New Member
5 0 0

I did the research. This link: https://shopify.dev/tutorials/make-paginated-requests-to-rest-admin-api

It says I can do pagination through API on the response "Link" header, but the "Link" header I got from the api is like

 [Link] =>  max-age=7889238  

 

How am I supposed to do the pagination?

0 Likes
emojobike
New Member
5 0 0

so now I manually do the request through curl with php. I got the header like this. In the Link parameter. There is no next page url.

 

HTTP/1.1 200 OK
Date: Mon, 21 Dec 2020 08:01:59 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Sorting-Hat-PodId: 151
X-Sorting-Hat-ShopId: 1552613465
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 1552613465
X-ShardId: 151
X-Stats-UserId: 
X-Stats-ApiClientId: 4588891
X-Stats-ApiPermissionId: 298009362584
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2020-10
Link: ; rel="next"
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://checkout.us.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=9681369d-d24a-4db2-89ee-31c94a05c5ca
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=9681369d-d24a-4db2-89ee-31c94a05c5ca
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
Content-Encoding: gzip
NEL: {"report_to":"network-errors","max_age":2592000,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: 9681369d-d24a-4db2-89ee-31c94a05c5ca
NEL: {"report_to":"network-errors","max_age":2592000,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
CF-Cache-Status: DYNAMIC
cf-request-id: 0725ead249000004b49f3f5000000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 605013fd3ebd04b4-LAX

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

What does your request (URI and body) look like?

0 Likes
emojobike
New Member
5 0 0

This is the request code.

 

$url = "https://". $shop .'/admin/api/2020-10/customers.json';

$params = [
'limit' => '200',
];

$header = [
'X-Shopify-Access-Token: '.$access_token,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url."?".http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING , '');
$result = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
echo "<pre>";
print_r($header);
print_r($body);die;
0 Likes
emojobike
New Member
5 0 0

any helps?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

I don't have any local PHP implementation to test again, so I just issued this command on my Windows workstation.

curl -H "Content-Type: application/json" -H "X-Shopify-Access-Token: {my_access_token}" https://{my_shop}.myshopify.com/admin/api/2020-10/customers.json?limit=200

 

And below is a screen shot of the response headers. Notice the area I boxed in green. The link includes the page_info parameter, which is the cursor ID for the next page. I'm wondering in the greater-than and less-than symbols that frame the link aren't being handled well through your PHP client. To narrow this down, try issuing the curl command and see what comes back.

Untitled.png 

0 Likes
emojobike
New Member
5 0 0

hmm, I have tested on cmd and also postman. The response header "Link" will display properly, but when I use curl with php ( also the curl code generated by postman). The response header "Link" is missing the link. Any suggestions?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

As I mentioned, I suspect how the Link response header value contains greater-than and less-than signs isn't being handled well via the PHP client. I'd look on the library provider's project site to see if there are known issues and perhaps create some wrapper to parse the value by escaping or ignoring these characters.

0 Likes