Unable to export Kibana dashboard using API

// curl -X POST “http://localhost:5601/api/saved_objects/_export” -H ‘kbn-xsrf: true’ -H ‘Content-Type: application/json’ -d’ { “type”: “index-pattern” } ‘

I use this as to export my dashboard but i get the error "Incorrect HTTP method for uri .......and method [POST], allowed: [DELETE, HEAD, GET, PUT]",
"status": 405

Any idea to fix this, thank youuu

Welcome to our community! :smiley:

Did you try replacing POST with GET?

1 Like

I just tried and it still gives the error. it shows "type": "illegal_argument_exception", "reason": """request [GET /"https://localhost/api/saved_objects/_export”] does not support having a body"""

I forget to mention. Both of elasticsearch and kibana running on version 8.3.3 . I run both of the services on docker

Hi @rt_888

This page gives the proper syntax.

So far your examples above have not been correct.

I just ran this

hyperion:sbrown$ curl -X POST "http://localhost:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '
{
  "type": "index-pattern"
}'

And it worked fine

It tried to run yours you are using back quotes not normal quotes looks like your cut-n-past is using smart quotes or something not normal quotes vs "

 curl -X POST “http://localhost:5601/api/saved_objects/_export” -H ‘kbn-xsrf: true’ -H ‘Content-Type: application/json’ -d’ { “type”: “index-pattern” } ‘

if I fix all the quotes... it works fine

curl -X POST "http://localhost:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'{ "type": "index-pattern" }'
1 Like

Hello @stephenb, Are we using curl -X here for calling Kibana API? Do we need to add curl -X too? I got error with " Incorrect HTTP method for uri"

P.S : Sorry, I am really new to working with API request and ELK stack.

The documents give you the exact syntax but I think you are cut-n-paste with smart quotes which is causing you issues..

So the response are the details of the saved objects from this request.

For the below request is it for export the data view saved objects? do I need to specifiy the api key? If yes, is it in JSON or Base64?

$ curl -X POST api/saved_objects/_export -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d ' { "type": "index-pattern" }'

Lets back up a bit.

What version of the stack are you on?

And what are you actually trying to accomplish?

And yes if your cluster has security enabled (authentication) you will need to pass those
either using the -u username:password flag or an API Key which you can rad about here

1 Like

The version of the Elastic and Kibana are on 8.3.3. I am trying to export the dashboard from one machine to another machine which also run the same version of elk stack.

and you want to do it via the API then you are on the right track... you need to decide if you are going to use basic auth or API Key.

of course it is very Simple to just do it through the Kibana UI -> Stack Management -> Saved Objects..

1 Like

Thanks @stephenb. I try with the basic auth and with API. I am a bit confused. Once I already exported the dashboard to another machine. The client machine which supposed to recieve the dashboard showing that it got the saved object file, but the object file is empty. Does it mean i also need to have the same index file for the dashboard?

You need to understand that an object like a dashboard has many dependent objects.

That is why I would start with the UI first to test export./ Import.

You also need to understand

includeReferencesDeep

As shown in the example

Export a specific saved object and it’s related objects :

$ curl -X POST api/saved_objects/_export -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '
{
  "objects": [
    {
      "type": "dashboard",
      "id": "be3733a0-9efe-11e7-acb3-3dab96693fab"
    }
  ],
  "includeReferencesDeep": true
}'

I don't know what that means...

Again if you are new to all this I would use the Kibana UI.

1 Like

Thanks a lot @stephenb :smile: . Yes I did the same method and resolve by adding index to another machine too so I can view the exported dashboard