Azure DevOps Api 203 error with bearer token

Matt Baylis 5 Reputation points
2023-08-11T01:52:50.8266667+00:00

I am trying to call a build pipeline from a function app. I've managed to do it with Powershell, but when using python, azure DevOps keeps giving me a 203 response and the pipeline is never run.

it successfully gets a token, but doesn't look like azure DevOps accepts it.

import datetime
import logging
import azure.functions as func
import os
import requests
import json

app = func.FunctionApp()

@app.route(route="HttpTrigger", auth_level=func.AuthLevel.FUNCTION)
def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    resource = "499b84ac-1321-427f-aa17-267ca6975798/.default"
    endpoint = os.environ['IDENTITY_ENDPOINT']
    header = os.environ['IDENTITY_HEADER']
    headers = { 'X-Identity-Header': header }
    user_managed_identity_id = "&mi_res_id=my UMI resource ID"
    url = f"{endpoint}?api-version=2019-08-01&resource={resource}" + user_managed_identity_id
    name = req.params.get('name')

    if name == "choice1":
        resp = requests.get(url, headers=headers)
        token = resp.json()
        token = token.get('access_token')
        azdevheaders = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {token}"
        }
        body = {
            "templateParameters": {}
        }
        uri = "https://dev.azure.com/
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
43,273 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,500 Reputation points Microsoft Employee
    2023-08-14T03:21:47.0666667+00:00

    @Matt Baylis Welcome to Microsoft Q&A! Thanks for posting the question.

    I understand that Azure function successfully gets a token, but Azure DevOps is not accepting it and getting 203 error.

    Please refer the sample code for HTTPTrigger function. This sample shows how to get an Azure AD access token for a Managed Identity using Azure Identity client library for .NET and authenticate to Azure DevOps to create or get a work item.

    Steps to call Azure Devops REST API using Azure AD access token are mentioned here.

    Refer to this video tutorial which demonstrates how to connect to Azure DevOps using a User Assigned Managed Identity within an Azure Function.

    Please note DevOps is currently not supported in the Q&A forums, the supported products are listed over here https://learn.microsoft.com/en-us/answers/products (more to be added later on).

    You can ask the experts in the dedicated forum over here:
    https://stackoverflow.com/questions/tagged/devops

    https://developercommunity.visualstudio.com/spaces/21/index.html

    **
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.