Open the API portal, find the API to edit, and click open to enter the details page:
Click policies:
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.
There are flows on the left side of the policy editor. Preflow and postflow are located under the proxy endpoint and target endpoint.
Select preflow on the left and mediation policies – > assign message on the right,
In the create policy panel, select incoming request for stream:
The added policy is displayed in the policy as shown in the following figure:
Enter the source code editor:
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:
<!-- 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:
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:
More Jerry’s original articles are: “Wang Zixi”: