web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Authorization Error When Sending Sales Invoice via Email Using Business Central API

(2) ShareShare
ReportReport
Posted on by 10
I am trying to send a sales invoice to my customer through the Business Central API with an email attachment of the invoice. This operation is handled entirely through the Business Central API; I am not making direct calls to the Microsoft Graph API. Despite having all necessary permissions configured in Azure AD, I am encountering an authorization error when attempting to send the email. 
 

Problem Summary:

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.

Setup and Code Implementation:

Business Central Code:
I have written the following code in Business Central to send the sales invoice:

 
al
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:

  • I have registered an app in Azure AD with all necessary permissions for Dynamics 365 Business Central and Microsoft Graph.
  • Permissions granted (with admin consent) include:
    • Dynamics 365 Business Central: AdminCenter.ReadWrite.All, API.ReadWrite.All, Automation.ReadWrite.All, Financials.ReadWrite.All, user_impersonation.
    • Microsoft Graph: Mail.Send, Mail.Read, Mail.ReadWrite, etc.

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.

Request:

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.

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    101,202 Super User 2026 Season 1 on at
    Hi, I'm not sure, it looks like you don't have the permission to send emails. Please check the settings below.
     
    Hope this can give you some hints.
    Thanks.
    ZHU
  • LM-13112017-0 Profile Picture
    10 on at

    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!

     
  • dschulze Profile Picture
    29 on at
    Hello,
    has there been a definitive solution to the problem?
    We are experiencing similar error messages when trying to send an email via API.
    We also suspect the graph rights to be the correct track.
    Has it solved the problem?
     
    Thanks for sharing.

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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,233 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,360 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,216

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans