I am new to OutSystems and am trying to get a POST request working in Outsystems.  I have it working in Postman and have the cURL code but can't seem to figure out how to make it work in Outsystems.  When I hit the test button it says my authorization code is invalid and I get a 401 error.  I have triple checked that the auth code in the header parameter is exactly the same as in Postman.  I have tested in Postman and it works fine.  Any suggestions on what I could be doing wrong?

Endpoint: https://stevesie.com/cloud/api/v1/endpoints/e7762587-1426-47ac-b5d5-d9b2836ec89b/executions

Here is the CURL request

POST /cloud/api/v1/endpoints/e7762587-1426-47ac-b5d5-d9b2836ec89b/executions HTTP/1.1
Host: stevesie.com
Token: my_api_key_goes_here_omitted_for_this_post
Content-Type: application/json
Content-Type: text/plain

{"inputs":{"neighborhood_id":"","ne_lat":"","ne_lng":"","property_type_id":"","sw_lat":"","sw_lng":"","checkin_date":"","checkout_date":"","location":"","price_max":"","price_min":"","superhost_only":"","currency":"","limit":"","offset":"","airbnb_api_key":""},"proxy":{"type":"shared","location":"nyc"},"format":"json"}

Hi Tim,

The issue is your token is not passed correctly & hence you are getting 401.

For token-based authentication, use the "OnBeforeRequest" callback to add the required HTTP authorization header to the outgoing requests. Check Simple Customizations for more information

https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Simple_Customizations


Hi, 

I agree with Assif that your passing parameter is not correct. You can share your oml file so we can check and validate and can able to upload the working version for you.


Thank you,

Sudip

assif_tiger wrote:

Hi Tim,

The issue is your token is not passed correctly & hence you are getting 401.

For token-based authentication, use the "OnBeforeRequest" callback to add the required HTTP authorization header to the outgoing requests. Check Simple Customizations for more information

https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/REST/Consume_REST_APIs/Simple_Customizations


Hi Assif_tiger,

I do not agree with your statement. I have loads of reusable components that call API's that require a token for authentication. In none of these I add the header (with the value) in the OnBeforeRequest since the required token needs to be supplied by the consuming application. 


For example I use the following REST for deleting items in Sharepoint Online via the Microsoft Graph;

Here you can see that I configure the Authorization header in the REST action. I then simply the Authorization header via the then automatically made parameters. 


So I'm not really sure what the exact issue is of Tim but adding these headers is not something that only needs to be done via the OnBeforeRequest action. So I suspect his issue lies somewhere else. Perhaps a few screenshot can shed some light?

Thanks everyone for the suggestions.  Here is a screenshot and I have attached the oml file.

Hi Tim, 

I don't think your issue is with OutSystems. I tried the exact same POST in Postman and got the same error. Are you sure that you have the correct key. Aren't there any typos?


I just tried in Postman and it worked fine.  Here is the CURL which can be imported in Postman via the import button top left and then paste raw text:

curl --location --request POST 'https://stevesie.com/cloud/api/v1/endpoints/e7762587-1426-47ac-b5d5-d9b2836ec89b/executions' \
--header 'Token: 3138c6bb-6623-4bef-9da0-c61793a0d117' \
--header 'Content-Type: application/json' \
--data-raw '{"inputs":{"neighborhood_id":"","ne_lat":"","ne_lng":"","property_type_id":"4","sw_lat":"","sw_lng":"","checkin_date":"2020-5-1","checkout_date":"2020-5-28","location":"east palo, CA","price_max":"","price_min":"","superhost_only":"","currency":"","limit":"","offset":"","airbnb_api_key":""},"proxy":{"type":"shared","location":"nyc"},"format":"json"}
'

Solution

I found the issue. The have named the header in OutSystems differently then in Curl/Postman. 

In Curl the header that contains the api key is called: Token
In OutSystems the header that container the api key is called: Authorization

Change the name in OutSystems to the correct value and I'm sure it will work. 

Solution

Hi Tim,

Vincent is right, the header was incorrect.

On top of that, OutSystems needs to generate a structure for the Request Body following the Task Execution instructions of the API. After adding the specified JSON for the Request Body, I got a Status 200 OK.

I added your corrected OML as an attachment.

Regards,

Nordin

Tim,

Don't forget to get a new API key. The one you provided is now out in the open for all to use.

Thanks and I will change the API key.  OK so I too got it working in the Rest builder using the Test button.  I am new to Outsystems and am wondering how I can get this working on a page and have it show the JSON?  Im not sure why I'm getting an error below and if I should put the token, content type in the fields below on the right.  Also not clear if the Request field should have the JSON from the Request body?  Ultimately this is my first time doing a REST call as I'm learning OutSystems. Im trying to have a page display the returned JSON in a text box and then will build on that learning.  Any suggestions are appreciated.

You get this error because you input a text/string ("bbbb") but the Request parameter is of a structure type (as can be seen by de > icon before it's name). Make sure you supply the correct data type and it should work as expected.

Vincent Koning wrote: How do I do that and where? in the expression editor?

You get this error because you input a text/string ("bbbb") but the Request parameter is of a structure type (as can be seen by de > icon before it's name). Make sure you supply the correct data type and it should work as expected.



Tim Jemison wrote:

Vincent Koning wrote: How do I do that and where? in the expression editor?

Hi Tim, 

This issue is separate from what you asked earlier. I will be glad to help you but lets do so in a new thread to keep things nice and clean. Please mark an answer here as a solution that helped you with your initial question and create a new thread for this one. 


Vincent Koning wrote:

Tim Jemison wrote: ok just closed it and thanks for everyone’s help. Opened a new thread here: https://www.outsystems.com/forums/Forum_Post_CreateEdit.aspx

Vincent Koning wrote: How do I do that and where? in the expression editor?

Hi Tim, 

This issue is separate from what you asked earlier. I will be glad to help you but lets do so in a new thread to keep things nice and clean. Please mark an answer here as a solution that helped you with your initial question and create a new thread for this one.