akoliya01
akoliya01

Reputation: 379

Azure Devops 203 Non-Authoritative Information with REST API

enter image description here

While calling a REST API for Azure DevOps I am getting an error 203 Non-Authoritative Information. Actually I want to trigger a release pipeline line with the help of REST API.

Upvotes: 22

Views: 29360

Answers (4)

Rachel
Rachel

Reputation: 1296

I got this error when using InvokeRESTAPI@1 in Devops pipelines, using System.AccessToken for authentication.

This may be an edge case, but I had changed our Service Connection, which had been using a PAT, removing the authentication in order to authenticate via $(System.AccessToken) in the pipeline. Apparently this retains the expectation that you are authenticating via basic auth, resulting in 203 error.

System.AccessToken authenticates as the User named "Project Collection Build Service ({Organization Name})". We also had to ensure that this identity has permission to to Queue the pipeline. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/access-tokens?view=azure-devops&tabs=yaml#job-authorization-scope

  1. Go to the target pipeline, Manage security, find the User, and set Queue Builds permission to Allow.

  2. If the targeted pipeline is in a different project, set Limit job authorization scope to current project for non-release pipelines setting OFF for both the org and the triggering pipeline project.

Upvotes: 0

Danny Beckett
Danny Beckett

Reputation: 20806

I didn't manage to get the other answers here to work, but I found an answer that worked for me on another question.

Here's the full code to connect to DevOps and get work item #123:

import base64
import requests

devops_org = 'Your organization name - check your DevOps URL'
devops_project = 'Your project name - check your DevOps URL'
devops_token = 'Your PAT from DevOps'
workitem_id = 123

b64_token = base64.b64encode(f":{devops_token}".encode()).decode()
headers = { "Authorization": f"Basic {b64_token}" }
response = requests.get(f"https://dev.azure.com/{devops_org}/{devops_project}/_apis/wit/workitems/{workitem_id}?api-version=7.1", headers=headers)

One important note: You MUST use two different variable names! If instead of using b64_token = base64... you attempt to use devops_token = base64... then it will generate a different base64-encoded string every time!

Upvotes: 0

Indrajeet Gour
Indrajeet Gour

Reputation: 4500

Yes, we are passing the PAT wrongly.

Just another way of doing it, COPY the PAT encode that to base64 manually from a site like - https://www.base64encode.org/

Note - make sure you add ":" as a prefix on PAT and then encode that.

Copy the encoded value to header on Authorization as mentioned -

enter image description here

Hope this will help a few, the only catch was to make sure we add the ":" on the mentioned position.

Edit:
Why to add ":"? It is the separator between the Username and Password. In the Official documentation you can see this pattern where the replacement happens with an empty string. link

Upvotes: 7

Mengdi Liang
Mengdi Liang

Reputation: 19026

The 203 error code normally caused by an incorrect PAT format. Looks like you are probably failing authentication because the PAT did not be encoded with base64 correctly.

Ensure the TYPE is Basic Auth, and input the correct PAT format into Password:

enter image description here

Authorization of Postman.

Upvotes: 24

Related Questions