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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jaapinho
New Member

Rest API / Powershell : Unable to create Datasource in Gateway (OnPremises)

Hello,
 
I'm using this code :
 
$url = "gateways/MYGateway/datasources"
$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
 
Note  : Credentials hash is RSA-OEP crypted from :
   {
    \"credentialData\":
       [
       {\"name\":\"username\",\"value\":\"MYUsername\"},
       {\"name\":\"password\", \"value\":\"MYPassword\"}
       ]
   }
 
This code returns :
    VERBOSE: Request Uri:
    https://api.powerbi.com/v1.0/myorg/gateways/MYGateway/datasources
    VERBOSE: Status Code: BadRequest (400)
 
I don't understand why. Can someone please help ?
1 ACCEPTED SOLUTION
jaapinho
New Member

Hi, MYgateway represents my gateway ID (Which i couldnt put here). But problem is solved. creds hash was miscalculated.

Thank you

View solution in original post

3 REPLIES 3
Ybam
Helper I
Helper 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-...)
Thank you 

jaapinho
New Member

Hi, MYgateway represents my gateway ID (Which i couldnt put here). But problem is solved. creds hash was miscalculated.

Thank you

lbendlin
Super User
Super User

there is no such thing as MyGateway. Did you mean to call Gateways - Create Datasource (Power BI Power BI REST APIs) | Microsoft Docs ?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.