0
votes

Im attempting to setup some R code to create a new work item task in Azure Devops. Im okay with a mostly empty work item to start with if thats okay to do (my example code is only trying to create a work item with a title).

I receive a 203 response but the work item doesn't appear in Devops.

Ive been following this documentation from Microsoft, I suspect that I might be formatting the body incorrectly.

https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/create?view=azure-devops-rest-5.1

Ive tried updating different fields and formatting the body differently with no success. I have attempted to create either a bug or feature work item but both return the same 203 response.

To validate that my token is working I can GET work item data by ID but the POST continues to return a 203.


require(httr)
require(jsonlite)

url <- 'https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$bug?api-version=5.1'

headers = c(
    'Authorization' = sprintf('basic %s',token),
    'Content-Type' = 'application/json-patch+json',
    'Host' = 'dev.azure.com'
  )

data <- toJSON(list('body'= list("op"= "add",
                                   "path"= "/fields/System.AreaPath",
                                   "value"= "Sample task")), auto_unbox = TRUE, pretty = TRUE)

res <- httr::POST(url,
                  httr::add_headers(.headers=headers),
                  httr::verbose(),
                  body = data)

Im expecting a 200 response (similar to the example in the link above) and a work item task in Azure DevOps Services when I navigate to the website.

Im not the best with R so please be detailed. Thank you in advanced!

1

1 Answers

0
votes

The POST continues to return a 203.

The HTTP response code 203 means Non-Authoritative Information, it should caused by your token format is converted incorrectly.

If you wish to provide the personal access token through an HTTP header, you must first convert it to a Base64 string.

Refer to this doc described, if you want to use VSTS rest api, you must convert your token to a Base64 string. But in your script, you did not have this script to achieve this convert.

So, please try with the follow script to convert the token to make the key conformant with the requirements(load the base64enc package first):

require(base64enc)
key <- token
keys <- charToRaw(paste0(key,":token"))
auth <- paste0("Basic ",base64encode(keys))

Hope this help you get 200 response code