JSON Request With Saved Object Find API

In the Find API, there is a has_reference parameter which is an object with fields type and id. However,

  • There is no example I can find of how to format that as a URL (e.g., for a curl get)
  • This comment implies that I can send the request as JSON. But my attempts to do so does not work
curl -b cookie.txt -k -H 'Content-Type: application/json' -XGET 'https://localhost:5601/api/saved_objects/_find' -d '
{
    "type": "visualization",
    "hasReference": {
        "type": "index-pattern",
        "id": "728b8d30-5977-11ea-a830-91c011d847a4"
    }
}
> '
{"statusCode":400,"error":"Bad Request","message":"[request query.type]: expected at least one defined value but got [undefined]"}
  • Note that if I include the type in the URL I will get data but it is obvious that the hasReference parameter as JSON request body was not processed.

Does anyone know how to either format a has_reference parameter or in general, send GET requests as JSON body to Kibana?

Hi @git-blame and welcome to the Discuss community!
The saved_objects/_find API doesn't support using hasReference. hasReference refers to saved objects that reference other saved objects like a dashboard referencing the visualization saved objects it contains.
If there's a specific saved object you want to retrieve, you can try using the experimental get API.

So it turns out you can use the has_reference parameter if you URL encode the JSON object. For example:

curl -b cookie.txt -G 'https://localhost:5601/api/saved_objects/_find?type=visualization&fields=title' 
--data-urlencode 'has_reference={ "type": "index-pattern", "id": "728b8d30-5977-11ea-a830-91c011d847a4" }' 

You would only get visualization objects that references that object.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.