pdfDocument
Closed this issue · 2 comments
saponteindra commented
Hi,
Do you have any example of upload a document to sale invocies?
That section doesn't have any information to use the endpoint in postman,
Regards.
christianbraeunlich commented
Yes, you are right @saponteindra. Sorry for the inconvenience.
The Attachments
API is something that still needs to be updated.
I've done it locally a few months ago but haven't updated the Postman Workspace yet.
We need to know that uploading files to the specific documents will create an "Incoming Document" (https://learn.microsoft.com/en-us/dynamics365/business-central/across-income-documents):
For the document attachments you would have to create your own Custom API afaik.
Create
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "••••••")
$body = @"
{
`"parentId`": `"ef4f9ac6-b449-ef11-bfe9-6045bdac9971`",
`"fileName`": `"myPDF.pdf`",
`"parentType`": `"Sales_x0020_Invoice`"
}
"@
$response = Invoke-RestMethod 'http://bcserver:7048/BC/api/v2.0/companies(83fb7f98-b449-ef11-bfe9-6045bdac9971)/attachments?tenant=default' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Upload
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("If-Match", "*") # change this for prod env
$headers.Add("Content-Type", "application/pdf")
$headers.Add("Authorization", "<insert_your_authorization_here>")
$body = "<file-contents-here>"
$response = Invoke-RestMethod 'http://bcserver:7048/BC/api/v2.0/companies(83fb7f98-b449-ef11-bfe9-6045bdac9971)/attachments(8be63854-3566-ef11-9223-b37aba01145f)/attachmentContent?tenant=default' -Method 'PATCH' -Headers $headers -Body $body
$response | ConvertTo-Json
saponteindra commented
Thanks for the answer, that helper me a lot.