How To Retrieve Custom Columns For DriveItems in MS Graph - sharepoint

I'm trying to use the Graph API to retrieve a hierarchy of files in a Sharepoint document library. Since document libraries are stored in "drives" (is it technically correct to call it OneDrive?), I'm using the /drives endpoint to fetch a list of files, like this:
https://graph.microsoft.com/beta/drives/{driveid}/root/children
I would like to get information from some of the custom columns that exist when viewing these items through Sharepoint. Using ?expand=fields doesn't work because fields only exists in listItem object of the /sites endpoint, not in the driveItem object of /drives endpoint. If I try obtaining the listItem from a single driveItem (traversing the Graph from OneDrive to Sharepoint), and then expanding the fields, like
https://graph.microsoft.com/beta/drives/{driveid}/items/{driveItemId}/listItem?expand=fields
this retrieves built-in columns (Author, DocIcon, and some others) but doesn't seem to retrieve the custom columns.
I've also tried getting the list of files from the /sites endpoint, and using ?expand=fields will get the custom columns, but it gets every file from every subfolder, rather than the current folder path. But I feel that deserves its own SO question.
Is it possible to retrieve custom column information from driveItems?

I spent a lot of time digging around with the different syntax possibilities and was finally able to get custom library properties using this query format. This is the only one that has produced my custom/user-defined fields for a document library.
https://graph.microsoft.com/v1.0/drives/insert_drive_id_here/root/children?expand=listItem
Shortened result:
{
"#odata.context": "...",
"value": [
{
"#microsoft.graph.downloadUrl": "...",
"listItem#odata.context": "...",
"listItem": {
"#odata.etag": "...",
"fields#odata.context": "...",
"fields": {
"#odata.etag": "...",
"Title": "...",
"Other_Custom_Property": "..."
}
}
}
]
}

I did some testing. What SHOULD work is:
https://graph.microsoft.com/beta/drives/{driveid}/root/children?$select=id,MyCustomColumnName
However, when I did that, it just returned that id field. In my opinion, that is a bug in the graph because this same type of query does work in the SharePoint REST api.
If this helps, you can accomplish this by using the SharePoint REST api. Your endpoint query would be something like:
https://{yoursite}.sharepoint.com/sites/{sitename}/_api/web/lists/(' {DocumentLibraryID}')/items?$select=id,MyCustomColumnName
There are other ways to do the same query.

Try the list endpoint then expand driveItem and fields. You now have both custom column fields and drive item fields.
/beta/sites/[site-id]/lists/[list-id]/items?expand=driveitem,fields&filter=(fields/customColumn eq 'someValue')

Related

using pdf files and their metadata for Azure cognitive search

I'm uploading hundreds of PDF files into blob storage to be used in Azure cognitive search.
I would like the user to be able to get the title and author of these PDF files on top of their search results.
I'm not sure how the metadata for these PDF files (e.g., 'author', 'date', 'title') can be added (e.g., as a json file) to the blob storage.
Any advice would be appreciated.
Thanks
I'm from the Microsoft for Founders Hub team. Azure blob storage has blob properties and metadata built into it! You can view and add metadata through various tools including the Azure Portal, CLI, PowerShell, or the REST API. To learn more, here's a great area to get started:
View Blob Properties and Meta Data using Azure Tools
Add Blob Metadata using Azure tools and code
If you would like the title, author and date to be returned in your search results, you can add them to the index. Thus, you can create fields called author, title and date in your index. Then, in the indexer, you can return the specific metadata for PDF's, as mentioned here, like this:
indexer= {
"name":...,
"dataSourceName":...,
"targetIndexName":...,
"skillsetName":...,
"fieldMappings": [
{
....
},
{
"sourceFieldName": "metadata_title",
"targetFieldName": "title"
},
{
"sourceFieldName": "metadata_creation_date",
"targetFieldName": "date"
},
{
"sourceFieldName": "metadata_author",
"targetFieldName": "author"
}
],
"outputFieldMappings": [
...
]
...
}
Where the "..." means that you add your own code.
Of course, the PDF's should have the metadata, otherwise it will return an empty value [].
You can then access the fields like you'd normally do for content for example.
NOTE: if you happen to put a null mappingFunction for the title, date and author, you might also get a []. If you don't use it, best remove it.

SharePoint Column Types

