I would like to be able to call the sharepoint search rest api from my powerapps using flow.
I have a standalone app that displays data from a list with many fields in a gallery. I want to be able to filter the items in the list based on a sharepoint search query. (i.e. I want to be able to let the user enter CustomerName=Contos* and have the view show only records where the field CustomerName begins with ‘Contos’.
The powerapps search function works, but it queries all fields. I want to query on Specific fields using the search API.
I want to be able to call a flow, passing in the search query string ‘CustomerName=Contos*’ and the list of fields to return, and have the flow call the sharepoint search API (_api/search/postquery) and return the data in tabular format so that the gallery control can just switch between using list data and search results.
I got it working by looping through all the results in @body('SPSearch')?['d']?['postquery']?['PrimaryQueryResult']?['RelevantResults']?['Table']?['Rows']?['results'] and then for each row looping through all of the columns and setting a temporary field to the value for that column, but it takes 10 minutes to run a simple query (because of the work being done in the for loop).
The issue is that the results from search look like this:
"results": [
{
"__metadata": {
"type": "SP.SimpleDataRow"
},
"Cells": {
"results": [
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Rank",
"Value": "27.591251373291",
"ValueType": "Edm.Double"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "DocId",
"Value": "17594549904503",
"ValueType": "Edm.Int64"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Title",
"Value": "TiO2_BCN - GR Nanomaterials - V. Mathur",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ListItemID",
"Value": "5678",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Created",
"Value": "2014-06-27T14:46:49.0000000Z",
"ValueType": "Edm.DateTime"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "IsClosedOWSCHCS",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ContactEmailAddressOWSTEXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "CompanyOWSTEXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "RequestTextOWSMTXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ResponseTextOWSMTXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "_ranking_features_",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "PartitionId",
"Value": "9eec07e6-f6f8-4e24-b4c7-c5868500b417",
"ValueType": "Edm.Guid"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "UrlZone",
"Value": "0",
"ValueType": "Edm.Int32"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Culture",
"Value": "en-US",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ResultTypeId",
"Value": "0",
"ValueType": "Edm.Int32"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "RenderTemplateId",
"Value": "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js",
"ValueType": "Edm.String"
}
]
}
},
{
"__metadata": {
"type": "SP.SimpleDataRow"
},
"Cells": {
"results": [
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Rank",
"Value": "27.5383605957031",
"ValueType": "Edm.Double"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "DocId",
"Value": "17621262638504",
"ValueType": "Edm.Int64"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Title",
"Value": "Prochazka, Jan ADVANCED MATERIALS JTJ",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ListItemID",
"Value": "26",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Created",
"Value": "2011-02-21T22:12:36.0000000Z",
"ValueType": "Edm.DateTime"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "IsClosedOWSCHCS",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ContactEmailAddressOWSTEXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "CompanyOWSTEXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "RequestTextOWSMTXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ResponseTextOWSMTXT",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "_ranking_features_",
"Value": null,
"ValueType": "Null"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "PartitionId",
"Value": "9eec07e6-f6f8-4e24-b4c7-c5868500b417",
"ValueType": "Edm.Guid"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "UrlZone",
"Value": "0",
"ValueType": "Edm.Int32"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Culture",
"Value": "en-US",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "ResultTypeId",
"Value": "0",
"ValueType": "Edm.Int32"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "RenderTemplateId",
"Value": "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js",
"ValueType": "Edm.String"
}
]
}
]
Anyone have any ideas how to turn the search results in the above format into a regular ‘flat’ array so that it can be returned to powerapps?