
4,380 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to send webhooks using Office Script in Excel. Here's the flow:
Tried both Fetch and XMLHttpRequest but the body of the received webhooks is empty in both cases. Fetch gives an error Unable to fetch but still sends the webhook.
Here's a sample code I've tried:
//XMLHttpRequest
function sendMessage() {
var request = new XMLHttpRequest();
request.open("POST", "webhookurl");
request.setRequestHeader('Content-type', 'application/json');
var content = { "value1": "test data" };
request.send(JSON.stringify(content));
}
sendMessage()
}
//Fetch:
function main(workbook: ExcelScript.Workbook) {
interface WebhookData {
message: string;
}
async function sendWebhook(data: WebhookData) {
const response: Response = await fetch('https://example.com/webhook', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
const json: unknown = await response.json();
return json;
}
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more