My goal is to create anything( Item, Folder, Files) in MS SharePoint using REST API. The issue is, I don´t have the influence to set up my access rights. It was set up by 3th party. They say, I have the full access to the subfolder. It goes something like this: https://xxxx.sharepoint.com/sites/xxxx/mysubfolder
Basically we were following the step by step here:
https://stuartmccoll.github.io/posts/2020-06-16-sharepoint-api-authentication-with-postman/
I use the Postman to test the process. The first step is getting the access token. It works fine and I get it.
When I try to test the get with
https://xxx.sharepoint.com/sites/xxxx/mysubfolder/_api/web/Lists/ using the token,
I get response back and with status 200 OK.
When I try to list e.g.
https://xxx.sharepoint.com/sites/xxxx/mysubfolder/_api/web/Lists/GetByTitle('Postman')/items
I get back:
{
"d": {
"results": []
}
}
empty? There are at least 2 items.
When I try to create a new list with post https://xxx.sharepoint.com/sites/xxxx/mysubfolder/_api/web/Lists
{
"__metadata": {
"type": "SP.List"
},
"AllowContentTypes": true,
"BaseTemplate": 100,
"ContentTypesEnabled": true,
"Description": "My list description",
"Title": "Test"
}
I recieve
{
"error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message": {
"lang": "de-DE",
"value": "Zugriff verweigert. Sie haben keine Berechtigung, diesen Vorgang auszuführen oder auf diese Ressource zuzugreifen."
}
}
}
with the status 403 Forbidden.
What am I missing / doing wrong?
Thanks.
I found the cause.
It was in the setup for "Grant permissions to a SharePoint Add-In"
It must be:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>
Then it works!
Related
I am trying to figure out how to obtain an "item-id" for a file in a sharepoint site for microsoft graph API.
Microsoft documentation: https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http
Here is what I tried for far:
Tried using https://developer.microsoft.com/en-us/graph/graph-explorer to guess the api link that will let me download the file I want.
I first tried to get the sharepointsite like so:
https://graph.microsoft.com/v1.0/sites/omidtechnfr.sharepoint.com:/sites/delploy
That worked:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
"createdDateTime": "2021-07-15T21:02:02.78Z",
"description": "delploy",
"id": "omidtechnfr.sharepoint.com,5e03397e-03b0-4d92-9658-f9163f0131b3,1d9f21da-4d74-45db-b5d4-e4a7f7f278a1",
"lastModifiedDateTime": "2021-07-17T02:16:39Z",
"name": "delploy",
"webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy",
"displayName": "delploy",
"root": {},
"siteCollection": {
"hostname": "omidtechnfr.sharepoint.com"
}
}
So then I tried using what I ASSUME is the item-id for the SharePoint site delploy to try and get more information out of the site so I can try to find the item-id for the file I want to download:
https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/
And I got back some result but it doesn't so the item-id for me to do anything with it:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
"createdDateTime": "2021-07-11T05:16:50Z",
"description": "",
"id": "b!fjkDXrADkk2WWPkWPwExs9ohnx10TdtFtdTkp_fyeKF_K1_Z49FFSbzXVFRA5GKa",
"lastModifiedDateTime": "2021-07-16T18:32:35Z",
"name": "Documents",
"webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy/Shared%20Documents",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "System Account"
}
}
At this point I started to get desperate and a little angry. So I tried to just download the file from sharepoint and assume that the characters at the end of the download link was the item-id but that didn't work either:
download link:
https://omidtechnfr.sharepoint.com/sites/delploy/_layouts/15/download.aspx?UniqueId=25e2fd4f%2Deb32%2D43ac%2D9141%2Dfa47a610a27c
Used https://www.urldecoder.org/ to decode what I am assuming is the item-id for the file I want to download
25e2fd4f-eb32-43ac-9141-fa47a610a27c
Then tried to desperately tack this on to the Microsoft graph api to see what happens:
https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/items/25e2fd4f-eb32-43ac-9141-fa47a610a27c
and it failed:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"date": "2021-07-17T14:13:51",
"request-id": "985e2893-5343-47ac-a93c-6629a00c4eb3",
"client-request-id": "73a3b6d0-f1ce-bb51-b126-43f0957d15e3"
}
}
}
You could get the file by the path: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/{item-path}
For example: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/test.docx
If the file is in a folder, it would be like this: https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/folder1/test.docx
I used the search site id endpoint GET /sites/{site-id}/drive/root/search(q='{search-text}')
Documentation here.
I am using Azure AD B2C to create users.
After a user is created I would like to add them to a Group
Using Postman I have made the following request (with access token in the header). Note: I have managed to successfully create a group using the Api.
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members/$ref?api-version=1.6
With Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
Which is what the documentation specifies. No matter the body that is sent I get the following error
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "The request URI is not valid. Since the segment 'members' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."
},
"requestId": "48cf65f3-20ba-411e-8121-f7ea54252f3a",
"date": "2019-05-27T06:09:25"
}
}
I tried removing the /$ref
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members?api-version=1.6
Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
as well as
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/users/{user-objectId}"
}
Now the error that gets returned now is:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "Unsupported resource type 'DirectoryObject' for operation 'Create'."
},
"requestId": "2c36cc6d-383c-44f8-8609-2ac3e3efc862",
"date": "2019-05-27T06:15:26"
}
}
The documentation that I have been using https://learn.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=javascript
You are using graph.windows.net endpoint, so you should refer to azure ad graph api.
POST https://graph.windows.net/myorganization/groups/b4bda672-1fba-4711-8fb1-5383c40b2c14/$links/members?api-version=1.6
{
"url": "https://graph.windows.net/myorganization/directoryObjects/3eb6055a-baeb-44d4-a1ea-2fee86d8891b"
}
The document you referred to is microsoft graph api. The endpoint should be https://graph.microsoft.com.
You can use Microsoft Graph explorer to call these apis.
I'm trying to download a file from SharePoint online using Microsoft Graph API.
Graph API is not allowing me to use /Content.
This is the endpoint I'm using:
https://graph.microsoft.com/v1.0/sites/<host.sharepoint.com>/lists/<ListID>/items/<ItemID>
This is what get (Values Removed):
{
"#odata.context","#odata.etag","createdDateTime","eTag","id","lastModifiedDateTime","webUrl","createdBy"{"user": {"email","id","displayName"}}, "lastModifiedBy": {"user": {"email","id","displayName"}},
"parentReference": {"id"},
"contentType": {"id"},
"fields#odata.context",
"fields": {"#odata.etag","FileLeafRef","id","ContentType","Created", "AuthorLookupId","Modified","EditorLookupId","_CheckinComment", "LinkFilenameNoMenu","LinkFilename","DocIcon","FileSizeDisplay", "ItemChildCount","FolderChildCount","_ComplianceFlags","_ComplianceTag", "_ComplianceTagWrittenTime","_ComplianceTagUserId","_CommentCount", "_LikeCount","Edit","_UIVersionString","ParentVersionStringLookupId", "ParentLeafNameLookupId"
}
}
When i try to add /content i get:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'content'.",
"innerError": {
"request-id": "<ReqID>",
"date": "<date>"
}
}
}
How do i download this file using the API?
The endpoint https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id} returns ListItem resource but Content is a property of DriveItem resource which
Represents an item within a drive, like a document, photo, video, or
folder resource
that's the reason this error occurs.
Given the provided endpoint it could be modified to
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem/content
to download a content
My team and I have been crawling both the net and Facebook Docs for answers, but for some reason there are no valid answers to our question.
So we desperately hope for help from someone here
We are trying to create a video AD on facebook. Upload is done and we are at the step where we need to create the creative through /adcreatives endpoint.
Below is the body of the POST :
https://graph.facebook.com/v2.8/act_[account_id]/adcreatives
{
"access_token": "token_that_is_valid",
"object_story_spec": {
"page_id": "valid_numeric_page_id",
"video_data":{
"image_url": "link_to_img",
"video_id": "valid_numeric_video_id",
"call_to_action" :{
"type": "LEARN_MORE",
"value":{
"link": "my_link",
"link_caption":"my_link_caption",
"link_description": "description"
}
}
}
},
"name":"jjkkllkjljl"
}
The response from facebook is rather worrying :
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_subcode": 1487390,
"is_transient": false,
"error_user_title": "Adcreative Create Failed",
"error_user_msg": "The Adcreative Create Failed for the following reason: Oops, something went wrong. Please try again later",
"fbtrace_id": "EVL6GYOOtYi"
}
}
Also as an extra info, creating both non-video / image creatives and herafter ads is not an issue. Posting pre uploaded videos to a page is NOT an issue. All access rights has been given to the Facebook APP.
Thank you for taking the time to look at this.
I've the same problem with Python.
To fix it you shouldn't use video_id from admin panel.screenshot from admin panel
You should upload video and get video_id from API.
Example Python code:
video = AdVideo(parent_id=ad_account_id)
video[AdVideo.Field.filepath] = 'test.mp4'
video.remote_create()
video_id_for_creative=video.get_id()
link description is not a valid parameter in the call_to_action value: https://developers.facebook.com/docs/marketing-api/reference/ad-creative-link-data-call-to-action-value/
I'm following documentation from here https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/sharepoint
I want to enumerate lists from default site.
get siteId using /sharePoint/site end point(works fine)
Request lists using sharePoint/sites/{{siteId}}/lists doesn't work returns 404 with following message
{
"error": {
"code": "itemNotFound",
"message": "Requested site could not be found",
"innerError": {
"request-id": "34b1b51a-59ba-4c56-991a-319ffbe33005",
"date": "2017-04-07T10:46:40"
}
}
}
any pointers
in sharePoint/sites/{{siteId}}/lists the part of {siteId} is actually 3 part, the domain, root site id, subsite id, for for example if i have a domain contoso.sharepoint.com, with a site named root site with id 123 (it should be a guid) and another subsite under that named Klingon Site with id of 145 so my final {siteId} is contoso.sharepoint.com,123,145
should be like contoso.sharepoint.com,fffdf23f-1234-1234-a744-17e2e196e777,1481eca1-4567-4567-8dbc-60c666ab3b8c
I'm assuming you have confirmed there is a list within this site. You'll get a 404 if you attempt to fetch a list collection from a site without one.
More likely is you're using the wrong ID. The documentation is a bit ambiguous about which property it means by {site-id}.
When you fetch your site, there will be both a siteId and an id property. You want the id property. Using siteId will result in a 404.
{
"createdDateTime": "",
"description": "",
"id": "**** Use this one ****",
"lastModifiedDateTime": "",
"name": "",
"webUrl": "",
"root": {},
"siteCollection": {
"hostname": ""
},
"siteCollectionId": "",
"siteId": "**** Not this one ****"
}