We need to upload a document to a SharePoint Online list and then add some searchable attributes to the document. We are uploading the document using Microsoft Graph.
Since we need to be able to search for the document against different criteria, we are uploading the document to a List.
Here is a snapshot of the request:
string requestUrl = "https://graph.microsoft.com/v1.0/drives/" +
driveID +
"/items/root:/" +
fileName +
".docx:/content";
HttpClient client = new HttpClient();
HttpRequestMessage message =
new HttpRequestMessage(HttpMethod.Put, requestUrl);
message.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
message.Content = new StreamContent(requestContent);
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type",
"application/json; odata=verbose; charset=utf-8");
HttpResponseMessage response = await client.SendAsync(message);
When the document gets uploaded we get back the response that includes a GUID and the document name.
{
"createdDateTime": "2018-02-27T10:44:02Z",
"eTag": "\"{446F157D-ED2C-4C1B-BB3F-56897A6190DA},1\"",
"id": "01JSWLMSD5CVNHFLHNDNGLWP2WGNNGDEG2",
"lastModifiedDateTime": "2018-02-27T10:44:02Z",
"name": "2018-02-27 15.43.55.7268PM.docx"
}
The trick comes when we try to get a hold of that document to add populate the other columns in the List.
We can get the document by using the id
field of the document in the list but that id
is not returned as part of the response when we upload the document so cannot use that value for our request.
Our challenge is to get the ListItem
using the fields that we get back from the JSON response but so far every avenue we have tried has resulted in a failure.
We have tried using both id
and name
fields mentioned in the response above but are getting an HTTP 400
response. Below are the requests we have tried in multiple variations.
.../lists/My Library/items?expand=fields&filter=fields/name eq '2018-02-27 15.43.55.7268PM.docx'
and
...:/lists/My Library/items?filter=id eq '01JSWLMSD5CVXUILHDNGLWP2WGNNGDEG2'
Where are we losing it?