2

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.

1 Answer 1

1

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'
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I have been following the official documentation. The same payload works on Postman and not with Pytest is what has raised this question.
Got it. It needed the square brackets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.