Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to access Rest API on confluence to retrieve information

Venneesha August 16, 2023

Trying to replicate the steps in 

Basic auth for REST APIs .

$Text = ‘your_email@domain.com:your_user_api_token’ $Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text) $EncodedText = [Convert]::ToBase64String($Bytes) $EncodedText

throws error '$Text' is not recognized as an internal or external command,
operable program or batch file.

'$Bytes' is not recognized as an internal or external command,
operable program or batch file.

'$EncodedText' is not recognized as an internal or external command,
operable program or batch file.

I am using Windows.

please let me know what am I doing wrong?

Not sure if i need some extra access or permissions.

1 answer

1 accepted

0 votes
Answer accepted
Andrii Maliuta
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.
August 16, 2023

Hello @Venneesha ,

The code looks a little strange. Do you want to use the Powershell script to access data via Confluence REST API?

If yes, you can save the script as .ps1 file and run it with Pshell cli tool:

'confluence.ps1'

$Text = ‘your_email@domain.com:your_user_api_token’ 

$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text) 

$EncodedText = [Convert]::ToBase64String($Bytes) 

$EncodedText

On WIndows just open Powershell and run it

.\confluence.ps1

 On Linux (Ubuntu)

pwsh confluence.ps1
Venneesha August 16, 2023

thanks for the response @Andrii Maliuta .

Can you please let me know the process for Gitbash or from cmd please?

Andrii Maliuta
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.
August 17, 2023

Install Powershell (https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.3) as CMD or GItBash need to have PS on PATH.

After you install it and it is present in system PATH, you can just use the 'pwsh' and specify the script file name as a parameter to run it:

``` pwsh SCRIPT_NAME.ps1  ```

Please note that you can use any CLI tool (HTTP client) to interact with Confluence REST API , like: Curl, Httpie, Any programming language client, etc.

Venneesha August 17, 2023

Appreciate your resposne@Andrii Maliuta 

I was unable to install powershell as I am working on my company laptop and so asking the commands for gitbash. Even VS code should be fine.

Thanks!

Andrii Maliuta
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.
August 17, 2023

@Venneesha ,

Yes, sure, you can use any tool, but using VS Code, anyway you need to install the Powershell addon/extension  - It will just do installation and configuration for you.

Please note that PShell is a framework: command-line shell, a scripting language, and a configuration management framework, so it is required anyway on your laptop - it is up to you how to get it: installing with executable, binary archive, some addon inside other tool, etc.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events