Create influxdb (type: flux) datasource using API with token

I am trying to add a new datasource using API and need to to be scripted. I can’t find a way to set the “token” in the InfluxDB details field.

I’ve looked and the following documentation and able to create a new influxdb datasource except the token, see snapshot below.


The curl command below works but looking from the gui, obviously “Token” field is blank. How do I set the token field using api?

curl -X POST --insecure “Authorization: Bearer <MY_TOKEN>” -H “Content-Type: application/json” -d ‘{
“jsonData”: {
}’ http://admin:admin@localhost:3000/api/datasources

Here is an example of my python script, “<>” are my variables that you have to replace with yours

import requests
import json

apiKey1 = "<MyApiKey>"
token = "<MyInfluxDBToken>"

server = "http://localhost:3000/"
url = server + "api/datasources/"
headers = {"Authorization":"Bearer "+apiKey1,

my_json = {
        "token": token

r = = url.format('/api/datasources'), headers = headers, json = my_json, verify=False)

data = r.json()

To see what you need (because it depends on your version) you can see the POST request with a valid datasource and using the GUI. In dev tools record the network to see the request.

When you get it, you can delete id, uid and replace secureJsonField with secureJsonData.
Your token have to be in secureJsonData.