How to use SAP API portal policy editor to automatically add authentication information to sap API calls

Time:2021-12-31

Open the API portal, find the API to edit, and click open to enter the details page:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

Click policies:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

On the right side of the policy editor, you can see out of the box policies that can help you select policies for your use cases. All security policies are grouped under security, and similar traffic management policies, mediation policies and expansion policies are grouped accordingly.

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

There are flows on the left side of the policy editor. Preflow and postflow are located under the proxy endpoint and target endpoint.

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

Select preflow on the left and mediation policies – > assign message on the right,

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

In the create policy panel, select incoming request for stream:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

The added policy is displayed in the policy as shown in the following figure:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

Enter the source code editor:
How to use SAP API portal policy editor to automatically add authentication information to sap API calls

Copy the following:

<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Add>
<Headers>
    <Header name="apikey">e9ZLBOfIplCOnibykWXsAfkMUexchhHN</Header>
    <Header name="Accept-Encoding">gzip,deflate</Header>
   </Headers>
</Add>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="request"></AssignTo>
</AssignMessage>

You must replace the marked text with the previously copied API key.

This code will enable SAP API management to add the required API key value to each request sent to the API center and accept the compressed format used to effectively transfer data for consumers.

Similarly, give a_ Salesorder flow, add an assign message under mediation policies:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

<!-- This policy can be used to create or modify the standard HTTP request and response messages -->
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>

     <!-- Sets a new value to the existing parameter -->
     <Add>
<QueryParams>
    <QueryParam name="$top">3</QueryParam>
</QueryParams>
</Add>

     <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
     <AssignTo createNew="false" type="request"></AssignTo> </AssignMessage>

This limits the number of fields returned by S / 4hana.

After saving the policy, directly click the API proxy URL after successful deployment:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

You can directly use the API key edited in the policy to access the S / 4hana cloud sales order API without entering the user name and password:

How to use SAP API portal policy editor to automatically add authentication information to sap API calls

More Jerry’s original articles are: “Wang Zixi”:
How to use SAP API portal policy editor to automatically add authentication information to sap API calls