Initial commit
This commit is contained in:
28
api/hooks/webhook/put_update.js
Normal file
28
api/hooks/webhook/put_update.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { bigcommerceApiOAuth, serverBaseURL, bigcommerceStoreHash } = require("../config.js")
|
||||
;(function () {
|
||||
const data = context.data
|
||||
if (context?.user?.auth()?.id) {
|
||||
if (context.data.type === "printful") {
|
||||
throw {
|
||||
status: 500,
|
||||
message: "Printful webhooks update are not supported",
|
||||
}
|
||||
} else {
|
||||
let url = `https://api.bigcommerce.com/stores/${bigcommerceStoreHash}/v3/hooks/${context.data.webhookId}`
|
||||
|
||||
let options = {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json", "X-Auth-Token": bigcommerceApiOAuth },
|
||||
body: JSON.stringify({
|
||||
scope: context?.data?.scope,
|
||||
destination: `${serverBaseURL}webhook`,
|
||||
is_active: context?.data?.active,
|
||||
events_history_enabled: true,
|
||||
headers: { token: "super_secure_and_extremely_secret_big_commerce_webhook_token_123" },
|
||||
}),
|
||||
}
|
||||
|
||||
const response = context.http.fetch(url, options).body.json()
|
||||
}
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user