Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How do I access variables in a Json Payload that is stored in a context variable?

Hi,

I have a Proxy which does a service call out to a get_oAuthToken service of the backend and gets a JSON Payload and stores it in a context variable "calloutResponse". how do i access the token variable in the JSON payload stored in the context variable. I have the below setup in my assignmessage policy.

<AssignMessage continueOnError="false" enabled="true" name="generateCustomResponse">
  <DisplayName>generateCustomResponse</DisplayName>
  <Set>
    <Payload variableSuffix="@" contentType="application/json" variablePrefix="#">
    { "toke" : #calloutResponse.access_token@ }</Payload>
    <Path/>
  </Set>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
Solved Solved
0 3 765
1 ACCEPTED SOLUTION

Try an ExtractVariables policy before the assign message policy and then use the variables created in the assign message policy.
https://cloud.google.com/apigee/docs/api-platform/reference/policies/extract-variables-policy#json

View solution in original post

3 REPLIES 3