MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
946 stars 278 forks source link

Cannot create ResourceFeedback #471

Closed kseniyaleutseyeva closed 3 years ago

kseniyaleutseyeva commented 3 years ago

Hi,

I have issues when trying to create a ResourceFeedback. A request like this:

await shopify.resourceFeedback.create({
  state: 'requires_action',
  messages: ['is not connected. Connect your account to use this sales channel.'],
  feedback_generated_at: new Date().toISOString(),
});

always throws this error:

{
  code: 'ERR_INVALID_ARG_TYPE',
  message: 'The "url" argument must be of type string. Received undefined',
}

Stack trace:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
  at validateString (internal/validators.js:118:11)
  at Url.parse (url.js:159:3)
  at Object.urlParse [as parse] (url.js:154:13)
  at <project_folder>/node_modules/shopify-api-node/index.js:141:42
  at processTicksAndRejections (internal/process/task_queues.js:97:5)

Kind regards

lpinca commented 3 years ago

This happens because the 202 response status code is handled differently (see https://github.com/MONEI/Shopify-api-node/issues/261 and https://github.com/MONEI/Shopify-api-node/pull/298 for the motivations), but it seems no Location header is returned for ResourceFeedback and instead the resource is created immediately.

I think Shopify is using the wrong status code in this case. It should be 201 and not 202 but it seems consistent with the documentation.

I'm not sure how to fix this. I can only think about creating a special case for ResourceFeedback or adding an option to make polling for 202 responses optional.

kseniyaleutseyeva commented 3 years ago

Thank you for the explanation. I tried reaching out to Shopify support to receive some comments on this topic but to no avail.

As another possible solution: check if the required headers are present in the reply and skip polling if they are missing.

lpinca commented 3 years ago

check if the required headers are present in the reply and skip polling if they are missing

Yes this is good idea.

rlweb commented 3 years ago

Thanks, for the fix @lpinca I just hit this and was very confused by Shopify's handling in this case!