Skip to Content
Technical Articles
Author's profile photo Prabhugoud Gogi

Cloud Integration (SAP CPI) – API_CV_ATTACHMENT_SRV (OData API for attachments)


Recently I faced a use case in which a integration flow needed to add an attachment to a supplier invoice, we have standard OData/SOAP API to perform operations like create, read, rename, and deletion of attachments, In this blog I’m going to discuss adding (creating) an attachment to supplier invoice by consuming OData API.


  1. Before consuming the OData API make sure that API_CV_ATTACHMENT_SRV oData API is active ,system client ID and alias name maintained.
  2. Check the entity list and make sure “AttachmentContentSet” entity set is present to create an attachment.
  3. System user should have sufficient roles assigned to call these API’s.

I assume that you successfully posted the Supplier invoice to the S4/Hana and noted Invoice details like Invoice Number and fiscal year to add an attachment for this invoice.



Below is the integration iFlow design to add an attachment.






Step 1: Fetch x-csrf-token

Set the header x-csrf-token with the value “fetch” and configure the connection like below to get a token.



set header to fetch token





Step 2:

Once we get a token set few mandatory header fields to post attachment .

Parameter Description Value
BusinessObjectTypeName Defines the business object for the supplier invoice. BUS2081 (supplier invoice)

Defines the business object instance key to which the attachment will be linked to.


Enter the key without space between the numbers for the invoice and the fiscal year.

<invoice number><fiscal year>
X-CSRF-Token Validates together with the cookie that the user is an authenticated communication user for the OData service Attachments ( API_CV_ATTACHMENT_SRV). You get the taken value together with the cookie value about the HTTP-GET request.
Slug Defines the file name and file type. Example: sample.txt
Content-Type Defines the mime type of the attachment. Example: Text/plain





Step 3: With the help of pool enricher get an attachment by passing the file name




Step 4:  Post the attachment through API by passing mandatory headers fields .




Step 5: Validate the attachment in S4Hana System.







Supplier Invoice posting

Attachment posting


Hope you find this article helpful and if you have any suggestion and comments, please reply in the Comments section below.


Best regards,

Prabhugoud Gogi

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Saurabh Kabra
      Saurabh Kabra

      Hi Prabhugoud,


      Thanks for such an informative blog. It was really helpful and to the point.

      Maybe just a suggestion...While making the call to S/4 HANA API, you could have used OData V2 connector, and this way it would have been very easy to configure. In the case of complex queries, an XSD would have also been generated by CPI which could be used for further mapping.

      Author's profile photo Prabhugoud Gogi
      Prabhugoud Gogi
      Blog Post Author

      Thanks Saurabh !!

      Yes i agree your point ,we can use OData V2 adapter, since my scenario was quite simple without any complex quires so went with Http connector, Even i tested with OData it works fine, Thanks for the suggestion.


      Prabhugoud Gogi

      Author's profile photo Laura Rainer
      Laura Rainer

      Hi Prabhugoud,
      I am currently struggling with exactly the scenario you describe in your reply. How did you manage to send the attachment via the OData v2 adapter? I always end up with the error "XmlPullParserException: only whitespace content allowed before start tag" because the content modifier doesn't contain an XML structure. My attachement is an excel file that comes into the flow via HTTPS sender and is customized afterwards. Unfortunately the HTTP adapter is not available to me as a solution, so I hope you see my question! I would be very happy to get an answer from you.



      Author's profile photo Varun Vichare
      Varun Vichare

      Hello Prabhugoud,


      What steps we need to perform for a FI posting integration scenario ?



      Varun Vichare.

      Author's profile photo Prabhugoud Gogi
      Prabhugoud Gogi
      Blog Post Author

      HI Varun,

      For most the scenario we do have standard API's for FI posting you can make use of those ,follow the respective API document which says what parameters need to pass ,consuming process remains same.



      Author's profile photo Sathyabhama B T
      Sathyabhama B T

      Informative ! Thanks Prabhu for your article.



      Author's profile photo Avinash Mallashetty
      Avinash Mallashetty

      helpful blog!

      thanks for sharing.

      regards, Avinash

      Author's profile photo Erik Hoven
      Erik Hoven

      http-adapter for posting the attachment - and not an odata-adapter ?

      Author's profile photo Sreeni Kadiri
      Sreeni Kadiri

      more informative and useful.  I have different use case, using attachment service ODATA api, archive/store the document in external DMS repository ( OpenText), current the attachment stored in SAP default DMS. Please let me know.