Devang Sanghani
Devang Sanghani

Reputation: 780

Error in creation of work-item in Azure DevOps using Pytest/Python

I am trying to create a work-item using Python and requests library.

def test_create_work_item(work_items):
    payload = {
                'op': 'add',
                'path': '/fields/System.Title',
                'value': 'Sample bug'
            }
    pl = json.dumps(payload)
    work_item = work_items.create(body=pl, type='bug')
    assert work_item.status_code == 200

I am getting the below error for this :

{"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException,Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}

The same body works okay with Postman. So not sure what more is needed here to get it working.

Upvotes: 2

Views: 130

Answers (1)

Shamrai Aleksander
Shamrai Aleksander

Reputation: 16018

I`m not familiar with Python.... Check this example: Create work item

The API uses an array of new fields:

[   
    {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample task"
    } 
]

In your case, you use just one field in the request:

{
    'op': 'add',
    'path': '/fields/System.Title',
    'value': 'Sample bug'
}

Upvotes: 1

Related Questions