How do I create a request message for a service callout policy?

1 1 6,598

When you leverage the ServiceCallout policy in Apigee Edge, there are a couple options for creating the HTTP request message used for that callout:

  1. Use an AssignMessage policy before the callout to create a new message variable with your headers, query parameters, path, payload, etc. You then reference the message variable like <Request variable="myCalloutRequest" /> .
  2. Directly use the AssignMessage <Set> config within the ServiceCallout policy assign the headers, query parameters, path, payload, etc. without having to use an AssignMessage policy execution before the callout.

Option #2 can be preferred to avoid an extra policy definition in your API proxy. An example policy for setting the HTTP request message directly in the ServiceCallout policy is below:

<ServiceCallout name="myServiceCallout">
    <Request>
      <Set>
        <Headers>
          <Header name="Accept">application/json</Header>
        </Headers>
        <Verb>POST</Verb>
        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">{"message":"my test message"}</Payload>
      </Set>
      <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>calloutResponse</Response>
    <HTTPTargetConnection>
        <Properties/>
      <URL>http://httpbin.org/post</URL>
    </HTTPTargetConnection>
</ServiceCallout>
Comments
mrios
New Member

@Michael Russo I'm trying to implement the option 1 without success yet.

I created an AssignMessage policy where I set the header with some variables. Like this:

<Set>
	<Headers>
		<Header name="somevariable">{messageid}</Header>
        </Headers>
        <QueryParams/>
        <FormParams/>
</Set>

That policy is before the Service Callout policy.

The problem is that on the Edge I see that the header is set but when I check the headers through an echo endpoint (shows the header of the request) on the Service Callout the variables are not there.

Any idea what could be the problem?

Let me know if you want me to create a new thread with the question.

Thanks.

Version history
Last update:
‎03-31-2015 10:28 AM
Updated by: