2

I am trying to use the Microsoft Power BI API to create a new data source on a gateway https://learn.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 Answers 2

1

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://learn.microsoft.com/en-us/power-bi/developer/encrypt-credentials

Sign up to request clarification or add additional context in comments.

1 Comment

Worked using the EncodeCredentials method and setting encryptionAlgorithm to "RSA-OAEP". Thanks!
1

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)

2 Comments

This code snippet is not working for me - I think because the encryption scheme has since changed to 2048 bits. Is this code still working for you? Do you have any updated code?
Same here, got DM_ErrorDetailNameCode_UnderlyingErrorMessage and DM_ErrorDetailNameCode_UnderlyingHResult as a response in api.powerbi.com/v1.0/myorg/gateways Did anyone got this done. @tim?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.