Add API authentication into an automation send web request

Ward Schwillens_ Schwillie April 20, 2023

I want to use automation to send a REST API - in automation language a Send web request action - but I need to be able to authenticate using an API Key from the receiving platform. 

Here's the authentication documentation from the receiving platform:

image.png

How can I insert this API key in the automations Send web request?

2 answers

2 accepted

3 votes
Answer accepted
Stephen Wrathall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2023

Hi @Ward Schwillens_ Schwillie,

"-u" is curl's way of specifying Basic Authorization. There is an article explaining how to achieve this in detail here:

https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828

To summarise for your case, you'll want to Base64 encode your "<username>:<password>" by running:

echo -n "abcdefghij1234567890:X" | base64

(or an equivalent base64 encoding tool)

and then adding a header to your Web Request with:

Key: Authorization

Value: Basic <your_base64_encoded_output_from_above>

I hope this helps!

Ward Schwillens_ Schwillie April 24, 2023

Thank you for explaining Stephen. I found a base 64 encoding tool to do this for me.

Best regards, Ward.

Like # people like this
1 vote
Answer accepted
Tony Langlet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2023

Hello @Ward Schwillens_ Schwillie 

As @Stephen Wrathall mention you need a base64 auth token generated based on the username and password, I'm not the biggest fan of curl but can provide a Powershell script that will provide the authtoken.

 

$atlassianUsername = <Username>
$atlassianPassword = <Password>
$atlassianAuthToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($atlassianUsername):$($atlassianPassword)"))

 


 

Once you've got that you're able to use the authtoken in a Jira Automation Send Webrequest.

You have to change the web request URL to match what your looking for and the HTTP method to match the endpoint. 

2023-04-24 10_41_03-Automation - Jira.png

Once you get a response you'll have to handle it some how, this is how the above web request is being managed to create a variable for the user. I placed the response in a variable to be able to reuse it throughout the automation. 

2023-04-24 10_23_20-Automation - Jira.png

 

I hope I managed to give you some insight in how you possible could work with the web request.

Stephen Wrathall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 24, 2023

Thanks @Tony Langlet. Minor note that:

applicaiton/json

needs to change to:

application/json

for the "Accept" header in your screenshot.

Tony Langlet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2023

Thanks, I've updated the screenshot, I copied data from a production automation to a test automation and thought my accuracy was good enough to write one word :D

Like Stephen Wrathall likes this
Ward Schwillens_ Schwillie April 24, 2023

Thanks Tony,

I found another way to generate the base64 encoded auth token based on the username and password. The basic authentication with the API key and the "X" worked fine.

I'm now updating freshservice tickets with this API call when specific updates occur in the Jira issue. 

Best regards, Ward

Like # people like this
Max Haley August 15, 2023

Hi Ward - can you explain what you mean by the "X"? is this something you append to your token?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events