I have a python project, where i am trying to get user details which set the workflow category state in an Azure Board.
For that, i am loading the workitem history via REST API request and return a json file. The json file looks like that (-> see "Sample Response" https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/updates/get?view=azure-devops-rest-6.0&tabs=HTTP)
I want to return the details of the user, which set the System.State to the Value 'New', 'Approved', 'Committed' or 'Resolved'. If the Value of System.Tags is "MYVALUE" i want to return the user who set the System.State not to 'New'.
For that i tried:
def find_user(updates):
for update in updates:
uniqueName = ''
displayName = ''
if 'fields' in update and \
'System.State' in update['fields']:
if update['fields']['System.Tags']['newValue'] == 'MYVALUE' and \
update['fields']['System.State']['newValue'] == 'New':
continue
elif update['fields']['System.State']['newValue'] == 'New' or \
update['fields']['System.State']['newValue'] == 'Approved' or \
update['fields']['System.State']['newValue'] == 'Committed' or \
update['fields']['System.State']['newValue'] == 'Resolved':
return update['revisedBy']['uniqueName'], update['revisedBy']['displayName']
return uniqueName, displayName
If my workitem have an System.Tags 'MYVALUE' and System.State 'New' i get the user details of the person who set the System.Tags to 'Approved', 'Committed' or 'Resolved'. The problem is that if i do not have the System.Tags 'MYVALUE' my program returns me nothing, altough one of the four System.State are available.
Does anyone have any idea how i can solve this problem?
Thanks in advance!
During my test, I found that we could get the returning correctly with your script, and below is what we edited slightly. And we also suggest that you could set breakpoints to check the response line by line for further troubleshootings.
import os
import json
import requests
def get_jsons(org,proj,workitem_id,pat):
url = "https://dev.azure.com/"+org+"/"+proj+"/_apis/wit/workItems/"+workitem_id+"/updates?api-version=6.0"
payload={}
headers = {
'Authorization': 'Basic '+pat,
}
response = requests.request("GET", url, headers=headers, data=payload)
json_response = json.loads(response.text)
return json_response['value']
def find_user(updates):
for update in updates:
uniqueName = ''
displayName = ''
if 'fields' in update and \
'System.State' in update['fields']:
if update['fields']['System.Tags']['newValue'] == 'MYVALUE' and \
update['fields']['System.State']['newValue'] == 'New':
continue
elif update['fields']['System.State']['newValue'] == 'New' or \
update['fields']['System.State']['newValue'] == 'Approved' or \
update['fields']['System.State']['newValue'] == 'Committed' or \
update['fields']['System.State']['newValue'] == 'Resolved':
return update['revisedBy']['uniqueName'], update['revisedBy']['displayName']
return uniqueName, displayName
org = '{org}'
proj = '{proj}'
workitem_id = '{id}'
base64encoded_pat = '{pat}'
updates = get_jsons(org,proj,workitem_id,base64encoded_pat)
print(find_user(updates))
``