Create a New Folder using Microsoft Graph API - microsoft-graph-api

I am trying to create a new folder under the root of my onedrive by making a call to the following end point :
Request:
POST graph.microsoft.com/v1.0/me/drive/items/rootId/children
Content-Type: application/json
{
"name": "New Folder",
"folder": { },
"#microsoft.graph.conflictBehavior": "rename"
}
Expected Response:
HTTP/1.1 201 Created
Content-Type: application/json
{
"createdBy": {
"user": {
...
Obtained Response:
200 OK
When I make a call to this endpoint using Postman, I get a list of children under the root folder and the folder is not created.
Is the any way to resolve this?
Is there anything that i am doing wrong?
Kindly let me know.

use HTTPS request for all Microsoft Graph APIs
POST https://graph.microsoft.com/v1.0/me/drive/items/<rootId>/children

Can you provide a link to the docs page with that endpoint?
You can try make request to drive/root/children
below is a c# code for that:
var folder = new DriveItem { Name = "New Folder", Folder = new Folder() };
await client.Drive.Root.Children.Request().AddAsync(folder);
I used it a bit differently for something else, but should work analogically for you.
As other workaround, you can try to get the id of your drive id and drive root item id and then try to use the the endpoint without "me/" and "drives/{driveId}/items/{rootItemId}" instead.
PS. Have you inspected your oneDrive to obesrve the results of your calls? What do they produce?

Related

How do I get the mimetype and file ID using the Microsoft Graph API for OneDrive?

We are integrating our product with MS OneDrive. Our users will connect their MS accounts and choose a folder that they want us to pull files from. Our system only supports certain file types so we have to get the mimetype information AND the file ID after making a request. But we can't find a request that brings back both pieces of information so we can determine if we should pull a file or not.
This is close, but it doesn't give us the mimetype information.
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_recent?view=odsp-graph-online
Anyone have any ideas?
The get method lets you retrieve all kinds of information about a file: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online
It returns a driveItem object, that has a file property. And that file property has a mimeType property. See here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online and here https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/file?view=odsp-graph-online.
Unfortunately that means, that you will need more than one request to get the information you want.
If filtering by filename suffix is good enough for you, you can query OneDrive like this:
POST /search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "filetype:docx OR filetype:doc"
}
}
]
}
Documentation: https://learn.microsoft.com/en-us/graph/search-concept-files#example-5-use-filters-in-search-queries

Microsoft Graph API Online Meeting Delete not working

I successfully created an online meeting with the following API.
POST https://graph.microsoft.com/beta/communications/onlineMeetings
Content-Type: application/json
{
"startDateTime":"2019-09-09T14:33:30.8546353-07:00",
"endDateTime":"2019-09-09T15:03:30.8566356-07:00",
"subject":"Application Token Meeting",
"participants": {
"organizer": {
"identity": {
"user": {
"id": "550fae72-d251-43ec-868c-373732c2704f"
}
}
}
}
}
But when I am trying to delete the meeting its not working. I tried with the following APIs:
DELETE https://graph.microsoft.com/beta/me/onlineMeetings/{meeting id}
and
DELETE https://graph.microsoft.com/beta/{user id}/onlineMeetings/{meeting id}
Please help.
The api documented here works for me, eg:
DELETE https://graph.microsoft.com/beta/me/onlineMeetings/550fae72-d251-43ec-868c-373732c2704f_19:meeting_M2IzYzczNTItYmY3OC00MDlmLWJjMzUtYmFiMjNlOTY4MGEz#thread.skype
I get an http 204 in response.
Note that even after deleting the meeting using the above api, I am still able to join the meeting from the teams client, this may be a different bug perhaps. However, trying to delete the same meeting id again gives a 404 not found, which is expected.

Anonymously uploading to a publicly shared folder on OneDrive

What is the REST API call to anonymously upload to a publicly shared folder on OneDrive?
I have tried sharing a folder both thru the OneDrive Web UI creating a link attributed with: "Anyone with this link can edit this item", and using the REST API:
POST https://graph.microsoft.com/v1.0/drives/{driveId}/items/{sharedFolderId}/createLink
Content-type: application/json
{
"type": "edit",
"scope": "anonymous"
}
In both cases, I can read from the shared folder without logging on by
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}
I can also read the permission itself using
GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/permissions
=>
{
"#odata.context":"https://api.onedrive.com/v1.0/$metadata#shares('{shareId}')/items('{sharedFolderId')/permissions",
"value":
[
{
"id":"{permissionId}",
"link":
{
"application":
{
"displayName":"{my own app}",
"id":"{short app id}"
},
"type":"edit",
"webUrl":"https://1drv.ms/u/{shareId}"
},
"roles":["write"],
"shareId":"{shareId}",
"expirationDateTime":"0001-01-01T00:00:00Z",
"hasPassword":false
}
]
}
However trying to upload a file or create a subfolder, i.e.
PUT https://api.onedrive.com/v1.0/shares/{shareId}/driveItem:/{filename}:/content
Content-type: text/plain
some text goes here
or
POST https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/children
Content-type: application/json
{
"name": "TestFolder",
"folder": { }
}
both fail as unauthorized calls - but isn't the whole point of an "edit" link with "anonymous" scope that "anyone with this link can edit this item"?
I have tried various combinations of https://graph.microsoft.com/v1.0 instead of https://api.onedrive.com/v1.0 and /drives/{driveId} instead of /shares/{shareId} as well as /shares/{shareToken}, where shareToken is the "u!"-encoding of the webUrl from the link in the permission.
So far without being able to figure out the right REST API call. I hope someone is able to help :-)
You can download my TestOneDrive Visual Studio test project to reproduce the issues. It also contains initialization code to create and share the folder.
Due to no guys from Product Group following this and no official docs announced this, so I suggest you to submit an feature request first on UserVocie or vote up an existing one close to your issue.

How to upload a large file to OneDrive using Microsoft Graph

I'm getting a 404 - File name not provided in url response when creating an upload session.
My request looks like (without any body):
POST /v1.0/drives/{drive-id}/items/{item-id}/createUploadSession
Authorization: bearer <token>
Content-Type: application/json
This problem is only with the consumer OneDrive, OneDrive for Business works fine.
It worked for me:-
POST - https://graph.microsoft.com/v1.0/me/drive/root:/filename.txt:/createUploadSession
In Headers:-
Content-Type : application/json
Authorization: Bearer EwCIA8l6BAAUO...9chh8cJaAg==
In Body:-
{
"item": {
"#odata.type": "microsoft.graph.driveItemUploadableProperties",
"#microsoft.graph.conflictBehavior": "rename",
"name": "filename.txt"
}
}
I could upload a file in a personal account using this URL for create the storage session:
https://graph.microsoft.com/v1.0/me/drive/items/{folderID}:/{fileID}:/createUploadSession
var config = {
method: 'post',
url: 'https://graph.microsoft.com/v1.0/me/drive/items/{folderID}:/{fileID}:/createUploadSession',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer
}
Response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"expirationDateTime": "2020-11-06T14:25:27.662Z",
"nextExpectedRanges": [
"0-"
],
"uploadUrl": {url}
}
Then:
To create the file you gonna need to send a PUT request for the
{uploadUrl} that you got in the response.
I've never run across your particular scenario but I suspect this is due to the folder that was shared with you via OneDrive for Business being part of the same tenant as your own OneDrive for Business. When you're accessing a shared folder from a consumer OneDrive however, you are effectively accessing a drive in a completely separate tenant.
Since using the root:/{path}:/ method I suggested works, it sounds like this scenario may cause some issues with the API determining the file's information from the {itemId}. I'm looking to confirm this so I can update the documentation going forward.

Creating Post with Dynamics CRM Web API

