I'm trying to use a Javascript callout, and inside the callout I'm simply trying to retrieve something from the request
Example, here is my request in postman with a JSON body
{ "email" : "janetutorialxml@example.com", "first_name" : "Jane", "lastName" : "Tutorial", "userName" : "jtutorialxml" }
And in apigee I have a callout as the following
var firstName = context.getVariable('request.formparam.first_name')
Expected result
Jane
Actual result
null
Solved! Go to Solution.
A request including form parameters will include a body such as
key1=value1&key2=value2
and its content type will be set to
application/x-www-form-urlencoded
Your request looks like a typical JSON request (Content type = application/json). You can extract values using an ExtractVariable policy such as:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-GetFirstName"> <DisplayName>EV-GetFirstName</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="firstName"> <JSONPath>$.first_name</JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">request</Source> </ExtractVariables>
You can of course do this with JavaScript, but using an out of the box policy is quicker and neater
A request including form parameters will include a body such as
key1=value1&key2=value2
and its content type will be set to
application/x-www-form-urlencoded
Your request looks like a typical JSON request (Content type = application/json). You can extract values using an ExtractVariable policy such as:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-GetFirstName"> <DisplayName>EV-GetFirstName</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="firstName"> <JSONPath>$.first_name</JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">request</Source> </ExtractVariables>
You can of course do this with JavaScript, but using an out of the box policy is quicker and neater