Skip to main content

Notifications

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.

  • dschulze Profile Picture
    8 on at
    Authorization Error When Sending Sales Invoice via Email Using Business Central API
    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.
  • LM-13112017-0 Profile Picture
    10 on at
    Authorization Error When Sending Sales Invoice via Email Using Business Central API

    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!

     
  • Suggested answer
    YUN ZHU Profile Picture
    84,557 Super User 2025 Season 1 on at
    Authorization Error When Sending Sales Invoice via Email Using Business Central API
    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

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,452

#2
YUN ZHU Profile Picture

YUN ZHU 1,313 Super User 2025 Season 1

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 1,083 Most Valuable Professional

Featured topics

Product updates

Dynamics 365 release plans