Add API authentication into an automation send web request
Asked by Ward Schwillens_ Schwillie:

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](/t5/image/serverpage/image-id/252948i86443C5EF48010ED/image-size/large?v=v2&px=999 "image.png")

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


Answers:
author: Stephen Wrathall
body: Hi [@Ward Schwillens_ Schwillie](/t5/user/viewprofilepage/user-id/1028001),

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

comments: author: Ward Schwillens_ Schwillie
body: Thank you for explaining Stephen. I found a base 64 encoding tool to do this for me.

Best regards, Ward.


author: Tony Langlet
body: Hello [@Ward Schwillens_ Schwillie](/t5/user/viewprofilepage/user-id/1028001)

As [@Stephen Wrathall](/t5/user/viewprofilepage/user-id/4974779) 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](https://community.atlassian.com/t5/image/serverpage/image-id/253521i1ADDA511FF66E3AC/image-size/large?v=v2&px=999 "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](https://community.atlassian.com/t5/image/serverpage/image-id/253518i3F1428DFFE563C8F/image-size/large?v=v2&px=999 "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.

comments: author: Stephen Wrathall
body: Thanks [@Tony Langlet](/t5/user/viewprofilepage/user-id/1284310). Minor note that:

```
applicaiton/json
```

needs to change to:

```
application/json
```

for the "Accept" header in your screenshot.


author: Tony Langlet
body: 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


author: Ward Schwillens_ Schwillie
body: 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


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


Tags: api

authentication

cloud