Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
Hi all, I'm trying to use PowerBI REST API in order to create a datasource. I'm using the endpoint (POST) https://api.powerbi.com/v1.0/myorg/gateways/{id}/datasources with the following body:
```
Where credentials is basically `{\"credentialData\":[{\"name\":\"username\", \"value\":\"MYUSERNAME\"},{\"name\":\"password\", \"value\":\"MYPASSWORD\"}]}` encrypted by using the gateway public key.
No matter what I do, I keep getting as response 400 Bad Request with the body:
```
{
"error": {
"code": "DM_GWPipeline_UnknownError",
"pbi.error": {
"code": "DM_GWPipeline_UnknownError",
"parameters": {},
"details": [
{
"code": "DM_ErrorDetailNameCode_UnderlyingErrorMessage",
"detail": {
"type": 1,
"value": "El parámetro no es correcto.\r\n"
}
},
{
"code": "DM_ErrorDetailNameCode_UnderlyingHResult",
"detail": {
"type": 1,
"value": "-2146893785"
}
}
],
"exceptionCulprit": 1
}
```
What I'm doing wrong here? I'm really struggling to find valid documentation
BTW, what is suggested in the documentation I found is the following:
{ "credentialDetails": { "credentialType": "Basic", "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"john\"},{\"name\":\"password\", \"value\":\"*****\"}]}", "encryptedConnection": "Encrypted", "encryptionAlgorithm": "None", "privacyLevel": "None", "useEndUserOAuth2Credentials": "False" } }
Which still doesn't work
Solved! Go to Solution.
Hi @nk-alex ,
Great question unfortunately, DAX in Power BI is just for calculations and modeling, so it can't make REST API calls, handle encryption, or talk to gateways. The datasource creation you're working on happens outside of Power BI, so you'll need to use something like PowerShell, Postman, or a backend script in Python or C# to get that done.
If you just want to see or build the JSON body, Power Query can help with that, but it still can't do encryption or actually create the datasource through the API. Those parts have to be done with external tools to keep things secure.
So, DAX isn't able to test or set up this process you'll need an external tool that can handle encryption and REST API requests.
Thank you.
Hi @nk-alex ,
It sounds like the issue is most likely related to how the credentials are being encrypted before they’re sent through the API. The gateway requires that the credentials are encrypted using its public key, which you can obtain by calling the public key endpoint for your gateway.
Once you have that, make sure the credential JSON is encrypted with RSA-OAEP (SHA-1) so that it matches what the gateway expects. In your request, you’ll also want to double-check that the encryption algorithm is set to RSA-OAEP, the encrypted connection setting is set to Encrypted, and the privacy level is set appropriately to either Private or Organizational.
Another important step is to confirm that the MySQL ODBC connector is installed on the machine running the gateway and that you’re able to connect successfully from Power BI Desktop with the same credentials. If that connection works locally, the API call should go through as well once the encryption is configured correctly.
If you’ve already gone through these steps and it’s still giving you trouble, let us know and we can help you dig a little deeper.
Thank you,
Tejaswi.
Hi @nk-alex ,
Just checking in have you been able to resolve this issue? If so, it would be greatly appreciated if you could mark the most helpful reply accordingly. This helps other community members quickly find relevant solutions.
Thank you.
Hi @nk-alex ,
I wanted to follow up and see if you had a chance to review the information shared. If you have any further questions or need additional assistance, feel free to reach out.
Thank you,
Tejaswi.
Hi @nk-alex ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Thank you.
Hi @v-tejrama I have followed your steps and still not able to connect. Is my sent body correct?
Hi @nk-alex ,
Great question unfortunately, DAX in Power BI is just for calculations and modeling, so it can't make REST API calls, handle encryption, or talk to gateways. The datasource creation you're working on happens outside of Power BI, so you'll need to use something like PowerShell, Postman, or a backend script in Python or C# to get that done.
If you just want to see or build the JSON body, Power Query can help with that, but it still can't do encryption or actually create the datasource through the API. Those parts have to be done with external tools to keep things secure.
So, DAX isn't able to test or set up this process you'll need an external tool that can handle encryption and REST API requests.
Thank you.
Hi @nk-alex ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Thank you,
Tejaswi.
Hi! For credential details I found this in the documentation:
var credentialDetails = new CredentialDetails(
credentials,
CredentialTypeEnum.Basic,
EncryptedConnectionEnum.Encrypted,
EncryptionAlgorithmEnum.None,
PrivacyLevelEnum.Private);
Configure credentials programmatically for Power BI embedded analytics - Power BI | Microsoft Learn
I also found this documentation, but not sure if it is what you need or not: Python Implementation | microsoft/PowerBI-Developer-Samples | DeepWiki
Proud to be a Super User! | |
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.