SharePoint REST API TimeCreated and TimeLastModified properties are different even if a file wasn't modified - onedrive

I uploaded a file to a user's OneDrive and than I used SharePoint REST API to fetch the file information. I used the following endpoint:
https://*-my.sharepoint.com/personal/*/_api/Web/GetFileByServerRelativePath(decodedurl='*file-path*')/
The response I got:
{
*
"TimeCreated": "2019-12-09T09:42:39Z",
"TimeLastModified": "2019-12-09T09:42:41Z",
*
}
As you can see the TimeCreated and TimeLastModified differ by 2 seconds, however, I didn't touch the file after it was uploaded. Can someone explain why do I see such a difference?

Related

Whatsapp Cloud API Update Profile Picture

I'm trying to upload an image as profile picture using WhatsApp Cloud API *.
After creating an application using WhatsApp Cloud API I'm not allowed to access neither using the regular application nor using Business Application. It says something like "try again in one hour". So I have to implement everything using the API.
After reading the docs and importing Postman Endpoints I found the one called Business Profiles > Update Business Profile
https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile
It has a field "profile_picture_url"and I have tried POSTing media https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/media and then with the given ID y used https://graph.facebook.com/{{Version}}/{{Media-ID}} to get the URL but it didn't work. The rest of the information is updated successfully
{
"messaging_product": "whatsapp",
"address": "",
"description": "Simple Bot",
"email": "...#gmail.com",
"websites": [
"https://..."
],
"profile_picture_url": "https://lookaside.fbsbx.com/..."
}
However if I try to send someone using the ID and the endpoint https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages it works fine.
And if I use Download Media Content with the URL in Postman it works fine too.
I don't know if I have misunderstood something or if it can't be done using the API.
It is mentioned in the Cloud API Documentation:
profile_picture_url (Optional): URL of the profile picture generated from a call to the Resumable Upload API.
But, i got it working using profile_picture_handle instead of profile_picture_url. So how do we get the profile_picture_handle?
Prerequisite:
Graph API token here. Or use your WhatsApp Cloud API token.
App ID, go Apps > Your App > Settings (sidebar menu) > Basic
Update Photo Profile:
Call POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
Save the session id you got, upload:XXXXXX?sig=XXXXXX.
Call POST https://graph.facebook.com/v14.0/{{sessionId}}, with the headers: Authorization=OAuth {{token}}, file_offset=0, Host=graph.facebook.com, Connection=close, Content-Type=multipart/form-data, and include your image file in the request body with type binary. If you using Postman, see image below (This is what I missed for hours).
Save the handle result you got, 4::XXX==:XXXXXX.
Finally, call POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile, with json request body: {"messaging_product": "whatsapp", "profile_picture_handle": "4::XXX==:XXXXXX"}
That's it, You can check the profile picture.
The last step you have to add your taken by selecting "Bearer" or else it will give you error. I had hard time on the last ones, do all the steps and then go to the following link and it should help.
https://web.postman.co/workspace/My-Workspace~a4ddb3b8-02a3-4132-8384-66e63e149b7b/request/22958165-506a0542-c845-41ac-b3fb-b8209fd6f53b

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.

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.

How do I delete file that I have uploaded on Cloudinary using Jquery?

Can someone advise me how to delete a file in Cloudinary using Jquery?
I can't find any sample snippets to get started.
There good documentation on deleting client side uploaded images.
There are a few caveats to note though:
This does not work with unsigned uploads.
You will have to set return_delete_token: 1 in the options during your file upload, then pass the returned image's delete_token to the cloudinary.delete_by_token(delete_token) method.
From the documentation, you can do this over REST like so: curl https://api.cloudinary.com/v1_1/demo/delete_by_token -X POST --data 'token=delete_token'
Deleting resources requires an authenticated API (including a signature). Since the signature is based on your account's api_secret which shouldn't be included in your client-side code, you'll need to generate the signature on the server-side.
Having said that, when uploading you can set the new return_delete_token to true to tell Cloudinary to return a deletion token as part of the upload response.
The token can be used to delete the uploaded image within 10 minutes using an unauthenticated API request.
This is done with the delete_by_token method. See the following for a reference:
https://github.com/cloudinary/cloudinary_js/blob/47cf97a07f063a32311ff7d7cd09dc5a5a919318/js/jquery.cloudinary.js#L598

Get OneDrive File ID

I've written a snapshot tool that upload my screenshots directly to microsoft onedrive (formerly skydrive) and puts the link into my clipboard.
The tool counts up the resource IDs in order to get the link.
Structure is like this
https://storage.live.com/items/<cid>!<file id>
I wanna know if there is any way via php requests or the onedrive api to get the fileid of the file i just uploaded
When you do a PUT to OneDrive in your snapshot tool there will be a JSON response. In that response will be id, file name and source URL.
You can use the LiveConnectClient.GetAsync (http://msdn.microsoft.com/en-us/library/hh694251.aspx) method to get the file ID.
Here's an example:
LiveConnectClient liveClient = new LiveConnectClient(this.session);
LiveOperationResult operationResult =
await liveClient.GetAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!129");
Replacing "file.8c8ce..." with the file's friendly name will work.