Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Alexander_Korne
Employee
Employee
In this blog post I will sum up information, necessary for binding URLs to documents, placed in external storage to Journal Entries in SAP S/4HAN A Cloud via API Attachments. During the implementation of the scenario it is necessary to take into account following considerations:

  1. The way to find correct link to do the posting of URL-Attachment

  2. Which values to use to fill the mandatory fields

  3. Whitelisting the sending URL

  4. Where to check the result


Getting link to do the posting


In opposite to the most APIs, this one does not require activation of separate Communication Arrangement. In our case we need to go to communication arrangement, relevant for Post Journal Entry Communication Scenario (SAP_COM_0002). The link for posting can be found there:


Then we need to go to API Attachments documentation and check, how we should enrich the link:
POST<host>/sap/opu/odata/sap/API_CV_ATTACHMENT_SRV/CreateUrlAsAttachment?SemanticObject='Product'&BusinessObjectTypeName='EKKO_RFQ'&LinkedSAPObjectKey='ZTEST_BO'&Url='https://www.sap.com'&UrlDescription='SAP'&MIMEType='text/url

As you can see, first of all we need to add method "CreateUrlAsAttachment", after which we can specify input values.

Filling mandatory fields


As we can see in the documentation there are 5 mandatory for the API fields:

  • BusinessObjectTypeName (value for Journal entry would be BKPF)

  • LinkedSAPObjectKey

  • Url (example value: "https://www.sap.com")

  • UrlDescription (example value: "SAP"

  • MIMEType (example value: "ext/url"


The most tricky is to prepare value for LinkedSAPObjectKey. The formula to build it is as following: Company Code + Journal Entry Number + Year. Therefore example value could look like 111101000056552022. Note, that if your Journal Entry number is shorter, then 10 symbols, corresponding number of  "0" should be added between Company Code and Journal Entry Number. See details in this SAP Note.

After preparing of all the values, the resulting link could look like this:
https://my<Number>-api.s4hana.ondemand.com/sap/opu/odata/sap/API_CV_ATTACHMENT_SRV/CreateUrlAsAttachment?BusinessObjectTypeName='BKPF'&LinkedSAPObjectKey='111101000056552022'&Url='https://www.sap.com'&UrlDescription='SAP'&MIMEType='text/url'

Whitelisting the sending URL


Before clicking "POST" you have to whitelist the sending URL in SAP S/4HANA Cloud. This has to be done in the app "Maintain Protection Allowlists". Details are available here. Example result could look like this:



Test and check the result


Now we are ready to click "POST" in Postman for example. Do not forget to update X-Csrf token value beforehand. Example request would look like this:


And now you can go to SAP S/4HANA Cloud, app "Manage Journal Entries", search for an entry, for which posting was done and the results should be available at the Attachments tab: