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

Read target response http status

How can we read target response status and assign it to a new variable in AM.
for example my target status is '200'.
I want to set a variable so that I can later check the status in variable and do further treatment.

I tried this and not working 😞
<AssignVariable>
<Name>_httpStatusCode</Name>
<Value>{response.status.code}</Value>
</AssignVariable>

Any help or hint will be much appreciated.

Solved Solved
0 2 339
1 ACCEPTED SOLUTION

The list of available variables in Apigee is here

https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference

It looks like you're using the right variable, however if you're trying to access another variable with AssignVariable, you should either use the <Ref> tag, or to use a message template ie with the curly braces that you have or other message template functions , use the <Template> tag

<Template>{response.status.code}</Template>

or

<Ref>response.status.code</Ref>

There are further examples in the docs 

https://cloud.google.com/apigee/docs/api-platform/reference/policies/assign-message-policy#assignvar...

View solution in original post

2 REPLIES 2

The list of available variables in Apigee is here

https://cloud.google.com/apigee/docs/api-platform/reference/variables-reference

It looks like you're using the right variable, however if you're trying to access another variable with AssignVariable, you should either use the <Ref> tag, or to use a message template ie with the curly braces that you have or other message template functions , use the <Template> tag

<Template>{response.status.code}</Template>

or

<Ref>response.status.code</Ref>

There are further examples in the docs 

https://cloud.google.com/apigee/docs/api-platform/reference/policies/assign-message-policy#assignvar...

Thank you, it works fine 🙂