Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Yet another "Invalid API key or access token (unrecognized login or wrong password)" thread

Solved

Yet another "Invalid API key or access token (unrecognized login or wrong password)" thread

janrosi
Tourist
4 1 1

Like some before I receive this error when trying to access the api (get orders). Since the api access changed the older topics are outdated for my case. I try to access "orders.json" via native PHP with curl functions.

 

I try to access it with the storefront-api-token I received after installing my custom app.

screen1.JPG

 

 

My code looks like this

$app_token = 'xxx'; // I get this when installing my app, attached a screen
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json','X-Shopify-Access-Token: '.$app_token]);
curl_setopt($ch, CURLOPT_URL, "https://xxx.myshopify.com/admin/api/2023-10/orders.json?status=any"); // xxx is my store id
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch)

 

Accepted Solution (1)

janrosi
Tourist
4 1 1

This is an accepted solution.

I solved it with some extern help. The shopify error message wasn't really accurate. I gave storefront-api permissions but forgot about the shopify-admin permissions. Once I set them and used the admin-api-token instead of the storefont-api-token, it works.

View solution in original post

Replies 6 (6)

Liam
Community Manager
3108 344 891

HI Janrosi,

 

Can you make calls to any Shopify API endpoint, or is it just orders which you're having this issue with?

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

janrosi
Tourist
4 1 1

I tried it with products/count (2023-10/products/count.json) and have the same result "Invalid API key or access token (unrecognized login or wrong password)".

Is it maybe because I don't have a development store? I am using a regular shopify and created a custom app for that.

Liam
Community Manager
3108 344 891

Did you create a custom app via the stores' admin - or is this a custom app created via the CLI? It's likely there is some auth issue here where the storefront API Token isn't registered correctly. 

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

janrosi
Tourist
4 1 1

This is an accepted solution.

I solved it with some extern help. The shopify error message wasn't really accurate. I gave storefront-api permissions but forgot about the shopify-admin permissions. Once I set them and used the admin-api-token instead of the storefont-api-token, it works.

Liam
Community Manager
3108 344 891

Glad you figured it out - I'll pass on the feedback too, regarding the error message

Liam | Developer Advocate @ 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 Shopify.dev or the Shopify Web Design and Development Blog

pchavez
Shopify Partner
3 0 3

Hi @janrosi . I am having the same issue. Could you please explain with more detail this:  I gave storefront-api permissions but forgot about the shopify-admin permissions. Once I set them and used the admin-api-token instead of the storefont-api-token, it works.

I have been working with shopify apis for some time but I am no expert. Thanks!

 

I am using this to auth and it works ok:

https://{store}.myshopify.com/admin/oauth/access_token

{"client_id":"xxx","client_secret":"xxx","code":"xxx"}

 

But then this one doesnt work:

https://{store}.myshopify.com/admin/api/2024-01/locations.json

X-Shopify-Access-Token: xxxx

 

{"errors": "[API] Invalid API key or access token (unrecognized login or wrong password)"}

 

It has been working for 2 or 3 years now, but with a new custom app is not working...