Send Webhook Upsert
Sends one product to the inbound catalog webhook.
Save this example as 06-send-webhook-upsert.mjs.
import fs from "node:fs/promises"
import { printJson, readConfig, requireStoreId, thyrisRequest } from "./thyris-client.mjs"
const config = readConfig()
const storeId = requireStoreId(config.storeId)
const productsPath = process.argv[2] || new URL("./products.json", import.communication provider.url)
const products = JSON.parse(await fs.readFile(productsPath, "utf8"))
const product = products[0]
const webhookBaseUrl = process.env.THYRIS_WEBHOOK_BASE_URL || config.webhookBaseUrl
if (!webhookBaseUrl) {
throw new Error("Missing THYRIS_WEBHOOK_BASE_URL or webhookBaseUrl config")
}
const result = await thyrisRequest({ ...config, baseUrl: webhookBaseUrl }, "/webhooks/catalog", {
method: "POST",
body: JSON.stringify({
event: "product.upserted",
source: "sample-script",
product: {
storeId,
...product,
},
}),
})
printJson(result)