A Post entity (https://msdn.microsoft.com/en-us/library/mt607553.aspx) cannot be created using Dynamics CRM 2016 Online Web API.
This payload should create a post on POST /api/data/v8.1/posts
{
"text": "Test Single Post",
"source": 1,
"type": 7
}
(source 1 is an auto post, type 7 is a status post)
But it returns:
{
"error":
{
"code":"",
"message":"An unexpected error occurred.",
"innererror"
{
"message":"An unexpected error occurred..."
}
}
}
Submitting the same payload with only "text" fails too.
Notice that the Post entity does not have single-valued navigation properties (https://msdn.microsoft.com/en-us/library/mt607553.aspx#bkmk_SingleValuedNavigationProperties) that will allow me to set the related entity (contact, account, etc).
For example, Creating a Task entity (https://msdn.microsoft.com/en-us/library/mt607619.aspx) works fine on POST /api/data/v8.1/tasks
{
"subject": "Test Single Task",
"description": "Test One Description of Task",
"regardingobjectid_contact_task#odata.bind": "/contacts(<someguid>)",
"scheduledend": "2016-07-21T12:11:19.4875892Z"
}
It seems to me that Post should expose something like regardingobjectid_contact_post#odata.bind, but it does not.
For context, this is how to create a Post via the SOAP endpoint and the SDK:
var result = Client.getOrganizationService().Create(new Post
{
Text = post.text,
RegardingObjectId = new EntityReference(
entityName,
Guid.Parse(post.regarding_guid)
)
});
Does anyone have a working example of a Post created via the Web API? Is this an omission in the Dynamics CRM Web API?
It doesn't look like this is listed in the limitations: https://msdn.microsoft.com/en-us/library/mt628816.aspx
UPDATE
It appears that the postregarding entity is where the link should be created to contact/account. This can be demonstrated by querying:
/posts?$filter=postregardingid/regardingobjectid_contact/contactid eq <someguid>
However, a "deep insert" like so does not work:
{
"text":"sometext",
"postregardingid":
{
"regardingobjectid_contact#odata.bind":"/contacts(someguid)"
}
}
The response is
Cannot create child entities before parent entity.
Nowhere it's mentioned like Post (activity feed) cannot be created using webapi. In fact it's not listed as crm webapi limitation like you pointed out.
Also on comparison, _regardingobjectid_value lookup property of post is different from activitypointer. Single valued navigation property too.
Out of curiosity, My investigation moved towards the Partner - post_PostRegardings
Only thing making sense - postregarding is strictly internal use. This could be the reason for all such behavior. This is my theory per v8.2 today(Aug 12 2017)
Description: Represents which object an activity feed post is regarding. For internal use only.
Entity Set path:[organization URI]/api/data/v8.2/postregardings
Base Type: crmbaseentity EntityType
Display Name: Post Regarding
Primary Key: postregardingid
Ref: https://msdn.microsoft.com/en-us/library/mt608103.aspx
Update:
Looks like MS recommend the community to use Organization service to create a custom Post record. Web api is still broken. Read more
I was recently struggling with this issue with an Activity table made using powerapps. For those who are interested, here's my post request:
POST: https://<MY_DOMAIN>.crm.dynamics.com/api/data/v9.1/<TABLE_NAME>
{
"regardingobjectid_contact#odata.bind": "/contacts(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)",
"description": "data for this entity",
"subject": "more data"
}
I didn't do anything different from other peoples' answers. I'll give an update if this problem fails sporadically. But as it is right now, it looks like regardingobjectid may be working in version 9.1
using D365 Api v9.1
POST https://{domain}.crm4.dynamics.com/api/data/v9.1/posts
{
"regardingobjectid_contact#odata.bind":"/contacts(guid)",
"text": "This is a private message post",
"source": 1,
"type": 4
}
source :
Auto Post
Manual Post
ActionHub Post
type :
Check-in
Idea
News
Private Message
Question
Re-Post
Status

Resources