Authentication 401 error

Authentication 401 error

Paddy3000
Shopify Partner
16 0 2

Hello everyone,

 

I've created a private app in the Shopify Admin area. Download and upload work fine in Postman, but from my server, only the download works. When trying to upload data, I receive a 401 status code, and the shop data (categories) remain unchanged.

Can anyone tell me what might be causing this?

Could it be related to outdated SSL certificates, or have I missed something fundamental regarding authentication?

I've attached my code (JavaScript and comments) for reference:

 

 

 

// Produces 400 + 401
function uploadCategoriesSFY() {
var settings = {
"url": "https://shop123456.myshopify.com/admin/api/2023-10/custom_collections.json",
//"url": "https://110a...:321@shop123456.myshopify.com/admin/api/2023-10/custom_collections.json",
// Also returns a 401
"method": "POST",
"timeout": 0,
"headers": {
"X-Shopify-Access-Token": "sh.._de1123....",
//"X-Shopify-Access-Token" produces a 401
/*
Fri Feb 16 15:05:05 CET 2024: API RESPONSE: {
"responseCode": 401,
"errorResponse": "{\"errors\":\"[API] Invalid API key or access token (unrecognized login or wrong password)\"}"
}
*/
"Authorization": "Basic 456..",
/*
* // Authorization in the header produces a 400
Fri Feb 16 15:02:30 CET 2024: API RESPONSE: {
"responseCode": 400,
"errorResponse": "{\"errors\":{\"custom_collection\":\"Required parameter missing or invalid\"}}"
}
*/
"Content-Type": "application/json"},
"data": JSON.stringify({
"custom_collection": {
"title": "SSLTEST",
"body_html": "Description of the collection",
"sort_order": "manual",
"template_suffix": "your_template_suffix",
"published_scope": "web"
}
})
};

 All the best,

 

Patrick

Reply 1 (1)

Liam
Shopify Staff
2873 312 821

Hi Paddy,

 

When you're saying that "download and upload work fine in Postman, but from my server, only the download works" - does this mean that on your local dev environment both actions are working as expected but when deployed they are not? It does sound like an auth issue, but also strange that download (read-access) is still working on the server environment. It's likely there is a server configuration issue at play, since the app credentials appear to be working as expected. 

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