Terry Hagan
Terry Hagan

Reputation: 81

Planner - BadRequest when updating Task Details

When using the Graph API I can successfully create a task, I then wish to update the task details, specifically the description and to add some references.

I'm following the documentation here https://graph.microsoft.io/en-us/docs/api-reference/beta/api/taskdetails_update

I add the request headers, Authentication Bearer, If-Match using the eTag from when I created the task. The URL is:

https://graph.microsoft.com/beta/tasks/6oqAlz30WE66F915zUcSepYAM2ki/details

Http method used is PATCH Body is:

{
  "description": "My Task Title description",
  "references": {
    "https://tenant.sharepoint.com/teams/teamsite/_layouts/15/WopiFrame.aspx?sourcedoc={521F1D0F-397D-4163-BB16-7C9EF436650B}&file=Release Notes.one&action=view&DefaultItemOpen=1": {
      "alias": "OneNote",
      "type": "OneNote"
    }
  }
}

Http response is:

StatusCode: 400, ReasonPhrase: 'Bad Request'

Response Content is:

{
    "error": {
        "code": "",
        "message": "The request is invalid.",
        "innerError": {
            "request-id": "4e2eae7d-9587-4a69-8c9d-40c5d571190a",
            "date": "2016-06-24T10:57:33"
        }
    }
}

Any ideas as to what I may be doing wrong here?

Coding in C# .Net using HttpClient, HttpRequestMessage.

Upvotes: 3

Views: 1157

Answers (1)

Terry Hagan
Terry Hagan

Reputation: 81

The URL in the references object needs to be encoded, that's it. i.e.

{
  "description": "My Task Title description",
  "references": {
    "https%3A%2F%2Ftenant.sharepoint.com%2Fteams%2Fteamsite%2F_layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7B521F1D0F-397D-4163-BB16-7C9EF436650B%7D%26file%3DRelease+Notes.one%26action%3Dview%26DefaultItemOpen%3D1": {
      "alias": "OneNote",
      "type": "OneNote"
    }
  }
}

Upvotes: 3

Related Questions