# Kibana Import Objects API

**URL:** <https://discuss.elastic.co/t/kibana-import-objects-api/288383>\
**Category:** Kibana\
**Created:** [November 4, 2021, 5:58am UTC](https://discuss.elastic.co/t/kibana-import-objects-api/288383 "2021-11-04T05:58:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Clark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_clark/32/44467_2.png) [@Ryan\_Clark](https://discuss.elastic.co/u/Ryan_Clark)\
**Post date:** [November 4, 2021, 5:58am UTC](https://discuss.elastic.co/t/kibana-import-objects-api/288383/1 "2021-11-04T05:58:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [November 4, 2021, 9:01am UTC](https://discuss.elastic.co/t/kibana-import-objects-api/288383/2 "2021-11-04T09:01:52Z")

</div>

I have used a similar method for a bulk insert  
Invoke-WebRequest -uri "[http://localhost:9200/\_bulk](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.

> **[GitHub - trevorndodds/Powershell-grafana-scripts](https://github.com/trevorndodds/Powershell-grafana-scripts)**
>
> Contribute to trevorndodds/Powershell-grafana-scripts development by creating an account on GitHub.

> **[Sending Commands to Elasticsearch API's | Chris Reeves' Blog](https://chrisreeves.co.nz/2020/07/04/elasticsearch-apis-postman-powershell/)**
>
> A quick introduction into how to interact with Elasticsearch rest APIs using either Postman or Powershell

> **[PowerShell REST API Programming](https://wilsonmar.github.io/powershell-rest-api/)**
>
> Reaching to web servies on the web gives scripts data power

---

<div class="post-metadata">

**Author:** ![Ryan\_Clark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_clark/32/44467_2.png) [@Ryan\_Clark](https://discuss.elastic.co/u/Ryan_Clark)\
**Post date:** [November 8, 2021, 5:40am UTC](https://discuss.elastic.co/t/kibana-import-objects-api/288383/3 "2021-11-08T05:40:15Z")

</div>

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.

```auto
$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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 6, 2021, 5:40am UTC](https://discuss.elastic.co/t/kibana-import-objects-api/288383/4 "2021-12-06T05:40:25Z")

</div>

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