Solved

Failed to update customer tags by Admin REST API

Gmistyle
Tourist
8 1 0

I'm trying to update a customer's tags by sending A PUT request.

BUT I always get this response : {"errors":{"customer":"Required parameter missing or invalid"}}

Thanks for Help!!!

 

<<My Code>>

 

 

req_url = "https://myshop.co/admin/api/2022-10/customers/123456789.json"

req_headers = {
    "X-Shopify-Access-Token": "XXXX",
    "Content-Type": "application/json"
}
req_body = {
    "customer": {
        "id": 123456789,
        "tags": "test1,test2"
    }
}
req = requests.put(req_url, headers=req_headers, json=req_body)
print(req.json())

>>>

 

 {"errors":{"customer":"Required parameter missing or invalid"}}

 

Accepted Solution (1)
Gmistyle
Tourist
8 1 0

This is an accepted solution.

I finally solved it. The idea was found from here: https://community.shopify.com/c/shopify-apis-and-sdks/python-product-tag-update-400-error-product-re... 

To everyone have the same problem : try every shop domain you can find from your shopify admin

View solution in original post

Replies 8 (8)

Gmistyle
Tourist
8 1 0

this is x-request-id from my response header : 

329c4c02-deeb-4385-bd2d-ad3f13230110

thanks!!

ShopifyDevSup
Shopify Staff
1325 218 459

Hi @Gmistyle 👋


Would you please try it in the below curl request instead:

 

 

curl -L -X PUT 'https://{SHOP_NAME}.myshopify.com/admin/api/2023-01/customers/123.json' \
-H 'X-Shopify-Access-Token: {ADMIN_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{"customer": {"id": "123", "tags": "abc,def"}}'

 

 

 

If that works for you, it's likely an issue with your python implementation. You may need to just encode the payload in a dict and pass it as data in your put request like this:

 

 

 

url = f"https://{SHOP_NAME}/admin/api/2023-01/customers/123.json"
data = {
    "customer": {
        "id": 123,
        "tags": "abc,def"
    }
}
data = json.dumps(data)
req = requests.put(url, headers=headers, data=data)

 

 

 

Hope that helps! 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

Gmistyle
Tourist
8 1 0

Thanks for your reply,

I haven't tried with curl put request.

But I have tried many ways to send the payload like below:

1.) requests.put(..., data=json.dumps(dict_payload))

2.) requests.put(..., data=json.dumps(dict_payload).encode('utf-8))

3.) requests.put(..., data=json.dumps(dict_payload).encode())

4.) requests.put(..., json=dict_payload)

...

 

unfortunately, it all failed, here is the x-request-id which sent payload like you suggest:

X-Request-ID : 64f807ea-87fe-4bc2-bef8-98b2744b539b

 

I also tried to send request by urllib3, the same result.

is this possible to be caused by like...wrong configuration in Shopify APP & Dev setting?

Gmistyle
Tourist
8 1 0

I tried in curl request and I get the same result : {"errors":{"customer":"Required parameter missing or invalid"}}

ShopifyDevSup
Shopify Staff
1325 218 459

The logs show that your put request doesn't contain a payload. Are you ensuring that your curl request payload is properly formatted as shown in the below example?

 

 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

Gmistyle
Tourist
8 1 0

Thanks, Here are my screenshot from curl request and python request.

Gmistyle_1-1678249338769.png

Gmistyle_2-1678249597812.png

 

 

Gmistyle
Tourist
8 1 0

I found the last screenshot I offered contained a typo with customer's', here is a correct one.

Gmistyle_0-1678352758565.png

 

from your answer, it seems that shopify admin API somehow didn't get my payload. Besides, I use postman to send this requests with the same value. I get a status 200 response, but nothing changed. 

Gmistyle
Tourist
8 1 0

This is an accepted solution.

I finally solved it. The idea was found from here: https://community.shopify.com/c/shopify-apis-and-sdks/python-product-tag-update-400-error-product-re... 

To everyone have the same problem : try every shop domain you can find from your shopify admin