13,721 questions
Error "Unexpected instance annotation name" while trying to update plannerExternalReference
Jocelino Mendes da Silva Júnior
0
Reputation points
Hi! I am trying to update the plannerExternalReferences of a set of planners that I have access to but I am struggling with this error when I call the requests.patch: "The request is invalid:\r\nAn unexpected instance annotation name xxxxxxx was found when reading from the JSON reader, In OData, Instance annotation name must start with @.","innerError".
Here is the function that I am using:
Thanks in advance for any help!
def update_planner_task_references_I(access_token, task_id, current_references, new_url, new_description, etag):
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"If-Match": etag
}
updated_references = {}
existing_ref_found = False
for ref_key, details in current_references.items():
cleaned_details = {
"@odata.type": details.get("@odata.type", "#microsoft.graph.plannerExternalReference"),
"alias": details.get("alias"),
"type": details.get("type", "Other"),
"@odata.id": details.get("url") if "url" in details else details.get("@odata.id")
}
updated_references[ref_key] = {k: v for k, v in cleaned_details.items() if v is not None}
if details.get("url") == new_url or details.get("@odata.id") == new_url:
existing_ref_found = True
print(f"Anexo existente com URL {new_url} (chave: {ref_key}) será atualizado com a nova descrição.")
updated_references[ref_key]["alias"] = new_description
updated_references[ref_key]["type"] = "Other"
if not existing_ref_found:
new_ref_key = str(uuid.uuid4())
updated_references[new_ref_key] = {
"@odata.type": "#microsoft.graph.plannerExternalReference",
"@odata.id": new_url,
"alias": new_description,
"type": "Other"
}
print(f"Novo anexo com URL {new_url} (chave gerada: {new_ref_key}) será adicionado.")
payload = {
"references": updated_references
}
print(json.dumps(payload, indent=2))
graph_url = f"https://graph.microsoft.com/v1.0/planner/tasks/{task_id}/details"
print(f"\nUpdating task attachment. {task_id}...")
response = requests.patch(graph_url, headers=headers, data=json.dumps(payload))
response.raise_for_status()
print("Attachment updated successfully!")
return response.json()
Microsoft Security Microsoft Graph
Sign in to answer