Forum Discussion
Rest API / Powershell : Unable to create Datasource in Gateway (OnPremises)
$body = @{
datasourceName = "MYDatasource"
datasourceType = "SQL"
connectionDetails = '{"server":"MYServer\\MYInstance", "database":"MYDatabase"}'
credentialDetails = @{
credentialType = "Basic"
credentials = "%A4O%95f%2C%F6p%...%25%15%BB3cE%04"
encryptionAlgorithm = "RSA-OAEP"
useEndUserOAuth2Credentials = "False"
}
}
$jsbody = $body | ConvertTo-JSON
invoke-PowerBIRestMethod -Method Post -Url $url -Body $jsbody
{
\"credentialData\":
[
{\"name\":\"username\",\"value\":\"MYUsername\"},
{\"name\":\"password\", \"value\":\"MYPassword\"}
]
}
https://api.powerbi.com/v1.0/myorg/gateways/MYGateway/datasources
VERBOSE: Status Code: BadRequest (400)
Hi, MYgateway represents my gateway ID (Which i couldnt put here). But problem is solved. creds hash was miscalculated.
Thank you
3 Replies
- lbendlinSuper User
there is no such thing as MyGateway. Did you mean to call Gateways - Create Datasource (Power BI Power BI REST APIs) | Microsoft Docs ?
- jaapinhoRegular Visitor
Hi, MYgateway represents my gateway ID (Which i couldnt put here). But problem is solved. creds hash was miscalculated.
Thank you
- YbamHelper I
Hi jaapinho ,
I want to create a datasource in my on-prem gateway but I always had a 400 error.
My code is similar to yours and I have 2 questions:- What's your "MYInstance" ?
- How your credentials are crypted, I use for mine this script(https://endjin.com/blog/2020/12/how-to-update-credentials-for-an-on-prem-power-bi-data-source-using-powershell.html#script)
Thank you