I (and a couple of coauthors) recently wrote a book on the API's, and the Attachments topic was definitely a chapter that was worth writing up.
It sounds like you're already on the right track.
What happens in the flow of creating an Incoming Document is that you:
- POST to create an Incoming Document record entry /attachment
- PATCH the Incoming Document entry to have the new /attachmentContent
The body of the POST needs to contain:
- parentType ("Sales Order" for example)
- parentId (the Guid of a Sales Order)
- fileName ("Example PDF")
This will reply with a POST Response that will contain the new Id field of the Incoming Document.
You then do a PATCH call to that Incoming Document, via /companies(CompanyId)/attachments(IncomingDocumentId)/attachmentContent
What it sounds like you're experiencing is that the Incoming Document was created with a Null Guid in a table for "Attachments" that aren't linked to a Document. When subsequent calls are being made, it's trying to make another null guid entry, and that's stopping you.
Two things will help:
- Run page 199 directly (add ?page=199) and remove the Unlinked Attachment
- If your POST call attaches the Document to a Document correctly, then you'll also not hit this table, saving you from errors.
Hope this helps - the API v2.0 reference book has gotten quite some praise for our coverage of Attachments and such.