MONEI / Shopify-api-node

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

inventoryLevel.set(...) not outputting anything. #415

Closed philr35 closed 3 years ago

philr35 commented 3 years ago

Hi, I'm trying to do something very simple. I'm trying to set all variants of a product to 0.

I'm using this code here:

return shopifyInstance.productVariant.list(product_id).then(variants => {
  console.log("Variants")
  console.log(variants)

  // Get the inventory item ID for all variants
  return variants.map(({ inventory_item_id }) => {
    console.log("-- Variant Inventory ID --")
    console.log(inventory_item_id)

    console.log({
      "location_id": origin_location_id || LOCATION_ID,
      "inventory_item_id": inventory_item_id,
      "available": 0
    })

    // Set all variants to 0
    return shopifyInstance.inventoryLevel.set({
      "location_id": origin_location_id || LOCATION_ID,
      "inventory_item_id": inventory_item_id,
      "available": 0
    }).then(
      res => console.log(res),
      err => console.log(err)
    )
  })

For some reason, inventoryLevel.set is not outputting anything to my console. No responses, no error, nothing. Every console.log above invetoryLevel.set is being printed out just fine. I can't figure this one out.

Questions:

  1. Am I calling the set function correctly?
  2. Why is there no output?
philr35 commented 3 years ago

I am following the Shopify documentation here: https://shopify.dev/tutorials/manage-product-inventory-with-admin-api

lpinca commented 3 years ago
  1. Am I calling the set function correctly?

Yes, it looks like you are using it correctly.

  1. Why is there no output?

I don't know, the request probably times out. Try to change the value of the timeout option.

What version of shopify-api-node and Node.js are you using? Try to see if it works with shopify-api-node@2.

philr35 commented 3 years ago

@lpinca This is what's inside of my dependencies:

"dependencies": {
  "aws-serverless-express": "^3.3.5",
  "body-parser": "^1.17.1",
  "express": "^4.15.2",
  "shopify-api-node": "^3.4.4"
}

I'll try shopify-api-node@2. I'm using this inside of my AWS lambda function which is called by a Shopify webhook.

Try to change the value of the timeout option.

I see the default is 1minute until timeout, but the function exits way before that. So I don't think it's timing out. Perhaps it's exiting preemptively? But not sure why, since all my other GET requests work fine. Only when I try to update the inventory level does it not output anything.

philr35 commented 3 years ago

I also confirmed the location_id was correct by doing postman request directly via shopify admin api. But even if it wasn't, there should be some sort of error, no?

Edit: Likewise if it succeeded, it should output something, right? I'm getting neither which is frustrating to troubleshoot

lpinca commented 3 years ago

But even if it wasn't, there should be some sort of error, no?

Yes, the promise should be rejected with an error.

Likewise if it succeeded, it should output something, right?

Correct. It should return something like this https://github.com/MONEI/Shopify-api-node/blob/6428f553388eecc33a42d548a44abe59b14ce0c5/test/fixtures/inventory-level/res/set.json#L3-L6

philr35 commented 3 years ago

I got it working. I tried doing hardcoded values, like so:

await shopifyInstance.inventoryLevel.set({ location_id: 47869067432, inventory_item_id: 36688460873896, available: 0 }).then(
  res => {
    console.log("SUCCESS:")
    console.log(res)
  },
  err => {
    console.log("ERROR:")
    console.log(err)
  }
)

And it was successful! I looked back at my original code, and indeed it does look like some promise issues in there that I need to sort out. Thanks for helping!

eduhdev12 commented 9 months ago

Hello, I'm encountering the same issue in the same situation. What I can do?