Cannot access SharedWithMe Folders via microsoft graph api - onedrive

I am trying to download the items of a shared folder following the v1.0 reference guide. I am able to retrieve the basic details by using the /v1.0/me/drive/sharedWithMe request.
sharedWithMe Response
However when I try and request the contents of the folder using the '/drives/remoteItem.driveId/items/id' request I get a 'itemNotFound' error code.
/drives/b!SuVijei8UUiLXWR4XeJPFe-SS3gbCDVJuXZLcatX7Ikm3BPqZMVJTLOW4rsDD7B2/items/01GB75254SYRXS4C7C25HLIWFMXFY7HWB3
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"request-id": "2a0591bd-6fdf-4bf8-a5f3-baca24fd1930",
"date": "2016-08-29T14:03:25"
}
Any ideas what is going on?
Thanks!
EDIT:
I was able to retrieve SharedWithMe folders data by using the '/drives/remoteitem.parentReference.driveId/items/remoteItem.id/children'
It seems also very important to use a scope of Files.Read.All (which seems to be currently undocumented)

It looks like you are almost there. All you need is the /content segment.
Expected: /drives/remoteItem.parentReference.driveId/items/id/content
Your actual: /drives/remoteItem.parentReference.driveId/items/id
You'll get redirected to the resource for download. I think the documentation should be updated
And just to make sure, the base url is a bit different:
To get the shared item content: /v1.0/drives/drive-id/items/item-id/content
To get the list of shared items: /v1.0/me/drive/sharedWithMe

Related

PUT request to google cloud storage signed URL generated by Shopify throws error MalformedSecurityHeader

I'm trying to upload a .glb file to a product in a Shopify store through Shopify GraphQL Admin API. For that, it first returns a google cloud storage signed URL, to where I should upload my file through an HTTP PUT request. After uploading, I should attach the same URL to the product with another API call.
This question is about that file uploading to the cloud storage signed URL. I include all these details to make this question easy to be getting answered. So, please read till the end.
What data Shopify provides me with is mentioned below.
{
"data": {
"stagedUploadsCreate": {
"stagedTargets": [
{
"parameters": [
{
"name": "GoogleAccessId",
"value": "threed-model-service--6bgx7cbe#shopify-applications.iam.gserviceaccount.com"
},
{
"name": "key",
"value": "models/a6436c066064bac3/windmill.glb"
},
{
"name": "policy",
"value": "eyJleHBpcmF0aW9uIjoiMjAyMC0wNy0yMVQwOToxNjoxMFoiLCJjb25kaXRpb25zIjpbWyJlcSIsIiRidWNrZXQiLCJ0aHJlZWQtbW9kZWxzLXByb2R1Y3Rpb24iXSxbImVxIiwiJGtleSIsIm1vZGVscy9hNjQzNmMwNjYwNjRiYWMzL3dpbmRtaWxsLmdsYiJdLFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDE5NzE3MiwxOTcxNzJdXX0="
},
{
"name": "signature",
"value": "vz+OdcEmD9Kbv2FbXdxWNUk59XO2GmXzhvtDswXbDQNcyZpUufI85z5x2PFGv/XZ+tSBsl/S393pmy0Bu9xG7oVgOZcMIWEbOIm9kXgQunbjKQY3Ff3BBpMocB0xazzlYmckZozdJ8ZZkyox/c/gEe1QaxqW4+419iufuFHy4Bp3LL/aUr+ATNChwn9Dn8+XnHMOckZxDlbiggcF3dx+yBuTFia8FneaVSiU0M5DIWmHqHb2YDCV0KtEP6jfTj/PQVUjS8pn8EGhrRaMx7Q2A5G8Pycgc9H35hqJnnUKCTa3AYeyI45RbhddYnIWw9YrAADXuQYlVCo6LYBHjxsCWA=="
}
],
"resourceUrl": "https://storage.googleapis.com/threed-models-production/models/a6436c066064bac3/windmill.glb?external_model3d_id=bW9kZWwzZC00MDg5Ng==",
"url": "https://storage.googleapis.com/threed-models-production/models/a6436c066064bac3/windmill.glb?external_model3d_id=bW9kZWwzZC00MDg5Ng=="
}
],
"userErrors": []
}
}
}
Using these parameters, I construct a signed URL as follows.
resourceUrl+"&signature="+signature+"&key="+key+"&policy="+policy+"&GoogleAccessId="+GoogleAccessId
Eg:
https://storage.googleapis.com/threed-models-production/models/a6436c066064bac3/windmill.glb?external_model3d_id=bW9kZWwzZC00MDg5Ng==&signature=vz+OdcEmD9Kbv2FbXdxWNUk59XO2GmXzhvtDswXbDQNcyZpUufI85z5x2PFGv/XZ+tSBsl/S393pmy0Bu9xG7oVgOZcMIWEbOIm9kXgQunbjKQY3Ff3BBpMocB0xazzlYmckZozdJ8ZZkyox/c/gEe1QaxqW4+419iufuFHy4Bp3LL/aUr+ATNChwn9Dn8+XnHMOckZxDlbiggcF3dx+yBuTFia8FneaVSiU0M5DIWmHqHb2YDCV0KtEP6jfTj/PQVUjS8pn8EGhrRaMx7Q2A5G8Pycgc9H35hqJnnUKCTa3AYeyI45RbhddYnIWw9YrAADXuQYlVCo6LYBHjxsCWA==&key=models/a6436c066064bac3/windmill.glb&policy=eyJleHBpcmF0aW9uIjoiMjAyMC0wNy0yMVQwOToxNjoxMFoiLCJjb25kaXRpb25zIjpbWyJlcSIsIiRidWNrZXQiLCJ0aHJlZWQtbW9kZWxzLXByb2R1Y3Rpb24iXSxbImVxIiwiJGtleSIsIm1vZGVscy9hNjQzNmMwNjYwNjRiYWMzL3dpbmRtaWxsLmdsYiJdLFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDE5NzE3MiwxOTcxNzJdXX0=&GoogleAccessId=threed-model-service--6bgx7cbe#shopify-applications.iam.gserviceaccount.com
Then I try to make a PUT request to this URL with the .glb file in POSTman as shown in this image -->
with the following headers.
But I don't get a success response. In fact, I get a 400 error with the following message.
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>MalformedSecurityHeader</Code>
<Message>Your request has a malformed header.</Message>
<ParameterName>signature</ParameterName>
<Details>Signature was not base64 encoded</Details>
</Error>
Can someone point me out what I'm doing wrong here? I have been dealing with this error for days and read a lot of questions and articles, but couldn't get this to work. Therefore, any helpful suggestion is highly appreciated.
Few suggestions for you to try:
When generating the initial request (Shopify did this in this case), GCS usually includes HTTP headers of that request and includes them in the request signature and expects the upload request (the one you're trying to do) to match same HTTP header values.
This means you are advised to include only those headers Shopify specified in their request in your signed key upload request and nothing extra. So first try removing all HTTP headers that are not documented by Shopify (e.g. ones added by POSTMAN) and ensure all headers values follow Shopify docs (e.g. Content-Type should match)
You need to ensure signature parameters are in the expected names and formats:
signature value field is named: x-goog-signature and not signature (This is the likely reason for the error you're getting that GCS can't find the expected param)
you likely have to provide a signing algorithm key as well (x-goog-algorithm)
you might need other keys as well depending on other factors like authentication and so
I'd say these should be documented by Shopify SDK and/or examples
One suggestion to simplify/speed up things for you might be to use Google Cloud Utils (gsutil command line tool) to create a signed url request and then try to reproduce the same behaviour in your code
For more information see these links:
https://cloud.google.com/storage/docs/access-control/signed-urls
https://cloud.google.com/storage/docs/access-control/signing-urls-with-helpers#gsutil
Then after familiazing yourself with signed url format, you can check this for some sample code on how to do in your own code:
https://cloud.google.com/storage/docs/access-control/signing-urls-manually
For your reference when reading the docs, the type of Signed URL you're trying to create is non-resumable upload (which uses a single PUT request) rather than resumable (which uses an initial POST plus a series of PUTs)
Sorry I haven't worked with Shopify but the above is from my experience working with GCS signed urls

Microsoft Graph: Uploading files to shared library instead of user's library?

In the documentation about Upload, these request options are listed:
PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/root:/{parent-path}/{filename}:/content
PUT /me/drive/items/{parent-id}/children/{filename}/content
PUT /groups/<id>/drive/items/<parent-id>/children/<filename>/content
In the documentation about Resumable Uploads, Create an upload session show these options:
POST /me/drive/root:/{path-to-item}:/createUploadSession
POST /me/drive/items/{parent-item-id}:/{filename}:/createUploadSession
What if I have to upload to other (not 'me') drive? For example, the default shared library (https://mycompany.sharepoint.com/Shared%20Documents), which for any other porpoise besides uploading, the documentation says can be accessed like this:
/drives/{drive-id}/items/{item-id}
So, my question is: Is it possible to upload to "/Shared Documents"? If so, which is the right syntax for the PUT (small file) or POST (upload session)?
Perhaps something similar to this? (I just made this up, and it doesn't work)
PUT /drives/{drive-id}/items/{parent-id}/{filename}:/content
or (in case of an upload session):
POST /drives/{drive-id}/items/{parent-item-id}:/{filename}:/createUploadSession
For example, in the Graph Explorer, the response for something like this:
/v1.0/drives/THEDRIVEID/items/THEFOLDERID:/whatever.jpg:/createUploadSession
was:
{
"error": {
"code": "invalidRequest",
"message": "A valid path must be provided.",
"innerError": {
"request-id": "THERETURNEDID",
"date": "THERETURNEDDATE"
}
}
}
EDIT: Because the company's root can also be accessed as /drive/root/, I also tried (with no luck, in both 1.0 and beta):
/drive/root:/whatever.jpg:/createUploadSession
/drive/root/whatever.jpg:/createUploadSession
This is possible, but you need the right app permissions to be able to read/create files outside of the user's OneDrive. Instead of requesting Files.ReadWrite, you would need to request Sites.ReadWrite.All and then use /v1.0/drive/root:/file.bin:/createUploadSession.
You can also use the SharePoint Sites API in Microsoft Graph to access team site document libraries (other than the root site). However, this API is still in the beta version and should not be used in production apps.

Microsoft Graph API on OneDrive returning error on retrieving children

I have authenticated to OneDrive and am trying to query it using the Microsoft graph API. I tried the documented query:
https://graph.microsoft.com/v1.0/drive/root/children
However, this returns an HTTP 500 with a JSON body that includes:
...
"code": "InternalServerError",
"message": "Unsupported extension property type.",
...
Some other queries such as /drive/root and /drive/root:/Documents work fine, but I can't get children to list.
You need to use this url to make it work:
https://graph.microsoft.com/v1.0/me/drive/root/children
Thanks
We've identified an issue with such requests for personal Microsoft accounts (LiveId). It has been corrected and you should no longer see such failures.

Copy operation on new OneDrive API

I've been stumbling on this issue for a while. I'm trying to copy file which is located at OneDrive's folder into another folder within the same account. (i.e: from user's root folder to one of it's subfolder).
According to OneDrive Copy API, I need to call this REST API:
POST /drive/items/{item-id}/action.copy
where {item-id} is the file's id which I want to copy. For this request, I've using this content:
{
"parentReference": {
"id": [destination-folder-id]
}
}
This http call was work just fine. I've got the desired result which is:
HTTP/1.1 202 Accepted
Location: https://onedrive.com/monitor/[generated-alphanumeric-characters]
When I following the link at Location header, I got the async job status which is:
{
"operation": "ItemCopy",
"percentageComplete": 0,
"status": "notStarted",
"statusDescription": "Completed 0/0 files; 0/0 bytes"
}
The problem is, no matter how many times I wait and call this link, it gives the exact response, which it's status was notStarted. I also try to reproduce this using OneDrive's API Console and it shows exact behaviors. I don't have any problem when copying an empty folder. This problem only occurs on files. Does anyone know why? Is there anything I should do to start that async job?
It seems that no one knows about this problem. For now, I have to use the old OneDrive API (formerly SkyDrive API) only for this copy operation, like this example:
COPY https://apis.live.net/v5.0/file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!126
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
{
"destination": "folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!114"
}
The things after file. and folder. is user id followed by item id (file id for the item or folder id for destination). Note that this only works on file. We cannot copy folder. If success, it will return a status code of Created.
Oh, and ... In order to use this API, we need to have wl.skydrive_update in the scope when authenticating our app.
I won't mark this answer as accepted answer since this is only a workaround for this issue. It does not solve the real problem.
UPDATE per April 12:
Ok. According to this bug tracking, this API should working by now (the referenced comment are posted on April 10. So I'll mark this question as answered.

Error 400 Bad Request when querying for list of projects

I am trying to query the list of projects available to a user with the Asana API as shown in their documentation under the title "Show all projects in a workspace or organization", but I am encountering a 400 Error.
The error message details being returned are:
{
"errors": [
{
"message": "Missing required `team` field"
}
]
}
I am using the following endpoint except that I am using my actual workspace ID:
https://app.asana.com/api/1.0/workspaces/14916/projects
The documentation for this example does not mention a team field, and the only reference to the team field applies to create-only operations. Does anyone have an idea as to what my issue is?
Without having additional information, it sounds like the query might actually be using the wrong HTTP verb - maybe POST? - rather than a GET.
Can you show the exact request you make, how you make it? An example with curl is usually a good common denominator, but code would work as well.