I am trying to create list items with Microsoft Graph API to a SharePoint endpoint. My URL is as follows:
https://graph.microsoft.com/v1.0/sites/{id}.sharepoint.com:/sites/{name of the site}:/lists/{list_id}/items
Calling this URL with POST, and a body like this:
{
"fields": {
"FileLeafRef": "757391.pdf",
"ContentType": "Document",
"Application_x0020_Name": "ABC",
}
}
It is giving error as
"message": "Files and folders should only be added to a
DocumentLibrary via the OneDrive API"
Can some one help on this, how to fix this issue?
Here I am trying to create metadata for document, with in a list.
You cannot upload a file (i.e. create a new ListItem in a Document Library) like that. You will need to first upload the file using the OneDrive endpoints:
PUT /v1.0/sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
POST /v1.0/sites/{siteId}/drive/items/{driveItem-id}/createUploadSession
Once you have the file in the document library, you can then update the metadata on the existing file using the SharePoint endpoints:
PATCH h/v1.0/sites/{site-id}/lists/{list-id}/items/{listItem-id}/fields
{
"FileLeafRef": "757391.pdf",
"ContentType": "Document",
"Application_x0020_Name": "ABC"
}
Related
So, I have a Power Automate Flow, which creates a Sharepoint Site using the Sharepoint REST API via "Send HTTP Request to Sharepoint" connector. I`ve following body:
{
"request": {
"Title": "#{variables('strSPName')}",
"Url":"#{variables('strSPAddress')}",
"Lcid": 1031,
"ShareByEmailEnabled":true,
"Description":"-",
"WebTemplate":"SITEPAGEPUBLISHING#0",
"SiteDesignId":"-",
"Owner": "#{outputs('Get_my_profile_(V2)')?['body/mail']}"
}
}
So right now I have only me as owner, but I need an additional owner.
I`ve tried to set two owners in an array like this:
"Owner": ["#{outputs('Get_my_profile_(V2)')?['body/mail']}", "email#test.com"]
Unfortunately, I`m getting the following error:
An unexpected 'StartArray' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected.
Any suggestions?
Thanks in advance.
As far as I am aware you can only set one owner when creating a site via the SPSiteManager endpoint. However, a workaround could be to add the second user to the Owners group directly after creation with a second POST request.
Below is an example
The principal id of the sitegroup should be 3.
Uri
_api/web/SiteGroups(3)/users
Body
{
"__metadata": { "type": "SP.User" },
"LoginName":"i:0#.f|membership|jane#contoso.onmicrosoft.com"
}
I am trying to upload a simple text document to a sharepoint shared document folder. My account do have write access within this folder.
To acheive that, I'm using the Microsoft Graph API v1.0.
According to the doc, I'm making the following request: PUT https://graph.microsoft.com/v1.0/sites/{site_id}/drive/items/Shared%20Documents/{name_of_folder}:/text.txt:/content
I've set Content-Type to be text/plain and my body is just 'text'.
The Microsoft Graph API send me the following error:
{
"error": {
"code": "BadRequest",
"message": "Entity only allows writes with a JSON Content-Type header.",
"innerError": {
"date": "2021-08-23T08:10:44",
"request-id": "51fcdf1f-d7d0-4585-b712-ddd0197e046e",
...
}
}
}
I've managed to upload a document using PUT /me/drive/items/{parent-id}:/{filename}:/content
Is there something wrong?
I am currently working with the SharePoint Graph API (beta) through Postman.
I have it all working and my Azure Active Directory application has the correct scopes for SharePoint.
What I am wondering is this:
I have this site (subsite, sorry my SharePoint terminology might not be the best):
https://graph.microsoft.com/{{api-version}}/sites/COMPANY_NAME.sharepoint.com,070d3261-xxxx-4c69-b186-a83e7ee0b6bb,09bc2cd0-aada-45fb-xxxx-bcdce9d5711e:/kb:/
which returns the site I am looking for (Note: I truncated the json):
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#sites/$entity",
"createdDateTime": "2020-05-18T06:02:28Z",
"description": "",
"id": "COMPANY_NAME.sharepoint.com,070d3261-xxxx-4c69-b186-a83e7ee0b6bb,e7808145-aab1-xxxx-bccc-df798f6a36eb",
"lastModifiedDateTime": "2020-09-23T21:37:37Z",
"name": "kb",
"displayName": "Knowledge Base - I removed the rest of the json"
}
But when I add /pages to the end:
https://graph.microsoft.com/{{api-version}}/sites/COMPANY_NAME.sharepoint.com,070d3261-xxxx-4c69-b186-a83e7ee0b6bb,09bc2cd0-aada-45fb-xxxx-bcdce9d5711e:/kb:/pages/
I get this:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.sitePage)",
"value": []
}
Now, I just went and created a new page in that site, even though there were already pages there, so I know they exist.
Another thing to note is that when I try to create a new page via the API:
POST https://graph.microsoft.com/{{api-version}}/sites/{{site-id}}/pages
I get this:
{
"error": {
"code": "accessDenied",
"message": "Access denied",
"innerError": {
"date": "2020-09-27T22:56:06",
"request-id": "1306506d-caea-4748-99a9-7eee20bb6404",
"client-request-id": "1306506d-caea-4748-99a9-7eee20bb6404"
}
}
}
Can anyone help me understand why the collection / array in my response does not contain any pages and also, why I cannot create a new page when my AAD App have the required scopes and these scopes have my admins' consent
cheers
Update. Adding some screen shots:
As you said you are using a daemon Application you need to specify right permissions here.
The screen shot shows that you are actually adding it for Sharepoint App permissions, please add the Sites.ReadWrite.All for the Microsoft Graph Permissions. As you can see above the green pointer there are 3 permissions(Directory.Read.All, User.Read.All and User.Read), add "Sites.ReadWrite.All" there to get the site pages and also it helps you in creating the pages.
I am using the REST API of Azure Data Catalog to register new assets. My users need to be able to add/change tags and description. However, when I register new assets over REST API, add tag buttons and description text field disappear.
I suspect I need to pass a parameter in the json to make the fields editable. In the official documentation I couldn't find anything related.
I have all of the admin rights in all of my users, so I don't think it is an access rights issue.
How can I make the assets editable?
The solution is explained here. By default, the assets that are created by REST API are only editable by their owners. In order to change that behaviour, the following json object should be added to the payload:
{
"roles": [
{
"role": "Contributor",
"members": [
{
"objectId": "00000000-0000-0000-0000-000000000201"
}
]
}
],
//properties start here
//"properties": {
//...
// }
}
if it is still unclear, please check the following sample code.
I am trying to integrated with Microsoft Sharepoint files for which i am started working with Microsoft Graph API.
https://graph.microsoft.com/v1.0/sites/XXXXdev.sharepoint.com:/sites/test
It gives me the site id and when i am trying to search for a file with the site id i am getting error
I am able to get the Site ID but unable to search for a file when i am trying with given API.
GET /sites/{site-id}/drive/root/search(q='{search-text}')
GET /sites/87fe5e97-7r8f-400f-90a7-ed9306f8uyu7/drive/root/search(q='change')
Response: 400
{
"error": {
"code": "BadRequest",
"message": "Url specified is invalid.",
"innerError": {
"request-id": "3e63ef7a-ca00-4464-9cfb-1bbfe48d7fee",
"date": "2019-08-13T10:57:59"
}
}
}
The site id return using "https://graph.microsoft.com/v1.0/sites/XXXXdev.sharepoint.com:/sites/test" like this:
xxx.sharepoint.com,7e659ba9-9691-4653-a556-f8a535a6917f,caadc04a-fd57-43e7-9c4b-9cce08050f6b
And search for a file with the site id API as below.
https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com,7e659ba9-9691-4653-a556-f8a535a6917f,caadc04a-fd57-43e7-9c4b-9cce08050f6b/drive/root/search(q='change')
I suggest you use Graph Explorer to test the Graph API.
As a workaround, we can use SharePoint Search REST API to achieve it.
https://tenant.sharepoint.com/_api/search/query?querytext='change IsDocument:"True"'
SharePoint Search REST API overview