devopshq / tfs

Microsoft TFS API Python client
https://devopshq.github.io/tfs/
MIT License
110 stars 28 forks source link

Unable to create work items #77

Open harsheel87 opened 5 years ago

harsheel87 commented 5 years ago

I am using Azure DevOps Server 17.143.28912.1.

I am able to invoke get_workitem calls but create_workitem calls fail. Can someone point me what I may be doing wrong?

staging_client =  TFSAPI("https://staged-tfs.lan/tfs/", pat = 'pat')

fields = {'Title': 'test item: placeholder for new bug', 'Description': 'My description', 'AreaPath': 'Dev\\Data\\Server One', 'IterationPath': 'Dev\\Data Server', 'AssignedTo': 'TFSUnassigned <TSI\\_TFSUnassigned>'}

workitem = staging_client.create_workitem('DEFECT', fields=fields, api_version=5.0)

ERROR:

  ..
  File "E:\automateDashboard\proj1\venv\lib\site-packages\tfs\connection.py", line 309, in create_workitem
    api_version)
  File "E:\automateDashboard\proj1\venv\lib\site-packages\tfs\connection.py", line 282, in __create_workitem
    raw = self.rest_client.send_post(uri=uri, data=data, headers=headers, project=True, payload=params)
  File "E:\automateDashboard\proj1\venv\lib\site-packages\tfs\connection.py", line 456, in send_post
    return self.__send_request('POST', uri, data, headers, payload=payload, underProject=project)
  File "E:\automateDashboard\proj1\venv\lib\site-packages\tfs\connection.py", line 506, in __send_request
    response.raise_for_status()
  File "E:\automateDashboard\proj1\venv\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://staged-tfs.lan/tfs/DefaultCollection/_apis/wit/workitems/$DEFECT?api-version=5.0
strahl commented 5 years ago

Hi @harsheel87, I stumbled upon the same issue. In my case I forgot the explicitly set the project id. And as get_workitem is more forgiving and runs without the project ID I did not notice this immediately. Here the "test" code that made me notice:

    client = TFSAPI(url, project = project, auth_type=HttpNegotiateAuth)    
    wi_fails = client.create_workitem('Bug', fields = fields)
    project_id = client.projects[0].id
    client_wtf = TFSAPI(url, project = f"{project}/{project_id}", auth_type=HttpNegotiateAuth)    
    wi_ok = client_wtf.create_workitem('Bug', fields = fields)
allburov commented 5 years ago

I have no installed Azure DevOps Server and don't can test this. @harsheel87 Did the above advice about project_id help you?

harsheel87 commented 5 years ago

Thanks @strahl for the inputs. @allburov , sorry for the late reply as I had to leave on family medical leave but the project was shelved before we could try the suggestion.