Forum Discussion
Power BI REST API via Powershell: Create Datasource
Sokon i'm trying to create a new data source on a gateway via REST API POST Method.
Here's the body of the request in JSON format:
$body2='{
"dataSourceType": "SQL",
"connectionDetails": "{\"server\":\"test2\",\"database\":\"MyDatabase\"}",
"datasourceName": "Sample Datasource",
"credentialDetails": {
"credentialType": "Basic",
"credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"Myuser\"},{\"name\":\"password\", \"value\":\"***\"}]}",
"encryptedConnection": "Encrypted",
"encryptionAlgorithm": "None",
"privacyLevel": "None"
}
}'
{
Invoke-PowerBIRestMethod -url "https://api.powerbi.com/v1.0/myorg/gateways/$GatewayID/datasources" -Method post -body $body2
I get error bad request 400... when i try to add this data source manually from the PowerBI administration GUI it's working.
If i'm using the GET method it's working as well and i can see all the data sources on that gateway...
Any ideas?
Ronnie7 There are some things I learned from experimenting with the (now working) PS-Code for the "Add Datasource Users"-Command I can share:
- Parameters seem to be case sensitive. "READ" is wrong "Read" worked. When you run the "Get Datasource" command, it will return "Sql" as dataSourceType and not "SQL".
- I can add Datasource Users only if the email addresses were valid. Fake or dummy addresses provoked an error. Perhaps that's the same with datasources. That's the reason why a tried to create a Web datasource with an anonymous authentication
- Here is a similar thread where someone wants to use C# instead of PowerShell. Nevertheless, look at the part/discussion about the credentials-tag: It's some kind of encrypted string that needed some clarification. Perhaps you understand that better than me?
- Ronnie77 years agoHelper II
Sokon thanks for the info.
I have seen that thread that you mentioned, and I also struggle to understand it. Looks like we are missing something there...
I'll actually try to create a new web data source with anonymouts login and see if that will work.if so, i'll share the code.
- Anonymous7 years agoNot applicable
- Sokon7 years agoAdvocate V
No progress here, sorry. But I posted an idea where you can vote for the documentation to be updated!