TimmerCoder
TimmerCoder

Reputation: 43

Azure DevOps API gives anonymous access error when creating a work item

I have been working on a project to create Azure DevOps work items from a form on a WordPress page. Everything works on my local WordPress installation running on WAMPserver but as soon as it is moved to the development or production servers I get the following error "TF400813: Resource not available for anonymous access. Client authentication required." I am fairly certain that this will be something that needs to be handled on the server but I am not sure what. I was able to due full authentication with the service account that was created for this purpose on my WAMPserver installation but the Windows Server IIS installation is not cooperating. The WordPress page handles authenication and passing data with CURL via PHP. Here is the code.

$url = 'https://organiztion-url/UMCom_DefaultCollection/area_path/_apis/wit/workitems/$'.$_POST['IssueType'].'?api-version=5.0';
    $headers = array('Content-Type: application/json-patch+json');
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);                         
    curl_setopt($curl, CURLOPT_USERPWD, 'account:password');
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);                    
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);                          
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);   
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');//PATCH
    curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($curl);
    $resultStatus = curl_getinfo($curl);

Upvotes: 2

Views: 930

Answers (1)

TimmerCoder
TimmerCoder

Reputation: 43

The solution was to use both a PAT and standard authentication as our local environments could not use the PAT correctly and our Dev, Stage, and Prod environments require the PAT.

Upvotes: 1

Related Questions