Skip to Content
Technical Articles
Author's profile photo David Da Silva

Create a pdf attachment using the Attachments API in S/4HANA Cloud

Welcome to this short blog post showing you everything you need to add an attachment to an object in S/4HANA Cloud by using the Attachments API and Postman. I wanted to write this blog post as I couldn’t find an easy to follow blog post on how to use this API to create a pdf attachment for S/4HANA Cloud.

This blog post assumes that you have already set up the necessary communication arrangement(s) and that you have access to the API with a technical user. If you need help setting up communication arrangements, you can go¬†here. If you don’t know which communication scenario you need to activate, please refer to the Attachments API link above.

Walkthrough

Open up Postman and create a new HTTP request, then fill out the request URL and Authorization (will likely be Basic Authentication for Username/Password).

 

Navigate to the Headers tab and create the following headers:

  • x-csrf-token, for those that do not know, you will first need to do a HEAD or GET request with the value “fetch” in order to retrieve a token to be used in the POST request when we attach the file.
  • slug, this will be the name of the file saved in S4HC
  • Content, this is the file location (Note: you should be able to execute the request with these headers and no Body, however if it doesn’t work for you, please provide a Body as explained later)
  • Content-Type, the file type of the file
  • BusinessObjectTypeName, this is the ID of the object type you want to attach to. My example is for a Sales Order which is value BUS2000116
  • LinkedSAPObjectKey, this is the key or number of the object you want to attach to. My example is for a Sales Order number 8000099999

You are almost ready to attach a file through the API!

Navigate to the Body tab, and select the radio button for “binary”. From here you can select the file you want to upload.

Everything is now in place to attach the file through the API. Now follow these steps

  1. set the value of the x-csrf-token header to fetch
  2. execute a HEAD or GET request to retrieve an x-csrf-token
  3. once you have this token, copy and paste it’s value over the fetch value in the x-csrf-token request header
  4. change the HTTP request to POST now and execute the request

You should see the following successful message:

If you get an error message, then please check the SAP community or comment here and I can help if I can.

If it is successful for you, then navigate to the object and try open the file to ensure it all worked as expected!

I hope you found this bog post useful.

If you have any thoughts, ideas, or feedback, then I encourage you to comment below!

Additionally, if you would like to do further reading around this topic, then please use these great resources: SAP S/4HANA Community page, SAP Q&A page, other SAP blogs.

If you would like similar content, then follow my profile where I will be publishing similar blog posts for easy-to-follow technical insights.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo David Da Silva
      David Da Silva
      Blog Post Author

      This API can attach several different types of objects but these need to be done in a different way.

      Please comment and let me know if you'd like to see blog posts on more of the Attachments API functionality.