Development discussions around Shopify APIs
Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more!
Hi,
I am using the CURL get request to get the link header for CURL response.
MY CURL Request
$curls = "https://{$shopdomain}/admin/api/2019-07/products.json?limit=1&access_token=".$access_token."";
$ch = curl_init();
curl_setopt($ch ,CURLOPT_URL, $curls);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
But the URL in Response header is missing
Here is the header response
HTTP/1.1 200 OK Date: Fri, 13 Sep 2019 06:26:21 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=df139750299ebfe8e7f405e7e209408e01568355981; expires=Sat, 12-Sep-20 06:26:21 GMT; path=/; domain=.myshopify.com; HttpOnly X-Sorting-Hat-PodId: 88 X-Sorting-Hat-ShopId: 2031747161 Vary: Accept-Encoding Referrer-Policy: origin-when-cross-origin X-Frame-Options: DENY X-ShopId: 2031747161 X-ShardId: 88 X-Stats-UserId: X-Stats-ApiClientId: 3084691 X-Stats-ApiPermissionId: 102802980953 HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40 X-Shopify-Shop-Api-Call-Limit: 1/40 X-Shopify-API-Version: 2019-07 Link: ; rel="next" Strict-Transport-Security: max-age=7889238 X-Request-Id: 119d8ce4-fd14-4f57-9b0e-9cd235c68cb2 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.shopify.cn https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.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%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=119d8ce4-fd14-4f57-9b0e-9cd235c68cb2 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%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=119d8ce4-fd14-4f57-9b0e-9cd235c68cb2 X-Dc: gcp-us-central1,gcp-us-central1 NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001} Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]} Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" Server: cloudflare CF-RAY: 51580c918f12dbdf-LHR
Can anyone help me on this what I am doing wrong. How I get the link.
Thanks,
Villiam
Hi @Villiamjit,
The response does indeed have a link header, but it looks like the actual url is not being parsed properly. How exactly are you logging the response headers? Can you try making the same request in the console and outputting the headers with '-i' appended to the end of the cURL request?
Let me know if that helps you see the next page url.
Cheers
Andrew | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi,
I've same issue, not getting Link in header. did you managed it?
Hi Busfox,
I am just printing the result from the CURL on the page using print_r();.
Can you please help me own this how Can I add '-i' in my CURL PHP code that I posted above.
Thanks,
Villiam
Hi Villiamjit,
Actually I realized that its sending header link. Its not visible in browser front end due to <https element.
If you inspect that Link you will find result.
Hi Jivan,
Thanks for your help I can see the link in inspect.
I am getting this
<https://vsd22.myshopify.com/admin/api/2019-07/products.json?limit=1&page_info=eyJsYXN0X2lkIjoxMzkxOT...>; rel="next"
Can you please let me know how Can I represent this link in a graphic view in php. Like
Regards,
Villiam
Hey @Villiamjit,
You'll need to escape the angle brackets so that they don't become interpreted as html tags. Also, I highly recommend not including your access token as a url parameter unless it is a storefront access token. Instead, you should pass the access token in the X-Shopify-Request-Id request header value.
Cheers,
Andrew | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
@Villiamjit I answered a similar question elsewhere today, try preg_match()
:
preg_match("/<(.*)>; rel={next}/", $link_str, $matches);
$matches[1]
will in the above case be the next link. There's probably a better expression to use, but that works for me in PHP.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi Alex,
It's not working for me maybe I got this in URL 'rel="next"' not rel={next}.
here is my Link <https://shopname/admin/api/2019-07/products.json?limit=1&page_info=pageinfokey>; rel="next".
Can you please check once. Its also not working if we have
<https://shopname/admin/api/2019-07/products.json?limit=1&page_info=pagekey>; rel="previous", <https://shopname/admin/api/2019-07/products.json?limit=1&page_info=pageinfokey>; rel="next"
How we get previous and next link separate.
Thanks,
Villiam
Hey @Villiamjit,
You're right! You'll need to change the regex @Alex shared to look for quotations instead of the curly brackets.
Andrew | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
User | RANK |
---|---|
16 | |
7 | |
6 | |
6 | |
5 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022