Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hi,
Have anyone meet this case . I try to change to Cursor-based pagination but no luck
string(18949) "HTTP/2 200 date: Fri, 20 Sep 2019 02:11:24 GMT content-type: application/json; charset=utf-8 set-cookie: __cfduid=de4e3f32d47050adadae399a85e22dc491568945484; expires=Sat, 19-Sep-20 02:11:24 GMT; path=/; domain=.myshopify.com; HttpOnly x-sorting-hat-podid: 47 x-sorting-hat-shopid: 15636398128 vary: Accept-Encoding referrer-policy: origin-when-cross-origin x-frame-options: DENY x-shopid: 15636398128 x-shardid: 47 x-stats-userid: x-stats-apiclientid: 2986379 x-stats-apipermissionid: 193326546992 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: 7c32bc05-779b-48f2-a0c3-fba414bb9728 x-shopify-stage: canary 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=7c32bc05-779b-48f2-a0c3-fba414bb9728 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=7c32bc05-779b-48f2-a0c3-fba414bb9728 x-dc: gcp-us-east1,gcp-us-east1 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: 519044bc9dd23377-HKG
The call look like : GET https://mystore.myshopify.com/admin/api/2019-07/products.json?limit=3 (I have 15 test products)
The response header I get was:
link: ; rel="next"
So I dont know how to get a proper link like in this guide
Can anyone help me?
Solved! Go to the solution
This is an accepted solution.
If anyone else has this issue and gets confused by the links saying they solved it on another post only to have them end back up at the docs where you started, my issue was that the output to chrome from php wasn't displaying the link cause it was wrapped in < > and hidden in the browser view.
link: <https://shop-name.myshopify.com/ ... >
It can be seen when inspecting or viewing the source.
Hello okito,
Refer below link this will help you:
I checked and the link header was sent properly. Make sure you are not using any library that deletes the `url` in the LINK header.
Ignacio
This is an accepted solution.
If anyone else has this issue and gets confused by the links saying they solved it on another post only to have them end back up at the docs where you started, my issue was that the output to chrome from php wasn't displaying the link cause it was wrapped in < > and hidden in the browser view.
link: <https://shop-name.myshopify.com/ ... >
It can be seen when inspecting or viewing the source.
Sample code to download everything in chunks of 100 from the price rules endpoint.
from urllib.parse import urlparse, parse_qs
headers = CaseInsensitiveDict()
headers["X-Shopify-Access-Token"] = "<access token>"
SHOP_HANDLE = '<STORE HANDLE HERE>'
API_VERSION = '2021-10'
shop_url = "https://{}.myshopify.com/admin/api/{}".format(SHOP_HANDLE, API_VERSION)
def header_handler(r):
resp_headers = json.loads(json.dumps(dict(r.headers)))
shopify_headers = parse_qs(urlparse(resp_headers['Link']).query)['page_info']
first = shopify_headers[0].split('>; rel=')
if len(shopify_headers) == 2:
return first[0], shopify_headers[1].split('>; rel=')[0] # prev always comes first
if 'previous' in first[1]:
return first[0], None
else:
return None, first[0]
def iter_all_price_rules(limit):
get_next_page = True
url = shop_url + '/price_rules.json?limit={}'.format(limit)
while get_next_page:
r = requests.get(url, headers=headers)
price_rules = json.loads(json.dumps(r.json()))['price_rules']
for price_rule in price_rules:
yield price_rule
prev_page, next_page = header_handler(r)
if(next_page is None):
get_next_page = False
else:
url = shop_url + '/price_rules.json?limit={}&page_info={}'.format(limit, next_page)
def get_price_rules(limit=100):
out = []
for price_rule in iter_all_price_rules(limit):
out.append(price_rule)
return out
result = get_price_rules()
User | RANK |
---|---|
5 | |
5 | |
4 | |
4 | |
3 |