Home > Software engineering >  Azure Devops API status code 200 on get but 404 on PUT
Azure Devops API status code 200 on get but 404 on PUT

Time:12-22

I am trying to write a bash script to disable/enable a pipeline in Azure Devops.

I just need to perform a PUT request as per the documentation. But first I need to run a GET in the same endpoint to get json, then modified it and send back using PUT.

The GET request works fine Get request

https://{{coreServer}}/{{organization}}/{{project}}/_apis/build/definitions/453?api-version={{api-version}}

Response status code 200

 ...
 "id": 453,
 ...
 "type": "build",
 "queueStatus": "disabled",
 "revision": 8,
 ...

The PUT request URL:

https://{{coreServer}}/{{organization}}/{{project}}/_apis/build/definitions/453?api-version={{api-version}}

The PUT body

 ...
 "id": 453,
 ...
 "type": "build",
 "queueStatus": "enabled",
 "revision": 9,
 ...

Response from PUT:

 "$id": "1",
    "innerException": null,
    "message": "Build pipeline 453 was not found.",
    "typeName": "Microsoft.TeamFoundation.Build.WebApi.DefinitionNotFoundException, Microsoft.TeamFoundation.Build2.WebApi",
    "typeKey": "DefinitionNotFoundException",
    "errorCode": 0,
    "eventId": 3000
}

The token to connect has the correct scope and permission. How is possible to find the correct resource on GET but not on PUT? What I am missing?

CodePudding user response:

By checking your API, you are using enter image description here

Using PUT to disable the queueStatus with the json body from above GET API

enter image description here

Updates an existing build definition. In order for this operation to succeed, the value of the "Revision" property of the request body must match the existing build definition's. It is recommended that you obtain the existing build definition by using GET, modify the build definition as necessary, and then submit the modified definition with PUT.

From your GET API, the revision is 8. Do not modify the revision to 9, just change the "queueStatus" and keep the same revision 8 as GET json to make sure the revision is matched.

Modify your PUT body as below:

 ...
 "id": 453,
 ...
 "type": "build",
 "queueStatus": "enabled",
 "revision": 8,
 ...
  • Related