my flow is I need to call an API to get the token and then call the actual API with that token.
I was able to get the token directly calling the token URL from postman without any issues. (screen grab below)
But when I am calling the same endpoint via apigee, I am getting 401 ( endpoint throwing 500).
I understand that I am doing something wrong in my service callout. (screen grabs below)
Postman call via proxy. (please observe I am sending my request details for the actual endpoint in the body)
Apigee Service call out
Apigee Trace Error:
Please let me know if you need more details?
Solved! Go to Solution.
It looks to me that
Have you tried to use x-www-form-urlencoded in the SC?
<ServiceCallout name='SC-1'> <Request> <Set> <Headers> <Header name='content-type'>application/x-www-form-urlencoded</Header> </Headers> <FormParams> <FormParam name='username'>godino@google.com</FormParam> <FormParam name='password'>ILoveAPIs</FormParam> <FormParam name='grant_type'>password</FormParam> <FormParam name='client_id'>ABCDEF</FormParam> <FormParam name='client_secret'>1234567</FormParam> </FormParams> <Verb>POST</Verb> </Set> </Request> <Response>SNPOCAuthResponse</Response> <HTTPTargetConnection> <SSLInfo> <Enabled>true</Enabled> <IgnoreValidationErrors>true</IgnoreValidationErrors> </SSLInfo> <Properties> <Property name='success.codes'>2xx, 3xx, 4xx, 5xx</Property> </Properties> <URL>https://myserver.com/oauth_token.do</URL> </HTTPTargetConnection> </ServiceCallout>
Anything inside the FormParam text element is treated as a message template, so you can refer to context variables by wrapping them in curlies like this:
<FormParam name='username'>{my_username}</FormParam>
It looks to me that
Have you tried to use x-www-form-urlencoded in the SC?
<ServiceCallout name='SC-1'> <Request> <Set> <Headers> <Header name='content-type'>application/x-www-form-urlencoded</Header> </Headers> <FormParams> <FormParam name='username'>godino@google.com</FormParam> <FormParam name='password'>ILoveAPIs</FormParam> <FormParam name='grant_type'>password</FormParam> <FormParam name='client_id'>ABCDEF</FormParam> <FormParam name='client_secret'>1234567</FormParam> </FormParams> <Verb>POST</Verb> </Set> </Request> <Response>SNPOCAuthResponse</Response> <HTTPTargetConnection> <SSLInfo> <Enabled>true</Enabled> <IgnoreValidationErrors>true</IgnoreValidationErrors> </SSLInfo> <Properties> <Property name='success.codes'>2xx, 3xx, 4xx, 5xx</Property> </Properties> <URL>https://myserver.com/oauth_token.do</URL> </HTTPTargetConnection> </ServiceCallout>
Anything inside the FormParam text element is treated as a message template, so you can refer to context variables by wrapping them in curlies like this:
<FormParam name='username'>{my_username}</FormParam>
@Dino-at-Google it worked, at least in my trace I can see the access token and refresh token.
but I have a new issue, See the error below
Where do I configure to pass content-type: JSON for my actual endpoint?
{ "error": { "message": "Invalid content-type. Supported request media types for this service are: [application/json, application/xml, text/xml]", "detail": null }, "status": "failure" }
I am getting below error when I am trying to remove the header from Assign Message flow.
it should be,
<Remove> <Headers> <Header name="header_name">header_value</Header> ... </Headers> </Remove>
No, Remove is like this:
<Remove> <Headers> <Header name="header_name"/> ... </Headers> </Remove>
Also, you don''t need Remove at all if you you use Set rather than Add.
<AssignMessage name="AssignMessageSNPOC"> <Set> <Headers> <Header name="content-type">application/json</Header> ... </Headers> ... </Set> ... </AssignMessage>
Also, if you are setting the content-type, you will also want to set the payload.
I don't suppose the payload is just magically application/json, and only the header is in need of being set.
Thanks @Siddharth Barahalikar . I have made the suggested changes.
API is still returning Invalid content-type error.
{ "error": { "message": "Invalid content-type. Supported request media types for this service are: [application/json, application/xml, text/xml]", "detail": null }, "status": "failure" }
Below is my modified assign message policy, Please let me know if you need any other details.
In the future, Please open a new question to ask a new question.
Thanks, Will do that.