Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Downloading an order confirmation and invoice PDF from a web site that is outside Dynamics 365

(0) ShareShare
ReportReport
Posted on by 2
How do you download an order confirmation and an invoice pdf that is produced by Dynamics 365 Finance and Operations through a REST api being called by a custom web site?
Categories:
  • Martin Dráb Profile Picture
    231,707 Most Valuable Professional on at
    Downloading an order confirmation and invoice PDF from a web site that is outside Dynamics 365
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
     
    Please tell us more about the scenario. How will you identify which file to download? Will the file already exist? If so, where? In the print archieve, for instance? 
  • JD-12031334-0 Profile Picture
    2 on at
    Downloading an order confirmation and invoice pdf from a web site that is outside Dynamics 365
    The D365 product is Finance Operations.
  • Martin Dráb Profile Picture
    231,707 Most Valuable Professional on at
    Downloading an order confirmation and invoice pdf from a web site that is outside Dynamics 365
    Which D365 product are you using? The D365 brand covers quite a few things, such as Finance and Operations, Business Central or Customer Engagement.

    Even if its F&O, don't pay much attention to saroha's answer, because it doesn't cover several important questions, e.g. whether the PDF file should be generated on demand, whether you assume it already exists and is attached to some record etc. Let's discuss details when we know which D365 app you're interested in.
  • saroha varun Profile Picture
    72 on at
    Downloading an order confirmation and invoice pdf from a web site that is outside Dynamics 365
    To get an order confirmation and an invoice PDF from Dynamics 365 Finance and Operations (FnO) using a REST API, you can do this:
    1. **Authenticate**: First, get an OAuth 2.0 token to confirm your API requests. Tools like Postman can help you generate this token.
    2. **Find the Right API**: Use either the Data Management Framework's package API or the Recurring Integrations API, depending on what you need. Both support REST and can manage file-based integrations.
    3. **Export Data**:
    - **Order Confirmation**: Use the right endpoint to export order confirmation data. You might need to create a data project in Dynamics 365 FnO and use the API to export the data package.
    - **Invoice**: Similarly, use the right endpoint to export invoice data. Create a data project for invoices and use the API to export the data package.
    4. **Download the PDF**: After exporting, use the API to download the file. The API will give you a URL to the exported file, which you can then download easily.
     
     
    here is an example please reverify with your techie:
    import requests

    # Step 1: Authenticate and get the OAuth token
    auth_url = "https://login.microsoftonline.com/{tenant_id}/oauth2/token"
    auth_payload = {
        'grant_type': 'client_credentials',
        'client_id': 'your_client_id',
        'client_secret': 'your_client_secret',
        'resource': 'https://your_dynamics_instance_url'
    }
    auth_response = requests.post(auth_url, data=auth_payload)
    auth_token = auth_response.json().get('access_token')

    # Step 2: Export the invoice data
    export_url = "https://your_dynamics_instance_url/data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.Export"
    headers = {
        'Authorization': f'Bearer {auth_token}',
        'Content-Type': 'application/json'
    }
    export_payload = {
        "DefinitionGroupId": "InvoiceExport",
        "ExecutionId": "your_execution_id",
        "EntityName": "InvoiceEntity",
        "ExportFormat": "PDF"
    }
    export_response = requests.post(export_url, headers=headers, json=export_payload)
    export_file_url = export_response.json().get('FileUrl')

    # Step 3: Download the PDF
    pdf_response = requests.get(export_file_url, headers={'Authorization': f'Bearer {auth_token}'})
    with open('invoice.pdf', 'wb') as file:
        file.write(pdf_response.content)
     
     

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,815 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,707 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans