Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Send attachment to Dynamics Business Central via c#

(0) ShareShare
ReportReport
Posted on by 130

Hi, 

I am trying to implement adding attachments to Business Central via Oauth

Maybe I am doing something wrong, please, look at my steps.

1)POST to create an Incoming Document record entry /attachment

pastedimage1678282342958v3.png

where _connectionDynamicsBusinessCentralOptions.Scope value is "">api.businesscentral.dynamics.com/.default"

URL is /v2.0/fc586214-b714-4bc4-8ff8-2e13a1a007cd/Sandbox/api/v2.0/companies(51fafb6c-c141-ec11-bb7e-000d3abb14eb)/salesOrders

BODY is {"externalDocumentNumber":"finally","currencyCode":"EUR","customerNumber":"10000","orderDate":"2023-08-05"}

The request is successful and data already generated in dynamics' system 

pastedimage1678282585408v7.png

2) Step 2 I retrieved Parent Id

pastedimage1678283984857v1.png

3) Step 3

I am trying to create attachment

pastedimage1678282729452v9.png

URL is  /v2.0/fc586214-b714-4bc4-8ff8-2e13a1a007cd/Sandbox/api/v2.0/companies(51fafb6c-c141-ec11-bb7e-000d3abb14eb)/attachments

BODY is  {"parentId":"5157829e-b5bd-ed11-9a88-002248d5380a","fileName":"123.txt"}

Request is successful and I get Id for attachment 

pastedimage1678282859523v10.png

4)Step 4

Everything is ready for PATCH method  via /companies(CompanyId)/attachments(IncomingDocumentId)/attachmentContent

I am using the following code

pastedimage1678282921686v11.png

In this part user and password are client id and client secret for Oauth authentication

pastedimage1678282973811v12.png

 BaseAddress is "api.businesscentral.dynamics.com/.default"

pastedimage1678283001925v13.png

Authorization parameter is Bearer  - oauth token 

pastedimage1678283052699v14.png

URl is following

 pastedimage1678283531241v16.png

And I get this

 pastedimage1678283594851v17.png

What I am doing wrong at that part ?

  • Suggested answer
    Dynamics Questions Profile Picture
    Dynamics Questions 130 on at
    RE: Send attachment to Dynamics Business Central via c#

    Thank you

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Send attachment to Dynamics Business Central via c#

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    www.dynamicsuser.net/.../14

    I will open this up to the community in case they have something to add.

    Thanks.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans