Issue with API - Get a single data source by Name

Hi!
Some trouble here with Grafana 5.0.0-beta4 API.
Here my scenario:

40

$ curl -X GET http://admin:admin@my.host.io:3000/api/datasources/id/datasource_foo
{"id":1}

$ curl -X GET http://admin:admin@my.host.io:3000/api/datasources/datasource_foo
{"id":1,"orgId":1,"name":"datasource_foo","type":"influxdb","typeLogoUrl":"","access":"proxy","url":"http://my.host.io:8086","password":"admin","user":"admin","database":"host-dev-foo","basicAuth":false,"basicAuthUser":"","basicAuthPassword":"","withCredentials":false,"isDefault":false,"jsonData":{"keepCookies":[]},"secureJsonFields":{},"version":4,"readOnly":false}

That is the expected behavior. But…

$ curl -X GET http://admin:admin@my.host.io:3000/api/datasources/id/does_not_exist_datasource
{"message":"Data source not found"}

$ curl -X GET http://admin:admin@my.host.io:3000/api/datasources/does_not_exist_datasource
{"id":1,"orgId":1,"name":"datasource_foo","type":"influxdb","typeLogoUrl":"","access":"proxy","url":"http://my.host.io:8086","password":"admin","user":"admin","database":"host-dev-foo","basicAuth":false,"basicAuthUser":"","basicAuthPassword":"","withCredentials":false,"isDefault":false,"jsonData":{"keepCookies":[]},"secureJsonFields":{},"version":4,"readOnly":false}

Why last API call return the datasource?

Thanks!

Hi,

You’ve used found a type in http api documentation. Will update documentation.

To get datasource by id use the /api/datasources/<numeric datasource id>
To get datasource by name use the /api/datasources/name/<datasource name of type string>

Thanks for reporting this!

Marcus

1 Like