Error 400 trying to create a shopify collection

I am trying to create a scenario to make an API call to Shopify to create a collection and upload an image.
I can GET data so I know I have authorized correctly.
I have the required products access scope in the auth key.

Here is what is in the API call:

URL:
smart_collections.json

API Version: 2023-01

Method: POST

Key: Content-type
Value: application/JSON

There is no query string.

I copied the request body directly from the shopify API:

{
“body_html”: “

The best selling ipod ever

”,
“handle”: “smart-ipods”,
“id”: 482865238,
“image”: {
“src”: “http://static.shopify.com/collections/ipod.jpg?0”,
“alt”: “iPods”
},
“published_scope”: “global”,
“rules”: {
“column”: “variant_price”,
“relation”: “less_than”,
“condition”: “20”
},
“disjunctive”: false,
“sort_order”: “alpha-asc”,
“template_suffix”: null,
“title”: “Smart iPods”,
“updated_at”: “2008-02-01T19:00:00-05:00”
}

When I run the scenario I am getting the following error:

The operation failed with an error. [400] [Collection]

I am very new to this and I can’t figure out what could be wrong, the error message isn’t very helpful.

Thank you so much for any assistance!

From initial looks, it looks like the body that you are sending is malformed, not sure if it due to formatting here in the community or it is what you are setting in Make itself. Can you crosscheck and see if there is no new lines in body_html?

It should look something like this,

{
“body_html”: “The best selling ipod ever”,
“handle”: “smart-ipods”,
“id”: 482865238,
“image”: {
“src”: “http://static.shopify.com/collections/ipod.jpg?0”,
“alt”: “iPods”
},
“published_scope”: “global”,
“rules”: {
“column”: “variant_price”,
“relation”: “less_than”,
“condition”: “20”
},
“disjunctive”: false,
“sort_order”: “alpha-asc”,
“template_suffix”: null,
“title”: “Smart iPods”,
“updated_at”: “2008-02-01T19:00:00-05:00”
}

Can you copy-paste this from here and replace the body content in Make an API call module and right click the module to run it once and see if you are still getting the issue?

1 Like

Hello,
Thanks so much for the assistance.
It must be the formatting here, there are no extra lines.
I copied and pasted from your link and no change, I am still getting

The operation failed with an error. [400] [Collection]

It will be hard to debug this. But what you can do is, Install this.

This should then enable you to review the data sent and error message that you will get back from Shopify.

There are a few things on the body that might be causing this but, I can’t say it certainly on whether they are causing this issue,

  1. template_suffix : Remove this or put ""instead of null
  2. updated_at : I don’t think this is needed if you are creating new Smart Collection.
  3. id is not required
  4. remove sort_order, disjunctive and published_scope

Also, from the document shouldn’t the body look like this,

{
	"smart_collection": {
		"title": "Macbooks",
		"rules": [{
			"column": "vendor",
			"relation": "equals",
			"condition": "Apple"
		}],
		"image": {
			"attachment": "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\n",
			"alt": "iPod"
		}
	}
}

With smart_collection as the parent in payload?

1 Like

Try with this and see if it works,

{
	"smart_collection": {
		"title": "Smart iPods",
		"rules": [{
			"column": "variant_price",
			"relation": "less_than",
			"condition": "20"
		}],
		"image": {
			"src": "http://static.shopify.com/collections/ipod.jpg?0",
			"alt": "iPods"
		}
	}
}
1 Like

I wasn’t really sure what to put for the payload, I copied the Smart Collection resource from the side of the documentation. What you put works though! I just need to change it to the image url so it will be uploaded.

1 Like

It works!!
Thank you!
I can’t figure out where you got the syntax of the payload, I don’t see it anywhere on the page but I understand how it works now. Thank you so much! I’m very new to this!

1 Like

For future reference, you can see the required payload as seen in the screenshot,

It should be available for all other endpoints as well.

1 Like

Thank you!
I understand where to get it now. I tried to copy the node.js and that didn’t work obviously.

1 Like