//native
type Square = {
token: string;
};
/**
* UpdateWebhookSubscriptionSignatureKey
* Updates a webhook subscription by replacing the existing signature key with a new one.
*/
export async function main(
auth: Square,
subscription_id: string,
body: { idempotency_key?: string },
) {
const url = new URL(
`https://connect.squareup.com/v2/webhooks/subscriptions/${subscription_id}/signature-key`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago