cancel
Showing results for 
Search instead for 
Did you mean: 

Set header in api managment flow request

Former Member
0 Kudos

Hi, I'm testing the api managment service and I'm having trouble doing the following:

I need to include a special header in the request flow, How should I perform this operation? Maybe with script policy preflow?

Any idea how I could do this operation? Thnks

View Entire Topic
svenhuberti
Product and Topic Expert
Product and Topic Expert

Hello Rodrigo,

you can use the "AssignMessage" Policy to do so.

Simply add a new policy into you pre-flow/conditional flow/post-flow, in the request.

If you are not sure where to place the policy, check Elijah's great blog on flows. At the beginning it may look complicated, but it is pretty simple and gives you great power!

https://blogs.sap.com/2016/03/17/sap-api-management-understanding-policy-flow/

And here is a simple example of the Assign Message policy:

  <AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
    <Add>
        <Headers>
            <Header name="X-SvenTest">Test</Header>
        </Headers>
    </Add>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
  </AssignMessage>

And here the link to the documentation for more detailed information!

https://help.sap.com/viewer/66d066d903c2473f81ec33acfe2ccdb4/Cloud/en-US/523efe6d0a9d43beb5d62ad0793...

Cheers,
Sven

Former Member
0 Kudos

Thank you for the answer, works perfect.

It is possible to obtain this value to be assigned to the new header making a request to another external API?

That is to say, make a prior request and use that response to assign a value to the next request.

svenhuberti
Product and Topic Expert
Product and Topic Expert

Hello again,

yes, this is absolutely feasible.

To do so, you would use a Service Callout policy, an Extract Variable policy and then an Assign Message policy again.

The Service Callout policy calls the external API.
The Extract Variable policy extracts the desired information from the response of the previous call.
The Assign Message policy does what you did first: assign a variable to a header.

I have documented it in detail in another blog:

https://blogs.sap.com/2016/10/11/sap-api-management-mash-api-proxy/

Hope this helps!
Sven

Former Member
0 Kudos

Thanks for the answer, it has served me a lot

13521697
Newcomer
0 Kudos
Hi Sven, When we apply header in Assign message policy, it works only in success scenarios. Can you let us know why the header is not visible in success scenaiors?