Importing dashboards using kibana api through curl

Hi Community,

I want to import metricbeat dashboard , but i can't find the id. ELK version 7.17
command used

 curl -u user:pass -k -X POST "https://localhost:5601/api/saved_objects/_export -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
  "type": "metricbeat-*"
}
' > export-2.ndjson

when i open this file , the file was empty.

I read some where, to import dashboard we need dashboard id through id we can download dashboard .

I also inspected the dashboard [Metricbeat System] Overview ECS but i couldn't find the id

That is not a valid Saved Object type (dashboard, index-pattern, etc). You need first find the identifiers of the saved objects you want to export and then build a request like this:

curl --header 'Content-Type: application/json' \
  --header 'kbn-xsrf: true' \
  --request POST \
  --user ${ELASTIC_USER}:${ELASTIC_PASSWORD} \
  "${KIBANA_HOST}/api/saved_objects/_export" \
  --data '{ "objects": 
[
  {"type": "index-pattern", "id":"YOUR-ID1"},
  {"type": "index-pattern", "id":"YOUR-ID2"},
  {"type": "index-pattern", "id":"YOUR-ID3"},
  {"type": "index-pattern", "id":"YOUR-ID4"},
...
]
}'

To find your index pattern identifiers you can run something like this using jq to extract the identifiers

curl --silent --header 'Content-Type: application/json' \
  --header 'kbn-xsrf: true' \
  --request GET \
  --user ${ELASTIC_USER}:${ELASTIC_PASSWORD} \
  "${KIBANA_HOST}/api/saved_objects/_find?type=index-pattern&search_fields=title&search=metricbeat" \
  | jq '.saved_objects[].id'

I am getting below error

{"statusCode":400,"error":"Bad Request","message":"Trying to export object(s) with non-exportable types: metricbeat:Metricbeat-system-overview-ecs"}

query i ran

curl -k --header 'Content-Type: application/json' \
  --header 'kbn-xsrf: true' \
  --request POST \
  --user elastic:elastic \
  "https://localhost:5601/api/saved_objects/_export" \
  --data '{ "objects":
[
  {"type": "metricbeat", "id":"Metricbeat-system-overview-ecs"}

]
}'

Please review again the documentation for the export endpoint to understand how to build your objects key