Skip to main content

Notifications

Business Central forum
Suggested answer

Can't update attachment with API v2

Posted on by
Using API v2 and `PATCH` to update attachments, keep getting corrupted files. 
I'm using javascript with this logic to create the stream: 
    const readableStream = new Readable();
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    readableStream._read = () => {};
    readableStream.push(fileContent);
    readableStream.push(null);
 
This is the headers: 
Accept: 'application/json',
      'Content-Type': 'application/json; odata.metadata=minimal; odata.streaming=true',
      'IF-MATCH': '*',
      'User-Agent': 'axios/0.26.0',
      'Content-Length': 413658

 
 
What am I doing wrong?
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,242 Super User 2024 Season 2 on at
    Can't update attachment with API v2
    Hi, I suspect it's an Endpoint problem.
    The first thing to note is that this standard Attachment API is not Document Attachment (table 1173), but Incoming Document (table 130). Second, this requires specifying the parent ID.
     
    Although not exactly the same, I mention this in the post below in hopes of giving you some tips.
    How to automatically upload files from OneDrive to Business Central with Power Automate (No customization)
    https://yzhums.com/39365/
     
    Thanks.
    ZHU

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans