Unsupported Media Type - 415 error in POST request in Graph Explorer - microsoft-graph-api

I am trying out Graph Explorer. I am able to get my profile from https://graph.microsoft.com/v1.0/me/.
But when I try to create a device using the Graph Explorer, it is returning Unsupported Media Type - 415 response.
My request and response are:
Request
POST https://graph.microsoft.com/v1.0/devices
Request headers
Content-type: application/json
Request body
{
"accountEnabled": false,
"alternativeSecurityIds": [
{
"type": 3,
"key": "base64Y3YxN2E1MWFlYw=="
}
],
"deviceId": "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
"displayName": "Test device",
"operatingSystem": "linux",
"operatingSystemVersion": "1"
}
I have given the consent for all permissions under Modify permissions section.
Response
Unsupported Media Type - 415 - 1168ms
{
"error": {
"code": "Request_BadRequest",
"message": "The specified content type 'application/json;odata=minimalmetadata, application/json' contains either no media type or more than one media type, which is not allowed. You must specify exactly one media type as the content type.",
"innerError": {
"request-id": "11235ffc-1fb3-4324-a832-2c92274e98bf",
"date": "2020-04-06T16:55:17"
}
}
}
Edit
value of deviceId in the request data

"DeviceId" AND "Key" that you are passing in Request body should be Unique identifier. Change you sample Device-Id & Key and try again. It worked for me. and you also increased the length of device id by appending 1 at end.
Documentation for accountEnabled here.

Related

I can't get this Google Sheets API Get request to work

I am trying to have a game to request data from the Google Sheets API, and I can't get the API Key to function properly. I can visit my API Link in the browser, and it tells me it is getting HTTP 400 (Bad Request) and Google additionally says it's a bad API Key, despite having JUST generated it. For reference my link looks like this: "https://sheets.googleapis.com/v4/spreadsheets/[SHEET_ID]?key=[API_KEY]/values", and the browser views this when using it:
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "sheets.googleapis.com"
}
}
]
}
}
I have absolutely no idea what is going wrong, I know the API key and Sheet ID are right (Directly copied each from their respective source).

Microsoft Graph-Delete planner task-Resource not found for the segment (ETag)?

I am trying to delete Planner task using Microsoft graph according to instruction on https://learn.microsoft.com/en-us/graph/api/plannertask-delete?view=graph-rest-1.0&tabs=http
GET works, DELETE does not.
Request should look like:
DELETE https://graph.microsoft.com/v1.0/planner/tasks/{id}
If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="
In my case, it is:
DELETE https://graph.microsoft.com/v1.0/planner/tasks/nWf2j63qnk69r69ZdK7135cAMVlSIf-Match:W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="
What am I doing wrong?
GET
https://graph.microsoft.com/v1.0/planner/tasks/nWf2j63qnk69r69ZdK7135cAMVlS
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks/$entity",
"#odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"",
...
"id": "nWf2j63qnk69r69ZdK7135cAMVlS",
...
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment '\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=\"'.",
"innerError": {
"request-id": "58d3c417-6474-422c-912d-e6fdaae856c3",
"date": "2019-09-06T23:47:35"
}
}
}
It appears you are trying to pass If-Match via request url:
DELETE https://graph.microsoft.com/v1.0/planner/tasks/nWf2j63qnk69r69ZdK7135cAMVlSIf-Match:W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
while it is expected to be provided via request headers, like this:
DELETE https://graph.microsoft.com/v1.0/planner/tasks/{id}
Headers:
If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="
Authorization: Bearer <access-token>
Graph Explorer example

pathIsTooLong is not returned from createUploadSession api

When we try to upload file to specified folder over maximum path length, the following error occurs from createUploadSession api.
{
"error": {
"code": "invalidRequest",
"message": "One of the provided arguments is not acceptable.",
"innerError": {
"request-id": "...",
"date": "..."
}
}
}
We expect to include "pathIsTooLong" code in error response body then.
https://developer.microsoft.com/en-us/graph/docs/concepts/errors#error-resource-type
Is this correct behavior?
About CreateUploadSession API
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession
According to your descriptions, you want to include "PathIsTooLong" in error response body.
We can post a suggestion here Url: https://todo.uservoice.com/.

400 when accessing shared file using graph api with shared url

I called the endpoint /shares/{shareId} using msgraph-sdk-php, but got response 400 as:
{
"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#shares/$entity",
"id":"s!here-is-the-share-id",
"name#odata.type":"#String",
"name":{
"error": {
"code": "BadRequest",
"message": "A primitive value was specified; however, a value of the non-primitive type '' was expected.",
"innerError": {
"request-id": "3ea56b1c-acd6-4fdf-a856-c46b35e01cb7",
"date": "2017-05-25T05:26:23"
}
}
}
(Yes, I even got 4 left brackets but only 3 right brackets.)
while I can get correct response via api.onedrive.com api with the same shareId.
I really can't find any tips from documentation.
Thanks for letting us know about this #SevenOutman! This was a configuration issue that has now been resolved.

What is the proper way to list all youtube broadcasts on behalf of the Content Owner (Youtube Partner) using Youtube API V3?

I tried this:
Went here - https://developers.google.com/youtube/v3/docs/search/list
Set the following parameters:
part - snippet
eventType - live (Also tried, completed)
forContentOwner - true
onBehalfOfContentOwner - 'Partner ID'
type - video
I have properly authenticated using the partners login credentials by switching on the OAuth at the top right of the form.
The documentation says, if 'eventType' is set, then the 'type' should be set to 'video' and if 'forContentOwner' is set then onBehlafOfContentOwner should be supplied and should be properly authenticated all of which I clearly did but I get the following error:
400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.search",
"reason": "invalidSearchFilter",
"message": "Invalid combination of search filters and/or restrictions.",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "Invalid combination of search filters and/or restrictions."
}
}
As it says in the debug info: video_filter is unsupported in combination with for_content_owner filter.
So you can not do it this way.

Resources