2
votes

I am trying to use the Microsoft Power BI API to create a new data source on a gateway https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource. To test I am trying to create a connection to an Azure Sql Database with basic authentication. I can add the data source using Power BI online GUI without a problem, however whenever I am trying to use the API I receive a 400 - DMTS_InvalidEncryptionAlgorithmError.

The key field is encryptionAlgorithm in the body, but as stated in the API documentation, it should be "None" for cloud data sources.

I have also tried using "RSA-OAEP", but this gives me a 400 - DM_GWPipeline_UnknownError.

I am currently working with Postman, but I also tried to replicate the same request with NodeJS with the same result.

Any hints towards a solution would be very helpful.

POST https://api.powerbi.com/v1.0/myorg/gateways/00000000-0000-0000-0000-000000000000/datasources

Headers

content-type: application/json,
Autorization: Bearer token

Body

{
"datasourceType": "Sql",
"connectionDetails": "{\"server\":\"servername.database.windows.net\",\"database\":\"dbname\"}",
"credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"myusername\"},{\"name\":\"password\", \"value\":\"mypwd\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
},
"datasourceName": "new-datasource-name"
}

Error message when using "None" - HTTP 400

{
"error": {
    "code": "DMTS_InvalidEncryptionAlgorithmError",
    "pbi.error": {
        "code": "DMTS_InvalidEncryptionAlgorithmError",
        "parameters": {},
        "details": [],
        "exceptionCulprit": 1
    }
}
}

Error message when using "RSA-OAEP" - HTTP 400

{
"error": {
    "code": "DM_GWPipeline_UnknownError",
    "pbi.error": {
        "code": "DM_GWPipeline_UnknownError",
        "parameters": {},
        "details": [
            {
                "code": "DM_ErrorDetailNameCode_UnderlyingErrorMessage",
                "detail": {
                    "type": 1,
                    "value": "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. "
                }
            },
            {
                "code": "DM_ErrorDetailNameCode_UnderlyingHResult",
                "detail": {
                    "type": 1,
                    "value": "-2146233033"
                }
            }
        ]
    }
}
}
2

2 Answers

2
votes

Just for completeness, here is Node code that you can use to encrypt your credentials. Using the library node-rsa

const nodeRSA  = require("node-rsa");

const credentials = '{\"credentialData\":[{\"name\":\"username\", \"value\":\"myusername\"},{\"name\":\"password\", \"value\":\"mypwd\"}]}';

const exponentString = 'AQAB';
const modulusString = 'rasdfsafsdfsadfsdafsdferasdasgfasgsfgdfgsdfgdsfgrgsrareasgasgasfasfasdfasdfsadfsadfgsadfsadfasfasdfsadfsdafasdfrgrhe4t345tge5g54g5gegdrg5tg45efgdfg5t=';

const key = new nodeRSA();

const modulus = new Buffer(modulusString, 'base64');
const exponent = new Buffer(exponentString, 'base64');

const pubKey = key.importKey({ n: modulus, e: exponent }, 'components-public');

const encrypted = pubKey.encrypt(credentials, 'base64');

console.log(encrypted)
1
votes

I think you need to encrypt your credentials when you load - not made very clear in the documentation. You can't just upload the free text.

Makes sense for security!

https://docs.microsoft.com/en-us/power-bi/developer/encrypt-credentials