Is this what you are after?
We use a CURL command to programmatically create visualisations and dashboards
curl -X POST \\
-H "osd-xsrf: true" \\
-H "securitytenant: $tenant" \\
"http://$USERNAME:$PASSWORD@host:5601/api/saved_objects/_import?overwrite=true" \\
--form file=@data.ndjson