I am using Outlook add in REST call to get attachment details. But I am receiving an error that says:
{ "error": { "code": "RequestBroker--ParseUri", "message": "Resource not found for the segment 'Q7GceiTKAvvXBwAtYompjmwrRqF359uQTkd1AAAAAAEJAAAtYompjmwrRqF359uQTkd1AAAHjsV0AAA='." } }
This is my code:
const encodedItemId = encodeURIComponent(Office.context.mailbox.item.itemId);
Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, async function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
const callbackToken = result.value;
// Construct the URL to download attachment content
const attachmentUrl = 'https://outlook.office.com/api/v2.0/me/messages/' + encodedItemId+ "/attachments";
const headers = { Authorization: `Bearer ${callbackToken}` };
// Fetch attachment content
fetch(attachmentUrl, { headers })
.then(response => response.arrayBuffer())
.then(arrayBuffer => {
const attachmentName = attachment.name;
const base64Data = arrayBufferToBase64(arrayBuffer);
})
.catch(error => {
console.log("Failed to fetch attachment content:", error);
});
I have also tried other variations to construct url, like
const attachmentUrl = ${Office.context.mailbox.restUrl}/v2.0/me/messages/${item.itemId}/attachments/${attachmentId}/$value;
What did I do wrong?
You should use RestID instead of EWSID which is Based64 but not URL safe.