How to send an HTTP request to Google Chat when inventory changes?

I’m attempting to set up a workflow that is triggered when inventory quantity changed, and if the total inventory is less than 1, Send HTTP Request to Google Chat.

The step I’m having difficulty with is the last “Send HTTP Request”.

In Google Chat, I go to the space where I want the message posted > Manage Webhooks > Create webhook. I give it a name, and Google Chat only provides the below URL (I’ve edited some of the characters, so this is not the exact URL).

I’m unsure if I need to include something else in the headers (i.e. the token value in the URL, the key value in the URL, etc.). If I include the token and/or key value in the headers, should they be removed from the URL?

Shopify Flow Action details:

Send HTTP Request

HTTP method: POST

URL: https://chat.googleapis.com/v1/spaces/ABCDSExMHiU/messages?key=AIzaSyDdI0hCZtE6vyAbCd-WEfRq3CPzqKqqsHI&token=mBFmc72i08TAbCd-ABC9M82x4onWRjyCbqXS72WWVRQ%3D

HEADERS

Key: Content-Type

Value: application/json; charset=UTF-8

Body:

Zero Inventory - {{productVariant.product.title}} {{productVariant.sku}}

{{productVariant.inventoryItem.inventoryHistoryUrl}}

2 Likes

Cool use case. I think you need to look at the Google Chat API spec. It appears the body must be JSON: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#Message

2 Likes

Thanks @paul_n , that worked.

I’m not familiar/comfortable with JSON whatsoever, but my first attempt worked. I’ll adjust formatting and work on adding more useful information in the body, but thanks again!

Updated body:

{
“text”: “zero inventory {{productVariant.sku}}”
}

1 Like

If you want to get order notifications in Google Chat without using webhooks, you can try out the app https://apps.shopify.com/notify-google-chat