I'm requesting SharePoint Columns using MS Graph and need to understand the type of each column.
Unfortunately, not all column types are support in Microsoft Graph. For example, Hyperlink or Picture (Url) types are not available. There is doesn't seem to be a way to look at a field has an unsupported type.
Are there plans to map all the types?
I've tried bot v1.0 APIs and beta APIs as well.
Request example:
https://graph.microsoft.com/beta/groups/group-id/sites/root/columns
for, let's say, Text field I see field property:
"text": {
"allowMultipleLines": false,
"appendChangesToExistingText": false,
"linesForEditing": 0,
"maxLength": 255
}
But for Url, or Taxonomy, and some other types there is no indication at all.
In currently, the Graph API can provide the type property of the ColumnDefinition resource.
Check the official document here: ColumnDefinition resource.
As a workaround, we have to use SharePoint REST API to achieve it.
https://tenant.sharepoint.com/sites/lz/_api/web/Fields

Azure Search with documentDB does not find data

It's the first time that i'm using Azure Search. I follewed the example with the generated dataset. Now I want to implement Azure search on my database.
This is an example of an item of the collection I want to index.
{
"_id" : "Watch",
"name" : "Watch",
"cloudProvider" : "azure",
"channel" : "C6SELFQMD",
"services" : [
"azure-backup",
"azure-data-lake-analytics",
"backup",
"blobstorage",
"site-recovery",
"storage"
],
"__v" : 0
}
Azure search itself doesn't even detect the fields.
This are the steps i'm doing:
If I add the fields manually it returns useless data. Does somebody know why this is happening? I do only have 2 items in my collection at the moment but I don't think that this is the problem?
UPDATE:
So the problem is that I've an underscore before my id ("_id"). Now I'm trying to use fieldMappings to solve this issue. But the api's response is:
{
"error": {
"code": "",
"message": "Data source does not contain column '_id', which is required because it maps to the document key field 'id' in the index 'index'. Ensure that the '_id' column is present in the data source, or add a field mapping that maps one of the existing column names to 'id'."
}
}
Azure Search currently does not support Cosmos DB Table API accounts, as seems to be the case here.
If you want to see Table API supported by Azure Search, please vote for Azure Search should be able to index Cosmos DB Table API collections to help us prioritize that work.

How to build search with facetting over unknown/unspecified set of attributes/properties?

I'm working on a product search engine with a big set of undefined products which is constantly growing. Each product has different attributes and at this time they're saved in an array of string key-value pairs like this:
"attributes": [
{
"key": "Producttype",
"value": "Headphones - 3.5 mm plug"
},
{
"key": "Weight",
"value": "280 g"
},
{
"key": "Soundmode",
"value": "Stereo"
},
....
]
Each product has also a category. I'm using elasticsearch 2.4.x to persist data that i want to search on via spring-data-elasticsearch. It's possible to upgrade to the newest elasticsearch version if needed.
As you can see the attributes are really generic. It's also needed to use nested objects to be able to search on this attributes. I'm also thinking about preprocessing this attributes to a standardized format. For example the "Weight" key might be written in different forms like "Productweight" or "Weight of product". Because there are a lot of attributes and i wouldn't like to create a custom property/field for each one i thought about about mapping only the important ones (like weight) to a custom, own field and to map the other attributes like described above.
Now if someone searches for example "iphone" i would like to show some facettes on the left of the search result page. The facettes should differ if someone searches "Adidas shoes". Is this possible with the given format above using nested objects? Is it possible to build the facettes dynamically regarding to the resultset elasticsearch is returning? E.g. the most common properties which all result products contain should be used to create facettes. Or do i have to persist some predefined filters/facettes on each category? I think that would be too much work and also doesn't work on search results where products can have different categories. What's the best practice to build a search feature with facetting on entities with n different properties that can grow in future?

can array of links be fetched / resolved in an Entry request

I am requesting a specific Entry and one of the fields of that Entry is an array of links. Is there a way to get those links to be resolved and returned in the resulting JSON response?
I am trying this via curl
curl -v https://cdn.contentful.com/spaces/o2bhdl4js7ak/entries/<entryID>?access_token=<accessToken>&include=2
The "include=n" parameter does not work in this particular case. should it?
Here's a snippet with the field I expect to be resolved / expanded
"lessons": [
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "26hzvgmWtqOcKeoeMQOAoO"
}
}
],
Have another read of the Links page on Contentful Developer Documents.
Contentful Developer Documents - Links
to get a relationship link into the json you are requesting then you change the request link slightly as documented. instead of using the entryID where you have it after the entries/ in your link in the question, use it as demonstrated below.
https://cdn.contentful.com/spaces/oc3u7dt7mty5/entries?access_token=6cabb22c95d52aa7752fe70ae9b3271a1fc2decf7ae7d99ccd7dceba718980e6&content_type=3HjHXUYR3yyosUqAGmi8wu&fields.restaurantField.sys.id=2UmoQ8Bo4g4S82WmGiQIQE
It's been moved into the sys.id at the end of the URL.

Resources