4,375 questions
How to send a webhook using Office Script in Microsoft Excel?
Blagoy Nikushev
0
Reputation points
I need to send webhooks using Office Script in Excel. Here's the flow:
- User fills some data in a table.
- User clicks a button in Excel.
- Script sends data via Webhook to external service (Zapier in this case)
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;
}
Microsoft 365 and Office Development Other
1 answer
Sort by: Most helpful
-
Deleted
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