Microsoft Graph returns "Internal Server Error" on request? - microsoft-graph-api

I am trying to get my Microsoft Teams assignments through Microsoft Graph. I submit this GET request https://graph.microsoft.com/beta/education/me/classes/{id}/assignments as shown in the docs, with my authentication token as a header. However, below is the reply I get. I am doing this with python, however I have also tried from Graph Explorer which yields the same result.
{
"error": {
"code": "InternalServerError",
"message": "Object reference not set to an instance of an object.",
"innerError": {
"date": "2020-09-07T16:44:48",
"request-id": "011086a0-9240-4896-9363-d403a1a0fb05"
}
}
}
Does anybody have any insight? Is this a problem with Microsoft?

You need to remove the /me. The correct URI is https://graph.microsoft.com/beta/education/classes/{id}/assignments.
From the documentation
POST https://graph.microsoft.com/beta/education/classes/11019/assignments
Content-type: application/json
Content-length: 279
{
"dueDateTime": "2014-02-01T00:00:00Z",
"displayName": "Midterm 1",
"instructions": {
"contentType": "text",
"content": "Read chapters 1 through 3"
},
"grading": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentPointsGradeType",
"maxPoints": 100
},
"assignTo": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentClassRecipient"
},
"status":"draft",
"allowStudentsToAddResourcesToSubmission": true
}

Related

Microsoft Graph API - Using postman to update the created task in microsoft planner

I am trying to update the task in Microsoft planner using Graph API in postman. I have already created a blank task and I am updating the created task using PATCH function to attach a file.
PATCH Request:
PATCH https://graph.microsoft.com/v1.0/planner/tasks/{task-id}/details
Content-type: application/json
Prefer: return=representation
If-Match: W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAVCc=\"
{
"#odata.etag": "W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBAVCc=\"",
"previewType": "noPreview",
"references": {
"https%3A//my%2Esharepoint%2Ecom/sites/Test12/Shared Documents/Sample%2Edocx":
{
"#odata.type": "microsoft.graph.plannerExternalReference",
"alias": "Sample.docx",
"lastModifiedBy": {
"user": {
"id": "5442777a-0440-4a2f-9269-21824464e3a1"
}
},
"lastModifiedDateTime": "2022-09-05T11:06:47.6011074Z",
"previewPriority": "0009005756397228702",
"type": "word"
}
}
}
When i sent it it showed 400 Bad Request.
Response Error Message -
{
"error": {
"code": "",
"message": "The request is invalid:\r\nAn unexpected 'StartObject' node was found for property named 'lastModifiedBy' when reading from the JSON reader. A 'PrimitiveValue' node was expected.",
"innerError": {
"date": "2022-09-06T04:49:34",
"request-id": "37001992-fafb-461e-a4f0-9f1dafa34b21",
"client-request-id": "37001992-fafb-461e-a4f0-9f1dafa34b21"
}
}
}
Is there any issue with the body content?

Microsoft ToDo Graph API is sending broken JSON

I'm getting the response with invalid JSON (brackets aren't closed) when trying to get the MS ToDo task for the user. Also, API sends HTTP status 200 with that response.
Request/response examples:
https://graph.microsoft.com/v1.0/me/todo/lists/:listID/tasks/:taskID
{
"title": "DELETED",
"createdDateTime": "2020-06-17T18:33:44.3228459Z",
"lastModifiedDateTime": "2020-11-27T11:36:55.8037415Z",
"id": "DELETED",
"linkedResources": [
{
"error": {
"code": "InternalServerError",
"message": "Invalid object within the collection response from workload for navigation property linkedResources with declaring type microsoft.graph.todoTask. Expected a JObject, but got Jtoken type - Null",
"innerError": {
"date": "2021-05-14T03:13:36",
"request-id": "5b9445b0-7405-436a-8179-cac92a8af087",
"client-request-id": "5b9445b0-7405-436a-8179-cac92a8af087"
}
}
}
How can I resolve this issue?

microsoft graph api assign license giving error

I am trying to assign license to a user with Office 365 business premium skuid but getting following error.
Request body:
{
"addLicenses": [
{
"skuId": "skuid"
}
],
"removeLicenses": []
}
Response
{
"error": {
"code": "Request_BadRequest",
"message": "Another object with the same value for property proxyAddresses already exists.",
"innerError": {
"request-id": "b94663b1-f58f-4e30-a457-3db66a0f0b51",
"date": "2020-03-13T11:22:35"
},
"details": [
{
"target": "proxyAddresses",
"code": "ObjectConflict"
}
]
}
}
But the user whom I am assigning license is unique.
Any help is much appreciated.
I can reproduce your issue via the following steps:
I already have a user account: allen3#tenant.onmicrosoft.com. It has an alias (proxyAddress): allenwu#tenant.onmicrosoft.com.
Now I create a new account through Microsoft Graph API with allenwu#tenant.onmicrosoft.com as the userPrincipalName.
POST https://graph.microsoft.com/v1.0/users
Content-type: application/json
{
"accountEnabled": true,
"displayName": "allent3",
"mailNickname": "allent3",
"userPrincipalName": "allenwu#tenant.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": false,
"password": "password-value"
}
}
The magic happened: the account was created successfully!
But when I assign license to the account allenwu#tenant.onmicrosoft.com with Microsoft Graph API, it gives me the same error as yours.
So I think this error prompt is reasonable. (Although it is unreasonable for the account to be created successfully.)
Please check if your tenant has the same problem as me. Hope it's helpful.

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.
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"
}
}
}

branding settings error youtube api

I have to update the featured video of my channel using youtube api.
When I sent PUT request using api explorer of the form
PUT https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&key={YOUR_API_KEY}
{
"brandingSettings": {
"channel": {
"featuredChannelsTitle": "featured channel",
"featuredChannelsUrls": [
"http://www.youtube.com/user/channelname"
]
}
},
"id": "channelId"
}
I am getting response as follows
404 Not Found
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.channel",
"reason": "channelNotFound",
"message": "Channel branding options not found.",
"locationType": "parameter",
"location": "id"
}
],
"code": 404,
"message": "Channel branding options not found."
}
}
Please let me know where I am going wrong.
I was giving the wrong channel ID. But now I am trying with the correct Channel Id, and I am getting yet another error message.
Content-Type: application/json
Authorization: Bearer ya29.1.AADtN_X2UP_3BfFvUwAkvLp0d0mk1U-itJNVtWMPEJQU8G7INQ5q-UpI1yNMYniiLQ
X-JavaScript-User-Agent: Google APIs Explorer
{
"id": channelId,
"brandingSettings": {
"channel": {
"featuredChannelsUrls": [
" http://www.youtube.com/user/USERNAME"
],
"featuredChannelsTitle": "Featured Channels"
}
}
}
Response is 400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.channel",
"reason": "brandingValidationError",
"message": "Channel branding validation failed.",
"locationType": "parameter",
"location": "brandingSettings"
}
],
"code": 400,
"message": "Channel branding validation failed."
}
}
If you can provide me a sample request it would be really helpful
As it says in the error message, it couldn't find the channel, make sure you are giving the right channel id.
The way to do it in API, do a channels->list request and use that response object, modify it and put it back. (Most important make sure the id is there and set.)

Resources