web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

(1) ShareShare
ReportReport
Posted on by 22
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:
I have the same question (0)
  • Martin Dráb Profile Picture
    236,025 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
    22 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
    236,025 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
    76 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 868 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 836 Super User 2025 Season 2

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 661

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans