access reference attachment content using outlook REST API - outlook-restapi

I'm using outlook rest api to scan email and access all its attachments. For attachments which are copied this works ok. But if the attachment is uploaded to one drive and sent as link, then I did not find a way to access its content.
using the //attachments endpoint, I get the folloing data for this attachment:
{'#odata.id': "....",
'#odata.type': '#Microsoft.OutlookServices.ReferenceAttachment',
'ContentType': 'text/plain',
'Id': '....',
'IsInline': True,
'LastModifiedDateTime': '2017-12-14T13:07:47Z',
'Name': 'ccc.txt',
'Size': 418}
Is there anyway to access the attachment content in this case? Thanks.

The properties you need are only available on the /beta endpoint (I'm guessing you're using /v2.0?)
The SourceUrl property contains the URL to access the attachment.
GET /api/beta/me/messages/{message-id}/attachments
{
"Id": "AAMkADBlNmQ2MTFl...",
"LastModifiedDateTime": "2017-12-14T16:21:02Z",
"Name": "Document1.docx",
"ContentType": null,
"Size": 13955,
"IsInline": false,
"SourceUrl": "https://1drv.ms/w/s!AuZOv...",
"ProviderType": "OneDriveConsumer",
"ThumbnailUrl": "",
"PreviewUrl": "",
"Permission": "Other",
"IsFolder": false
}

Related

How to Update properties of a OneDrive item using REST API?

I am trying to update the properties of a OneDrive item using SharePoint REST API.
OneDrive item web URL:
https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt
Mainly looking to updating following fields: Author, Created_x0020_By, Editor, Modified_x0020_By, Modified, Created
I tried using Graph API:
Request:
Method: PATCH |
URL: https://graph.microsoft.com/v1.0/sites/vx13-my.sharepoint.com,eab581b1-a945-4d23-9c8e-ec67bb74a42d,32fa1468-54b6-40d6-abbd-f775c4c3932b/drives/b!sYG16kWpI02cjuxnu3SkLWgU-jK2VNZAq733dcTDkyvIAAMdpSy_Sryiw8ARQ8Gv/root:/SrcDir/File-To-Update.txt:/listItem/fields |
Header:
Content-Type: application/json |
Accept: application/json;odata=verbose |
Body:
{
"Created": "2019-02-01 10:25 AM",
"Modified": "2020-01-27 11:25 AM",
"Modified_x0020_By": "3",
"Created_x0020_By": "3",
"Author": "Alex Wilber",
"Editor": "Alex Wilber"
}
It is giving failure response as:
{"code": "accessDenied", "message": "Field 'Created' is read-only"}
Through CSOM API using ValidateUpdateListItem() its working & successfully updating the property fields of OneDrive items.
But is there any way to update property fields of OneDrive item through REST API?
By default, these properties are Readonly by and cannot be edited.
You need to set the ReadOnlyField to false to update these fields. I used to answer the same question here: https://learn.microsoft.com/en-us/answers/questions/221106/rest-api-to-create-item-with-custom-created-by-and.html
For Created By column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created By')
Body:
{
"__metadata": { "type": "SP.FieldUser"},
"ReadOnlyField": false
}
For Created column:
Url: /_api/web/lists/getbytitle('Mylist')/fields/getbytitle('Created')
Body:
{
"__metadata": { "type": "SP.FieldDateTime"},
"ReadOnlyField": false
}
Using SharePoint REST API,
a work around to update the Properties of OneDrive item using method ValidateUpdateListItem()
Get the list-item-id of the file
GET https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/GetFileByServerRelativePath(decodedurl='/personal/alexw_vx13_onmicrosoft_com/Documents/SrcDir/File-To-Update.txt')/listitemallfields/fieldvaluesastext?$select=Id
Update Author, Editor, Created & Modified fields of list item using ValidateUpdateListItem
POST https://vx13-my.sharepoint.com/personal/alexw_vx13_onmicrosoft_com/_api/web/Lists/GetByTitle('Documents')/items(<list-item-id>)/ValidateUpdateListItem()
Content-Type:application/json
Accept:application/json;odata=verbose
Body:
{
"formValues":
[
{
"FieldName": "Created",
"FieldValue": "2019/02/01 10:25 AM"
},
{
"FieldName": "Modified",
"FieldValue": "2020/01/27 11:25 AM"
},
{
"FieldName": "Author",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_AK#vx13.onmicrosoft.com'}]"
},
{
"FieldName": "Editor",
"FieldValue": "[{'Key':'i:0#.f|membership|test_user_JV#vx13.onmicrosoft.com'}]"
}
],
"bNewDocumentUpdate": true
}
If you refer to the documentation here under the Properties section, you will notice certain fields are read only and you wont be able to update them using Graph API.
For all other properties(e.g. name), follow this documentation to update.
Being said that, you can always request for a feature by filling a User Voice so that it goes into our backlog.

Graph API: Unable to programmatically upload OneDrive item with specific properties (failing for createdBy and lastModifiedDataTime)

I am uploading an item to OneDrive using Graph API. I am also setting the properties of the item after it has been uploaded successfully. I am able to set "lastModifiedDateTime" but am not able to set "createdBy" and "createdDateTime".
"createdBy" is always set to the Azure AD application I have created for OAuth and in OneDrive UI it always shows "modified By" "SharePoint App".
And the "createdDataTime" is always current time (time of upload). Is there any way I can set these properties correctly?
The json I am using to patch the item properties:
{"createdDateTime":"2020-12-28T12:25:39Z",
"lastModifiedDateTime":"2020-12-28T12:25:39Z",
"createdBy":
{
"user":{
"email":"AlexW#vx2.onmicrosoft.com"}
},
"lastModifiedBy":{
"user":{
"email":"AlexW#vx2.onmicrosoft.com"}
},
"fileSystemInfo":{
"lastModifiedDateTime":"2020-12-28T12:25:39Z",
"createdDateTime":"2020-12-28T12:25:39Z"},
"file":{"mimeType":"image/jpeg"}
}
Please find the properties (queries from graph explorer) after the upload and above patch request:
{
"createdDateTime": "2020-12-28T12:28:09Z",
"lastModifiedDateTime": "2020-12-28T12:25:39Z",
"createdBy":
{
"application": {
"displayName": "ConsoleApp"}
},
"fileSystemInfo": {
"createdDateTime": "2020-12-28T12:28:09Z",
"lastModifiedDateTime": "2020-12-28T12:25:39Z"
},
"file": {
"mimeType": "image/jpeg",
"hashes": {
"quickXorHash": "4EQEGnBnLd04VXEmYqGHHIeZ2po="
}
}
}
As you can see user name has been replaced by the Azure AD app name and created by time is the time the upload was done and not the time specified in the patch request.
Please let me know if anyone has any idea about this.
If you refer the below article : https://learn.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0 under the Properties section.
These are read-only fields meaning you will not be able to manually configure the values for the same.
WorkAround :
Having said that this cannot be achieved through Graph API however, you can make use of the Sharepoint API to update the same.
ValidateUpdateListItem()
For modifiying the created by , last modified by and last modified the sample body would be of below :
{ formValues": [
{
"FieldName": "Editor",
"FieldValue": "[{'Key':'i:0#.w|AlexW#vx2.onmicrosoft.com'}]"
},
{
"FieldName": "Author",
"FieldValue": "[{'Key':'i:0#.w|AlexW#vx2.onmicrosoft.com'}]"
},
{
"FieldName": "Created",
"FieldValue": "02/18/2020 11:25 PM"
}
],
"bNewDocumentUpdate": true
}
Request URL :
https://SPOURL/_api/web/Lists/GetbyTitle('Library Name')/items(1)/ValidateUpdateListItem"

What does it mean "Property has an invalid value"?

During the creation of a batch of users in Azure AD by using the Graph API version 1.0 I receive the followiing error message:
Property has an invalid value
As you can see, there is not property name in the message, so I can't understand the real problem. What I can say is that those users have no particular conditions among the all others successfully created.
Any ideas?
Update 1:
As people asked, below are the post data. Since there is sensitive data, I have to changed names and som other personal data:
POST https://graph.microsoft.com/v1.0/users
And the JSON payload:
{
"accountEnabled": false,
"country": "BR",
"displayName": "Jane Sagan",
"givenName": "Jane",
"mailNickname": "jane.sagan",
"otherMails": [
"jane.sagan.#gmail.com"
],
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "J#n3Sa8aN"
},
"surname": "Sagan",
"usageLocation": "BR",
"userPrincipalName": "jane.sagan#university.br",
"userType": "Member"
}
The property "otherMails" doesn't support the format "jane.sagan.#gmail.com".
Username cannot end with '.' in O365. You can have a try (create a user whose username ends with '.') in O365 portal to verify it.

How to use GetChanges API for File Folder changes in MS Sharepoint 2013?

I have added some folder and files to 'Shared Documents' and trying to read get changes response.
Please have a look at my /getchanges request and response below:
POST https://xxxx.sharepoint.com/_api/web/getchanges?$filter=(Time ge datetime'2018-04-03T09:24:17Z')
{"query":{"__metadata":{"type":"SP.ChangeQuery"},"Add":true,"Web":true,"Site":true,"Update": true, "DeleteObject":true, "File":true, "Folder":true, "ContentType":true}}
For the above request I am getting below response:
{
[
"odata.type": "SP.ChangeFile",
"odata.id": "https://xxxx.sharepoint.com/_api/SP.ChangeFile7f33e785-a5dc-424a-bc31-d953171db7b2",
"odata.editLink": "SP.ChangeFile7f33e785-a5dc-424a-bc31-d953171db7b2",
"ChangeToken": {
"StringValue": "1;2;155cd6ac-2fa5-4fc6-8297-10917724fcdf;636583446482830000;79145543"
},
"ChangeType": 1,
"SiteId": "f6aea202-e4c9-4a16-927d-a222975c592e",
"Time": "2018-04-03T09:30:48Z",
"UniqueId": "83746e80-56e7-4b76-9427-6920b0677447",
"WebId": "155cd6ac-2fa5-4fc6-8297-10917724fcdf"
},
{
"odata.type": "SP.ChangeFolder",
"odata.id": "https://xxxxxx.sharepoint.com/_api/SP.ChangeFolder202b82c0-4a3a-4b70-879a-8d41b63ced7f",
"odata.editLink": "SP.ChangeFolder202b82c0-4a3a-4b70-879a-8d41b63ced7f",
"ChangeToken": {
"StringValue": "1;2;155cd6ac-2fa5-4fc6-8297-10917724fcdf;636583446489070000;79145549"
},
"ChangeType": 2,
"SiteId": "f6aea202-e4c9-4a16-927d-a222975c592e",
"Time": "2018-04-03T09:30:49Z",
"UniqueId": "6847b1e9-169b-4d15-9c3c-0b3b1a9848a8",
"WebId": "155cd6ac-2fa5-4fc6-8297-10917724fcdf"
}
]
}
I am facing below issues for getchanges api:
getchanges API not returning changes in response in case of File and Folder. It is returning file and folders updated yesterday.
Same API worked perfectly fine with List, ListItem, etc.
For above response, how can I retrieve which folder or file was added/updated, as I am getting webid and siteid in response
Please suggest?

The property IsDefaultFolder is always false when retrieving taskfolder list with outlook rest api

We are using the outlook-rest api to retrieve a list of taskfolders
GET: https://outlook.office.com/api/v2.0/me/TaskFolders
I tried with a outlook.com and Office 365 account but the property IsDefaultFolder is always false for the default folder.
Can anyone reproduce ? Is this a bug ?
Thanks
See response below
{
"#odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/TaskFolders",
"value": [{
"#odata.id": "https://outlook.office.com/api/v2.0/Users('xxx')/TaskFolders('ccc')",
"Id": "iii",
"ChangeKey": "ccc",
"Name": "Taken",
"IsDefaultFolder": false,
"ParentGroupKey": "0006f0b7-0000-0000-c000-000000000046"
}],
"#odata.deltaLink": "https://outlook.office.com/api/v2.0/me/TaskFolders/?%24deltatoken=ddd"
}

Resources