Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
nk-alex
New Member

Unable to create Datasource on PowerBI API

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:

 
```
{
  "dataSourceType": "MySql",
  "connectionDetails": "{\"server\":\"ip:port\",\"database\":\"db_name\"}",
  "datasourceName": "ds_name",
  "credentialDetails": {
        "credentialType": "Basic",
        "credentials": "oAAAxFtEpXVBt888BtpsG4VlkNKhHpaSdfkdcO0WQcX14jMl+PSU9iWEEEak+EoiDBplvJqYxCvZs1ljI9LJMo3jLuYyW6ajY011dU9VMgl7YBdVasPvn+MwN8PvwHA6PsBpmsEjYz4ZNR/JXOD16QjGf+ZPGOjaGUn8BSrpiXvMUM5wWwpcjEOPb6CIrMJnGsXCD9fNNyhRzPUyGLus/BjNQc0H2stqZXfRWVDe5fm1k0JLIxfdB03F9jJqYDCv55SpNDqXlE0alyLzv8tlAxbuiXu17RjwG+6vdp09eeWY6R4SNigc8DnRf3xTpZf7VSZfwo5MUUT0DepZrhxkWw==",
        "encryptedConnection": "Encrypted",
        "encryptionAlgorithm": "RSA-OAEP",
        "privacyLevel": "None"
    }
}

```


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

1 ACCEPTED 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.

View solution in original post

8 REPLIES 8
v-tejrama
Community Support
Community Support

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.

audreygerred
Super User
Super User

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

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors