Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
farski

Getting Inventory from Orders API response

Recommended Posts

Posted (edited)

I looking for a way to retrieve inventory data related to an order.

I have a webhook setup in Stripe, to get notifications when orders are placed. Stripe passes along the Squarespace

orderId

, so I'm able to use the Orders API to get data about the order. The Inventory API, though, expects a

variantId1

, and it doesn't seem like that is included in the Orders API response. The only inventory-related values I'm seeing in the order response are

sku

and

productId

, but neither of those work as values to send to the Inventory ID.

Is there a way to do this, other than requesting the entire inventory from the API and paging through it until I find the correct SKU?

Thanks

Edited by farski
Initial Revision

Share this post


Link to post

Hey farski,

I've been able to tackle this issue through API automation. To extract the Inventory ID for the specific products ordered, you need to pull the Order from the Order API and parse the result, specifically (per order row), look at '{lineItems}{<index>}{id}'. I use Python to loop through the products and flatten the structure before import into our backend system, so i do not use the <index> field, I just throw it into a loop that hands me the list of items and I parse the fields I want.

Once you have the lineItem ID, you can send that through the Inventory API, and you should get the inventory record you are looking for.

Alternatively, as a business process, as I upload or create new inventory on the site, I do a full pull from the Inventory API and then match the internal DB SKU to the SKU connected to the VariantId. I then retain this and when I want to query the inventory item (or change quantity, and hopefully price soon), I can easily extract the ID from my db and submit the right call.

Hope that helps.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...