Kibana Import Objects API

Hi,
I'm trying to write a powershell script to import some saved objects I have created and exported from Kibana.

I can get this to work just fine on linux using curl:
curl -X POST "http://myserver:5601/api/saved_objects/_import?createNewCopies=false" -H "kbn-xsrf: true" --form file=@MyDashboard.ndjson -H 'kbn-xsrf: true'

How do you do this with invoke-restmethod in powershell? The main thing I'm not seeing is something equivalent to "--form" and then defining the file=

Has anyone done this in PowerShell with Invoke-RestMethod? Can you provide an example?

I have used a similar method for a bulk insert
Invoke-WebRequest -uri "http://localhost:9200/_bulk" -Method POST -ContentType "application/json" -InFile C:\temp\test.json -UseBasicParsing

This links will help you to write the PS script.

Thanks for the reply and the links but it seems that the Kibana API works a little differently requiring some extra headers or something. I've tried two methods and got to the point with both where I'm getting the error: "The remote server returned an error: (403) Forbidden."

I know I'm using the correct credentials as I can login through the web browser just fine.

Here are the two methods I tried.

$hdrs = @{}
$hdrs.Add("kbn-xsrf","true")
Invoke-RestMethod  -Method POST -Uri "https://$serverName:5601/api/saved_objects/_import?createNewCopies=false" -Credential $ACred -ContentType "application/json" -Body $WinDash -Headers $hdrs

and

Invoke-WebRequest -Uri "https://$serverName:5601/api/saved_objects/_import?createNewCopies=false" -Method POST -ContentType "application/json" -InFile $WinDash -UseBasicParsing
1 Like

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