pythonmicrosoft-graph-apimicrosoft-graph-plannertasks

Getting "attemted changes conflicted with already accepted changes" error in Microsoft Graph Planner API


As in title I'm getting "The attempted changes conflicted with already accepted changes. Read the latest state and resolve differences." error when i'm trying to make patch request to planner api. It works fine in Postman when i'm doing Get planner taks by id first and then Update plan task but when i'm trying to do it in python i'm getting error mentioned above.
Get task works fine because im getting 200 response

Get_task.py

import requests


access_token = 'access token'

url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'
headers = {
  'Authorization': access_token,
}
graph_result = requests.get(url=url, headers=headers)
print(graph_result.text)

Patch_task.py

import requests

plan_e_tag = 'planEtag'
access_token = 'acces token'
url = 'https://graph.microsoft.com/v1.0/planner/tasks/{task_id}'

headers = {
  'Authorization': access_token,
  'If-Match' : plan_e_tag
}
data = {
  "title": "test"
}

graph_result_patch = requests.patch(url=url, headers=headers, json=data)

print(graph_result_patch.text)

I'm trying to run get_task.py first to read the latest state but i'm still getting and error. Same happens when i'm making get request via postman and then running patch_task.py. I'm excpecting to change the name of the task.


Solution

  • The Etag of the task is returned in the GET operation. You need to pass that value to the If-Match header in the PATCH operation. Etag represents the version of the entity that the client knows about. If the version the client is editing has already been edited with conflicting changes by the same or other clients, then a conflict error is going to be returned. You can specify a "prefer" header with value "return=representation" to get the response of the patch, which will also include the latest etag of the entity.