Devops-Learner
Devops-Learner

Reputation: 505

Need to encode PAT to use it in REST API for azure devops in a BASH script, struck with issue with PAT encoding and passing in the body

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

Upvotes: 1

Views: 1996

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35184

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

Upvotes: 2

Related Questions