How to use Service CallOut for getting access token from external source. I have to write Service Callout for getting this token.
I need to pass below details in header:
Content-Type : application/x-www-form-urlencoded
Authorization : Basic (BASE64ENCODED)
I need to pass below details in Body:
grant_type : refresh_token
refresh_token : {ajaskdkjskjdksj}
Below is my code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="GetThirdPartyAccessToken"> <Request variable="googleAuthRequest"> <Payload contentType="application/x-www-form-urlencoded" variablePrefix="$" variableSuffix="%"><![CDATA[ grant_type=refresh_token&refresh_token=ajaskdkjskjdksj&client_id=CLIENT_ID&client_secret=VERY_SECRET&redirect_uri=myredirectURI ]]></Payload> </Request> <Response>calloutResponse</Response> <Timeout>30000</Timeout> <HTTPTargetConnection> <Properties/> <URL>https://wd2-impl-services1.workday.com/ccx/oauth2/mmc9/token</URL> </HTTPTargetConnection> </ServiceCallout>
Solved! Go to Solution.
your code should look similar to
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1"> <DisplayName>Service Callout-1</DisplayName> <Properties/> <Request> <Set> <Headers> <Header name="Content-Type">application/x-www-form-urlencoded</Header> <Header name="Authorization">Basic xyz</Header> </Headers> <FormParams> <FormParam name="grant_type">refresh_token</FormParam> <FormParam name="refresh_token">{request.formparam.a}</FormParam> </FormParams> </Set> </Request> <Response>calloutResponse</Response> <HTTPTargetConnection> <Properties/> <URL>http://mocktarget.apigee.net/echo</URL> </HTTPTargetConnection> </ServiceCallout>
your code should look similar to
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1"> <DisplayName>Service Callout-1</DisplayName> <Properties/> <Request> <Set> <Headers> <Header name="Content-Type">application/x-www-form-urlencoded</Header> <Header name="Authorization">Basic xyz</Header> </Headers> <FormParams> <FormParam name="grant_type">refresh_token</FormParam> <FormParam name="refresh_token">{request.formparam.a}</FormParam> </FormParams> </Set> </Request> <Response>calloutResponse</Response> <HTTPTargetConnection> <Properties/> <URL>http://mocktarget.apigee.net/echo</URL> </HTTPTargetConnection> </ServiceCallout>
Above looks correct with just few notes
<Request clearPayload="true" variable="myRequest">
so that you have complete control on that request object
Hi,
I hardcoded the refresh_token in the service callout in place of {request.formparam.a} and then tested proxy via trace.
The overall proxy was in error with status 400.
However, I could see the access token generated in Service Callout Response.
But, when I try using POSTMAN by using POST method and URL as proxy end point I get invalid request error. However, if I use same proxy endpoint with all the details(Header, authorization, grant_type, refresh_token) in POSTMAN then I get access token.
Is this expected behaviour ?
Please note that API proxy only has ServiceCallout policy and nothing else.
Yes , it's expected.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |