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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Create data source from REST API

Hi everyone, 

I am trying to add a file type data source using REST API, however it is failing. I have tried with Service Principal as well as a usual user with PBI Pro license and admin rights on the gateway but no luck. I am wondering if I can get some help and can be guided in the right direction.

My calls are as below

JSON For data source connection

{
"datasourceName": "testDataSource",
"credentialDetails": {
"encryptedConnection": "Encrypted",
"credentialType": "Windows",
"credentials": {
"UserName": "<user_name_or_service_principal_ID>",
"Password": "System.Security.SecureString"
},
"privacyLevel": "Organizational",
"encryptionAlgorithm": "None"
},
"dataSourceType": "=File",
"connectionDetails": "{\"FilePath\":\"C:\\Working\\some.csv\"}"
}

 

REST API End Point
https://api.powerbi.com/v1.0/myorg/gateways/<gateway_id>/datasources

 

Error

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.

 

Thanks
Kaz

1 REPLY 1
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please refer the following posts, they might be helpful.

https://community.powerbi.com/t5/Developer/Invoke-RestMethod-The-remote-server-returned-an-error-400-Bad/td-p/445288

https://community.powerbi.com/t5/Developer/API-Refreshes-Data-Set-400-Bad-Request-error-after-first-time/td-p/399228

 

If it doesn’t meet your requirement, we suggest you to open a ticket here for help: https://powerbi.microsoft.com/en-us/support/

 

Support Ticket .gif

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Kudoed Authors