Problem:
Unable to extract form params using below.
eg:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-FormData"> <DisplayName>Extract-FormData</DisplayName> <FormParam name="appKey"> <Pattern>{appkey}</Pattern> </FormParam> <FormParam name="userName"> <Pattern>{usr}</Pattern> </FormParam> <FormParam name="password"> <Pattern>{pwd}</Pattern> </FormParam> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Source clearPayload="false">request</Source></ExtractVariables>
Tested using post man with below input & it doesn't extracts the form params.
input:
header:
Content-Type : application/x-www-form-urlencoded
appKey: abc
userName: 123
password: test1
Please suggest.
Attached sample.
Solved! Go to Solution.
You need to use "x-www-form-urlencoded" instead of form-data.
Javascript Policy,
print(context.getVariable("request.formparam.abc"))
Will print "123" to the trace output from all transactions,
Find more about form-data vs x-www-form-urlencoded here.
Dear @vinay poreddy,
@Anil Sagar is right, you need to use the Content-Type as "x-www-form-urlencoded" while making your calls in Postman to send the form parameters.
If you are using curl command then you can run it as follows:
curl -v -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "appKey=abc&userName=123&password=test1" "<URL>"
In my Javascript I added the following code to print the form parameters:
print("appKey = " + context.getVariable("request.formparam.appKey")); print("userName = " + context.getVariable("request.formparam.userName")); print("password = " + context.getVariable("request.formparam.password"));
I tried the above in my org and it printed the values as shown below:
appKey = abc userName = 123 password = test1
Regards,
Amar
You do not need to extract the form variables with a policy, they are available directly as flow variables. For example request.formparam.userName
You can use this directly in your AssignMessage policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Credentials"> <DisplayName>Assign-Credentials</DisplayName> <Properties/> <Set> <FormParams> <FormParam name="appKey">{request.formname.appKey}</FormParam> <FormParam name="userName">{request.formparam.userName}</FormParam> <FormParam name="password">{request.formparam.password}</FormParam> </FormParams> <Verb>POST</Verb> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
Hope this helps
Tried the suggestion but didn't work.Can you share the postman & trace snapshot if you can?
-Vinay
Below are the snapshots.
As @Anil Sagar and @AMAR DEVEGOWDA mentioned, please try it out and let us know.
If it worked, please accept the answer
You need to use "x-www-form-urlencoded" instead of form-data.
Javascript Policy,
print(context.getVariable("request.formparam.abc"))
Will print "123" to the trace output from all transactions,
Find more about form-data vs x-www-form-urlencoded here.
Dear @vinay poreddy,
@Anil Sagar is right, you need to use the Content-Type as "x-www-form-urlencoded" while making your calls in Postman to send the form parameters.
If you are using curl command then you can run it as follows:
curl -v -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "appKey=abc&userName=123&password=test1" "<URL>"
In my Javascript I added the following code to print the form parameters:
print("appKey = " + context.getVariable("request.formparam.appKey")); print("userName = " + context.getVariable("request.formparam.userName")); print("password = " + context.getVariable("request.formparam.password"));
I tried the above in my org and it printed the values as shown below:
appKey = abc userName = 123 password = test1
Regards,
Amar
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |