AdminAPI/REST Reference-"Create a new product with the default product variant" example doesn't work

Solved
pmd85
Tourist
21 0 1

I tried to create new product using "Create a new product with the default product variant" example but Shopify returned error "400 Bad Request".

https://shopify.dev/docs/admin-api/rest/reference/products/product#create-2021-04

I've found that the problem is in the "tag" property.  Value "\Big Air\" is a problem. It works if I remove it from array. Also I've found that I can send tags as a string("\Big Air\" tag must come first).

What is the correct way? Array or string? Everywhere in the responses, tags are as a string. Shouldn't the string be in the request as well?

 

Tags in the example:

"tags": [

"Barnes & Noble",
"John's Fav",
"\Big Air\"
]

 Working  tags


"tags": "\Big Air\, Barnes & Noble, John's Fav"

"tags": [
"Barnes & Noble",
"John's Fav"
]

 

Thanks

0 Likes
GrahamS
Shopify Staff
Shopify Staff
92 17 17

Hey @pmd85 !

Good find. The use of backslashes in API payloads needs to be appended with a second backslash (so "\\Big Air\\") due to the way that backslashes are parsed into the system from the client. Once changed, you can absolutely send your tags as an array. The server response will return "\\Big Air\\", however it will be correctly parsed into the admin as just "\Big Air\"

We've brought this up to the API Docs team to have this updated in the example payload. Thanks for pointing this out!

Graham S | API Support @ 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

0 Likes
pmd85
Tourist
21 0 1

Hey GrahamS,

Thanks for your reply.

Can I send tags also as comma separated? Is it officially supported? Because it also works.

As I wrote,  tags are comma separated in all responses. So I was surprised that I should use an array in the request. I tested it and it also works.

 

"tags": "tag1, tag2, tag3"
0 Likes
GrahamS
Shopify Staff
Shopify Staff
92 17 17

This is an accepted solution.

Hey @pmd85 ,

Both would be considered as accepted and supported. You can find an example in our docs of a String query for tags here: UPDATE PRODUCT TAGS. If a comma separated string suits your needs better then there should be no problems with utilizing that in your workflow.

Graham S | API Support @ 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

0 Likes