Notifications
Announcements
No record found.
When I attempt to send an email with the invoice attachment using the Business Central API, I receive the following error:
You are not authorized to access this resource: https://graph.microsoft.com/.default. Contact your system administrator.
This error occurs only when trying to send the sales invoice via email. Other API calls, such as creating and sending electronic documents, work as expected.
Business Central Code: I have written the following code in Business Central to send the sales invoice:
procedure SendInvoiceOIOUBL(jobNo: Text): Integer var SalesInvHeader: Record "Sales Invoice Header"; Customer: Record "Customer"; DocumentSendingProfile: Record "Document Sending Profile"; DocName: Text[150]; CustomerNo: Code[20]; RecordVariant: Variant; CustomerFieldNo: Integer; DocumentNoFieldNo: Integer; ReportUsage: Enum "Report Selection Usage"; begin // Set the report usage to "Sales - Invoice" ReportUsage := ReportUsage::"S.Invoice"; SalesInvHeader.Reset(); // Find the latest posted Sales Invoice where External Document No. equals jobNo SalesInvHeader.SetRange("External Document No.", jobNo); if not SalesInvHeader.FindFirst() then Error('No posted Sales Invoice found for job %1.', jobNo); // Get the Bill-to Customer record if not Customer.Get(SalesInvHeader."Bill-to Customer No.") then Error('Customer %1 not found.', SalesInvHeader."Bill-to Customer No."); // Get the Document Sending Profile if not DocumentSendingProfile.Get(Customer."Document Sending Profile") then Error('Document Sending Profile for customer %1 not found.', Customer."No."); // Assign the SalesInvHeader record to the Variant variable RecordVariant := SalesInvHeader; // Send the electronic document (fails with email) DocumentSendingProfile.Send( ReportUsage.AsInteger(), RecordVariant, SalesInvHeader."No.", CustomerNo, DocName, CustomerFieldNo, DocumentNoFieldNo ); exit(1); // Success end;
Azure AD Permissions:
AdminCenter.ReadWrite.All
API.ReadWrite.All
Automation.ReadWrite.All
Financials.ReadWrite.All
user_impersonation
Mail.Send
Mail.Read
Mail.ReadWrite
Issue: The email sending fails only when trying to send invoices via the DocumentSendingProfile set to email. This call fails with the above error message, despite having the necessary Microsoft Graph permissions. All other Business Central API calls, including sending electronic documents, are functioning as expected.
Could you please advise on why this authorization error occurs specifically for email sending, and if there are additional configurations required for Business Central to use Microsoft Graph permissions indirectly?
I am looking for guidance on how to resolve this issue so that I can send sales invoices via email using Business Central’s API.
Thank you for your assistance in resolving this matter.
Oh wow, Yun Zhu! I recognize you! Thank you so much for your reply—I’ve watched many of your tutorials, and they’ve been incredibly helpful. I truly appreciate all the guidance you share!
Now, to stay on topic: Although I’ve already granted several permissions, I’m still encountering the same error. Could you possibly provide any additional insights or suggest further troubleshooting steps?
Thank you for your time and help!
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
OussamaSabbouh 2,066
YUN ZHU 658 Super User 2025 Season 2
Sumit Singh 595