738
Views
16
Comments
Solved
API Authorization Error
Question

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"}

2020-09-21 08-42-47
Vincent Koning
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. 

2021-04-09 11-42-43
assif_tiger
 
MVP

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


2020-09-21 08-42-47
Vincent Koning

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?

2024-05-03 14-03-28
Sudip Dey

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

UserImage.jpg
Tim Jemison

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

REST3.oml
2020-09-21 08-42-47
Vincent Koning

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?


UserImage.jpg
Tim Jemison

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"}
'

2020-09-21 08-42-47
Vincent Koning
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. 

2021-08-12 11-00-27
Nordin Ahdi
 
MVP

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

REST3.oml
2020-09-21 08-42-47
Vincent Koning

Tim,

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

UserImage.jpg
Tim Jemison

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.

REST3.oml
2020-09-21 08-42-47
Vincent Koning

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.

UserImage.jpg
Tim Jemison

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.



2020-09-21 08-42-47
Vincent Koning

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. 


UserImage.jpg
Tim Jemison

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. 




UserImage.jpg
RPA Vanguard

Hello - I'm a few weeks into OutSystems. I have an issue similar to the topic of this forum thread. I have been trying to work with the ZOHO Mail API. Everything runs smooth until the point where I have to pass two headers to a GET request.  As usual, it works great in Postman, but fails to work in OutSystems. 

I reached out to ZOHO and they got back to me on two requests that I sent around the same time from Postman and from OutSystems. The Authorization header was received on the ZOHO end from Postman, but the exact same token when used from OutSystems was not received. 

The nature of the ZOHO Authorization header is a bit different from the standard "Bearer <access_token>" pattern.

Instead, the token is passed in the following pattern: "Zoho-oauthtoken <zsupp_Access_Token>" 

Here are the log extracts from OutSystems when the Service runs. I can see the token going into the Server Action, but the logs have redacted what is actually being passed in the Authorization header that makes it difficult to troubleshoot the issue.  Here are the logs snippets:


/* I can see the token being composed correctly before the actual REST API is invoked */

Zoho-oauthtoken  1000.e575cb655391706251202e8e8e8ffcb8.2966c55a90984226296e23b001ac0876


/* The redacted line in OutSystems log isn't actually helping to show what was actually passed in the Authorization. ZOHO confirmed that the token was not part of the request */

GET http://mail.zoho.com/api/accounts/6450907????????????/messages/search?searchKey=subject%3aPAYBILL%3a%3asender%3amyserviceaccount%40gmail.com&receivedTime=20160&start=1&limit=1&includeto=true HTTP/1.1

User-Agent: OutSystemsPlatform

Authorization: [redacted]

scope: messages

HTTP/1.1 400 

Connection: keep-alive

X-Content-Type-Options: nosniff

X-XSS-Protection: 1

Content-Length: 119

Content-Type: text/html;charset=UTF-8

Date: Sat, 11 Dec 2021 19:04:34 GMT

Set-Cookie: fc2f5e4ce1=e30668dc42df6294320bb6301d6073f1; Path=/,zmcsr=0efa9443-2158-4083-ba3f-0e8341f81d48;path=/;SameSite=None;Secure;priority=high,_zcsr_tmp=0efa9443-2158-4083-ba3f-0e8341f81d48;path=/;SameSite=Strict;Secure;priority=high,JSESSIONID=2E063DCF22C64BAAE993F2B66B908C6C; Path=/; Secure; HttpOnly

Server: ZGS

Pragma: no-cache

Cache-Control: private,no-cache,no-store,max-age=0,must-revalidate

Expires: Thu, 01 Jan 1970 00:00:00 GMT

X-Frame-Options: SAMEORIGIN

/* This is the error returned. It confirms that the access token was not submitted via the OutSystems HTTP request */

{"data":{"errorCode":"INVALID_TICKET","moreInfo":"Invalid ticket"},"status":{"code":400,"description":"Invalid Input"}}


Can someone help me figure out where I'm going wrong? I've consumed other APIs that are more complex in terms of the request structure, but they all accept the access token as "Bearer".  The ZOHO request on the other hand is really simple in nature, but the access token being passed in follows a different pattern.

Could this be the problem?

thanks!





UserImage.jpg
RPA Vanguard

I suppose this is an unsolvable problem. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.