All things Shopify and commerce
Hi, we have created a "Develop Apps" and when we try to call the admin API with the access token but its not returning any results. Below is the endpoint and we are using the access token from the dashboard to make the call
curl -X GET "https://XXX.myshopify.com/admin/api/2023-10/products/count.json" -H "X-Shopify-Access-Token: XXX"
Solved! Go to the solution
This is an accepted solution.
The response you're receiving from the Shopify API indicates a 301 Moved Permanently status. This means that the URL you're trying to access has been permanently moved to a different location. Specifically, your request to https://XXX.myshopify.com/admin/api/2023-07/graphql.json is being redirected to https://123.myshopify.com/admin/api/2023-07/graphql.json .
Key Points to Consider:
Check the Store URL: Ensure that you're using the correct URL for your Shopify store. The redirect suggests that the initial URL might be incorrect or outdated.
Update the Request URL: Use the URL provided in the location header of the response (https://123.myshopify.com/admin/api/2023-07/graphql.json ) for your API requests.
Follow Redirects: If your HTTP client does not automatically follow redirects, you may need to configure it to do so, or manually update the request URL to the new location.
This redirection is likely the reason why you're not able to count products. Once you update the URL, your API call should work as expected, provided that other parameters (like the access token and API version) are correct.
This one I wasn't sure about at all, but a simple search returned this code.
https://{{yourShop}}.myshopify.com/admin/products/count.json?selectedView=all&status=ACTIVE
I don't think I am right tho, so ignore me lol
Did u try hitting this api with an access token? When i tried i didnt get any response
I would ensure that the access token is valid and has the necessary permissions to access the products count. This is a simple one that should return something if you have the correct access.
Are you getting a response back? 400 500 200? 404?
thanks mate. Am using the access token from the admin console in the "developer apps". Is that the right one?
Yes, you should have a configuration page like this. Here you will click edit next to "Admin API Integration" and make sure you have the "read_products" scope enabled.
Thanks mate. This is how it looks like. I have already enabled that scope but still the response is empty.
Also does the access token start with "s h p a t_"?
Yes, that is the access token.
Even tried with the graphql endpoint but still it doesnt return any results
curl -X POST \
https://pubbl.myshopify.com/admin/api/2023-07/graphql.json -H 'Content-Type: application/json' -H 'X-Shopify-Access-Token: {XXX}' -d '{
"query": "query { products(first: 10, reverse: true) { edges { node { id title handle resourcePublicationOnCurrentPublication { publication { name id } publishDate isPublished } } } } }"}'
Can you inspect the request or check the logs and see the response that you are getting back?
This is the logs i can see on enabling verbose on curl
* Connected to pubbl.myshopify.com (23.227.38.74) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* CAfile: /Users/predeep/anaconda3/ssl/cacert.pem
* CApath: none
* [CONN-0-0][CF-SSL] TLSv1.3 (OUT), TLS handshake, Client hello (1):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Server hello (2):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Certificate (11):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, CERT verify (15):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Finished (20):
* [CONN-0-0][CF-SSL] TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* [CONN-0-0][CF-SSL] TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Cloudflare, Inc.; CN=myshopify.com
* start date: Aug 23 00:00:00 2023 GMT
* expire date: Aug 21 23:59:59 2024 GMT
* subjectAltName: host "pubbl.myshopify.com" matched cert's "*.myshopify.com"
* issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: POST]
* h2h3 [:path: /admin/api/2023-07/graphql.json]
* h2h3 [:scheme: https]
* h2h3 [:authority: pubbl.myshopify.com]
* h2h3 [user-agent: curl/7.87.0]
* h2h3 [accept: */*]
* h2h3 [content-type: application/json]
* h2h3 [content-length: 189]
* Using Stream ID: 1 (easy handle 0x14a00aa00)
> POST /admin/api/2023-07/graphql.json HTTP/2
> Host: pubbl.myshopify.com
> user-agent: curl/7.87.0
> accept: */*
> content-type: application/json
> content-length: 189
>
* We are completely uploaded and fine
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* [CONN-0-0][CF-SSL] TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
< HTTP/2 301
< date: Wed, 03 Jan 2024 23:16:35 GMT
< content-type: text/html; charset=utf-8
< location: https://08d534.myshopify.com/admin/api/2023-07/graphql.json
< x-sorting-hat-podid: 194
< x-sorting-hat-shopid: 63097700547
< referrer-policy: origin-when-cross-origin
< x-frame-options: DENY
< x-shopid: 63097700547
< x-shardid: 194
< strict-transport-security: max-age=7889238
< set-cookie: request_method=POST; path=/; SameSite=Lax
< server-timing: processing;dur=25
< 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.shopifycs.com 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 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=query&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fgraphql&source%5Bsection%5D=admin_api&source%5Buuid%5D=55673052-18b5-4a78-8363-d93a865df057
< 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=query&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fgraphql&source%5Bsection%5D=admin_api&source%5Buuid%5D=55673052-18b5-4a78-8363-d93a865df057
< x-dc: gcp-australia-southeast1,gcp-us-central1,gcp-us-central1
< x-request-id: 55673052-18b5-4a78-8363-d93a865df057
< cf-cache-status: DYNAMIC
< report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=4DgYRHldUvG4hJfFbeGdY61W63cQj1d4EJGor9Xchg4YFw9y89g%2F1oy0ricopUAfwO%2BCMgK8Eri5w2C2e3WCx9ty7arQqQV%2B4w92U0GV5Dg5Y0CSQAxj7hzMtqyRY0MG51S0TxY%3D"}],"group":"cf-nel","max_age":604800}
< nel: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}
< server-timing: cfRequestDuration;dur=225.999832
< server: cloudflare
< cf-ray: 83fef34958d0572d-SYD
< alt-svc: h3=":443"; ma=86400
<
* Connection #0 to host pubbl.myshopify.com left intact
This is an accepted solution.
The response you're receiving from the Shopify API indicates a 301 Moved Permanently status. This means that the URL you're trying to access has been permanently moved to a different location. Specifically, your request to https://XXX.myshopify.com/admin/api/2023-07/graphql.json is being redirected to https://123.myshopify.com/admin/api/2023-07/graphql.json .
Key Points to Consider:
Check the Store URL: Ensure that you're using the correct URL for your Shopify store. The redirect suggests that the initial URL might be incorrect or outdated.
Update the Request URL: Use the URL provided in the location header of the response (https://123.myshopify.com/admin/api/2023-07/graphql.json ) for your API requests.
Follow Redirects: If your HTTP client does not automatically follow redirects, you may need to configure it to do so, or manually update the request URL to the new location.
This redirection is likely the reason why you're not able to count products. Once you update the URL, your API call should work as expected, provided that other parameters (like the access token and API version) are correct.
Thanks mate. That fixed it. Not sure why the name i set for the store isnt working. But using the redirected url fixed it.
Awesome, glad I could help! If you need anything else just feel free to ask!
Happy Coding!
I am going to edit out your url from the above responses now, just in case 😄
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024