Monday, 6 September 2021

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

Introduction:

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.

Pre-requisite:

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.

Steps:

Below is the integration iFlow design to add an attachment.

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
iflow

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.

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
set header to fetch token

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
getToken

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)
LinkedSAPObjectKey 

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

Note

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 

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
SetHeaders

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

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
sftpCallToGetfFle

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

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
postTheAttachmentThroughAPI

Step 5: Validate the attachment in S4Hana System.

SAP HANA Exam Prep, SAP HANA Tutorial and Material, SAP HANA Learning, SAP HANA Career, SAP HANA Study Material, SAP HANA Preparation, SAP HANA Guides
AttachmentPostedSuccessfully

No comments:

Post a Comment