FROM CACHE - en_header

Bad Request (publications; expected Array to be a Hash).)

parkerjm
Tourist
16 0 3

Hey guys,

 

We just upgraded one of our private apps from a very old version to the latest version. Now when creating products in shopify, I get the error:

Response code = 400. Response message = Bad Request (publications; expected Array to be a Hash).)

 

However, I do not set "publications" in my request, nor do I even see a field called this for the product API, nor am I aware that we use this "publications" functionality at all.

 

The only arrays I see us sending are the list of variants (only one element), and list of metafields (many elements).

Replies 25 (25)
parkerjm
Tourist
16 0 3

The problem was that I forgot to upgrade the API version of the private app in our prod account. This error seems to occur if you use the 2020-01 API version against a private app that's set to use an old one from 2019.

Kris_Doyle
Shopify Partner
99 0 25

I'm getting this error with Smart collections intermittently. I'm using the 2020-04 version through and through.

 

In my case, I get it once in a while when updating a Smart collection.

parkerjm
Tourist
16 0 3

I am also still seeing this error occasionally while creating shopify products... looking into it.

aveshopstech
Shopify Partner
24 0 16

Hey @parkerjm, Did you ever figure this out? I've seen this a few times randomly also, but no idea why. I'm also not setting the `publications` field at all. 99% of the time I can create products with no problem, but every once in a while this error pops up for no apparent reason.

parkerjm
Tourist
16 0 3

yeah, we still have the same issue. same as you, 99% of the time it's fine... we're also not setting the `publications` field. must be some internal thing the API is doing that's causing a failure in certain cases. wish I had more info.

m60digital
New Member
2 0 1

I am having this problem when trying to create products via the API. I am currently using the API to import around 37k products with variants in to Shopify. After 27k products I am suddenly getting this error. Very strange as nothing has changed in my import script. Every single attempt to add a product now returns this error. I have tried simplifying the product I am sending to only contain the required fields and no variants and I am still getting this error. I am using a supported version of the API. I have also tried deleting the private app and creating a new one but no joy.

 

Really hoping someone at Shopify can help with this. 

m60digital
New Member
2 0 1

It looks like I have hit the 50k API variant limit so I think the issue might be related to this. It might be related - hoping support can increase our API limit for our initial product import 🤞

parkerjm
Tourist
16 0 3

hmm I will have to check my call rate to see if the error is associated with large spikes in product creation

Kris_Doyle
Shopify Partner
99 0 25

Quick bump to say that I've started getting this again too: 400 Bad Request {"errors":{"publications":"expected Array to be a Hash"}

Looks like it's on this endpoint each time (REST Admin API):
PUT /admin/api/2020-04/smart_collections/{collectionId}.json

In each case I'm doing a simple update to a Smart collection to set it to published. This only happens a few times every couple weeks or so.

The plot thickens! lol 🙂

parkerjm
Tourist
16 0 3

marked topic as unsolved again since this continues to happen for us and others. in the last 60 days, we've seen it happen only 4 times, but last time was yesterday, so definitely still an active issue.

aveshopstech
Shopify Partner
24 0 16

We continue to see this error randomly as well when creating (or maybe updating) products. Again, I'm not touching anything that has to do with collections or smart collections, yet we still see this error. There doesn't seem to be any pattern to when or why this happens, either, except that maybe it seems to happen more frequently when the volume of product creation requests is higher. Or maybe its just that higher volume = more chances for the error to happen, and is not a direct result of the volume. Either way, this really feels like an issue on Shopify's side. Or, at the least, an incorrect/bad error message. Maybe there's a problem somewhere, but I really doubt it has anything to do with collections since I don't set that value for any of my product creation attempts.

aveshopstech
Shopify Partner
24 0 16

WFIW, I was running a script against a shop's API today and got the "publications: expected Array to be a Hash" error when attempting to create a product. I immediately re-ran the exact same job, and it worked without any problems. Meaning, the exact same code pushed the exact same data and request to Shopify and the first time if failed with that unhelpful error code, and the second time it worked. @Shopify... can someone please look at this?

kstar12345
New Member
1 0 1

I am so getting this error. When start my process again that sends the requests, it goes through fine the second or third time. This is still an issue with no resolution.

Kris_Doyle
Shopify Partner
99 0 25

For me this happens probably once or twice every few weeks. It's highly intermittent and I haven't found a way to reproduce it. The last couple of times it happened was with a call to this REST API endpoint:

/admin/api/2020-04/smart_collections/{collection_id}.json

I use this call to update the published status for a given collection.

Cheers,
Kris

aveshopstech
Shopify Partner
24 0 16

As mentioned before, this is happening to me when sending a product create request. I'm not doing anything with publications or collections of any kind. It still happens frequently, so I finally just trapped the specific error and automatically perform a retry, which pretty much always works. Just more evidence that this has nothing to do with the request. Its a bug on Shopify's side. Really wish there was a way to submit official bug reports, or get someone from the Shopify dev team to look at this stuff.

policenauts
Shopify Partner
194 9 57

I am also getting this error intermittently when creating a product variant through /admin/api/2020-04/products.json. I'll send the exact same payload immediately afterward and it works fine. I am passing published:false which leads me to believe this is the problematic field. 

The only other change I made recently was I migrated my server side to Google Cloud Functions (previously I was using Google Apps Scripts). 

I'm also going to try updating to 2020-07 API version to see if that helps.

 

aveshopstech
Shopify Partner
24 0 16

I wonder if this has anything to do with a bug in a specific API version. I'm currently on 2020-01. Is anyone else with this problem on a higher version? @policenauts, once you upgrade it would be great if you'd let us know if you still experience the issue, please!

ecomplement
Shopify Partner
19 0 2

I'm using 2020-07 and this issue still happens. I don't think it is related to any of the collection creation properties, but an error that happens randomly when creating any collection.. I suggest that until Shopify will courteously fix this issue, use a simple retry mechanism. in python:

        for attempt in range(4):
            res = requests.post(
                url="https://" + self.domain + "/admin/api/" + shopify_api_version + "/custom_collections.json",
                json=req_data, headers={"X-Shopify-Access-Token": self.data['shopify_token']})

            if 200 <= res.status_code < 300:
                break

            elif res.status_code >= 500 or (res.status_code == 400 and json.loads(res.text)['errors']['publications'] == "expected Array to be a Hash"):
                logger.warning("error when creating collection attempt: "+str(res.status_code)+". "+res.text)

            else:
                raise AssertionError('error creating collection: '+str(res.status_code)+". "+res.text)

        else: #when all attempts accured.
            raise AssertionError('all collection creation retry attempts failed')

 This works for me.. of course this is a workaround but sometimes you must control your destiny 🙂

Ray14
Shopify Partner
16 0 0

Same here. It is happening randomly, since upgraded API version to 2020-07 even if we don't use the collection at all.