Update Inventory on Product View

The Square API provides methods to adjust the inventory/stock levels and works well. For example, we have an API that imports the product information including stock from our suppliers API.

The only option I see is to scan current products in Square and query the supplier for the stock count manually or in intervals.

What I would like to do is have the square website call our custom API to update inventory on product view using the square website. I don’t see a webhook/subscription on product views so we can automatically update the inventory in Square API.

Another Example: Currently 10 in stock with the supplier but is discontinued after stock reaches 0. If a competitor/partner bought all 10 before we manually updated the stock in Square, we would need to issue a refund as the product is NLA. To fix that, we would like to create a webhook on product views with items from X supplier.

I been digging into creating a website JS snippet in the square website to make this call on product selection or clicking a product link. This way we can get the current stock level from the supplier before allowing the customer to add the item to the cart. This I feel would be cumbersome, and not sure the square website will update quick enough to reflect the new stock levels. Example: On redirection to product view page, check and or update stock level before loading the product page or even on product page load run snippet first.

If anyone has tacked this or have any suggestions, it would be really appreciated.

Is this the Square online store that your wanting to call the suppliers API to get and show the stock count? If so the online store unfortunately can’t be configured to make an API call to show the stock count from external APIs. :slightly_smiling_face:

We have our own website/tools and API that uses the Square API to manage the suppliers’ items and stock. I can than query the supplier get the required data and batch upsert the items to square. We also have a tool that will pull the catalog items from square API and compare the listed items against the suppliers’ inventory and update square according. The issue is it is not dynamic and would like to just update the item when a customer views the online square site product page.

(Simple Test Case) I was able to get the Snippet API to work and call our custom API. From the snippet; I can send a parsed URL on page load and validate and/or update the inventory from our custom API. The issue is the page is already loaded and square website is not updated with the new stock until another refresh. It would be a lot easier if there were a webhook on product click event or the likes. I guess I will have to do it the hard way :wink:

Example of the test Square Snippet.

var parsedProductPageUrl = 'https://api.XYZ.com/CheckItem/ProductId12345'

var testFunc = function()
    fetch(parsedProductPageUrl, {
        method: 'GET',
        headers: {
            'Accept': 'application/json',
        .then(response => response.text())
        .then(text => console.log(text))

document.onload = testFunc();

Yeah, unfortunately you’ll need to do it the other way since like you pointed out there’s no webhook on product click. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

Thank you Bryan, cheers :wink: