Can't set basicAuth when adding InfluxDB datasource through the API

I am trying to add a datasource by sending a POST request to /api/datasource with the following payload:

{
 "orgId": 1,
 "name": "mydatasource",
 "type": "influxdb",
 "access": "proxy",
 "isDefault": false,
 "url": "http://myinfluxdbdomain:8086",
 "password": "<password>",
 "user": "grafana",
 "database": "mydatabase",
 "basicAuthUser": true,
 "basicAuthUser": "grafana",
 "basicAuthPassword": "<password>"
}

The data source is properly added, but the basicAuth related fields are simply ignored:

{"datasource": {"id": 10,
   "orgId": 1,
   "name": "mydatasource",
   "type": "influxdb",
   "typeLogoUrl": "",
   "access": "proxy",
   "url": "http://myinfluxdbdomain:8086",
   "password": "<password>",
   "user": "grafana",
   "database": "mydatabase",
   "basicAuth": false,
   "basicAuthUser": "",
   "basicAuthPassword": "",
   "withCredentials": false,
   "isDefault": false,
   "secureJsonFields": {},
   "version": 1,
   "readOnly": false},
 "id": 10,
 "message": "Datasource added",
 "name": "mydatasource"}'

I have tried all sorts of things and still can’t get this to work, which leads me think it is a bug of sort. Has anyone managed to add a datasource which requires basicAuth through the API?

Probably a typo. Try to update

"basicAuthUser": true,

to:

"basicAuth": true,

Hi, thanks for the reply!

I managed to fix the problem.

I was using the Python requests library and it seems that the issue was due to the JSON payload (Python dictionary) being passed with the data argument instead of json (which seems to change some headers in the request as well).

# Before
session.post(url.format('/api/datasources'), data=payload)

# After
session.post(url.format('/api/datasources'), json=payload)

The typo probably showed up when I was copying/formatting the JSON to post here.