1

Need to encode PAT to use it in REST API for azure devops, struck with issue with PAT encoding and passing in the body. Need help with the format to encode PAT and use it in the body of REST. I am using this in a BASH script

#PAT-Encoding

B64_PAT=$(printf "%s"":$PAT" | base64)


#Create Repo in Azure

"Repo_Creation_Status=$(curl --write-out "%{http_code}\n" --location --request POST "https://dev.azure.com/"${OrganizationName}"/"${projectId}"/_apis/git/repositories?api-version=6.1-preview.1" \
        --header "Authorization: Basic ${B64_PAT}" \
        --header "Content-Type: application/json" \
        --data-raw '{
  "name": "'"$RepoName"'",
    "project": {
        "id": "'"$projectId"'"
          }
}' --output output.txt --silent)"
Devops-Learner
  • 451
  • 1
  • 4
  • 16

1 Answers1

2

To create a repo with CRUL script, you could directly use the PAT without coding it.

Here is an example:

curl -X POST \
-u  :PAT  https://dev.azure.com/orgname/projectname/_apis/git/repositories?api-version=6.1-preview.1 \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ 
   "name": "Reponame", 
    "project": 
        {
           "id": "ProjectID" 
        }
}' 
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • 1
    This will work as well, I had tested this via Postman and through that PAT tokens are getting encoded for Basic Authorization, so thought of picking up that code and add it via passing encoded PAT in my BASH script. Thanks for suggestion. – Devops-Learner May 11 '21 at 07:15
  • Hi @Vishal If the answer could give you some help, you may consider accepting it. Thank you. – Kevin Lu-MSFT May 11 '21 at 07:24