Gateways - Create Datasource

Creates a new data source on the specified on-premises gateway.


On premises data source credentials must be encrypted. The encryptedConnection parameter must be set to Encrypted and the credentials should be encrypted using the gateway public key.

See the CreateGatewayDataSource PowerShell script for an example of using this API.

Note

To encrypt credentials, see Configure credentials programmatically for Power BI and review the EncryptCredentials .NET Core, Java and Python examples.

Permissions

Supports only on-premises gateways and the user must have gateway admin permissions

Required Scope

Dataset.ReadWrite.All

Limitations

  • Virtual network (VNet) and Cloud gateways aren't supported.
  • OAuth2 as a credential type isn't supported.

POST https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources

URI Parameters

Name In Required Type Description
gatewayId
path True
  • string
uuid

The gateway ID. When using a gateway cluster, the gateway ID refers to the primary (first) gateway in the cluster. In such cases, gateway ID is similar to gateway cluster ID.

Request Body

Name Required Type Description
connectionDetails True
  • string

The connection details

credentialDetails True

The credential details

dataSourceName True
  • string

The data source name

dataSourceType True
  • string

The data source type

Responses

Name Type Description
201 Created

Created

Examples

Azure Analysis Services example
SQL example

Azure Analysis Services example

Sample Request

POST https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources
{
  "dataSourceType": "AnalysisServices",
  "connectionDetails": "{\"server\":\"MyServer\",\"database\":\"MyDatabase\"}",
  "datasourceName": "Sample Datasource",
  "credentialDetails": {
    "credentialType": "Windows",
    "credentials": "AB....EF==",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "RSA-OAEP",
    "privacyLevel": "None"
  }
}

Sample Response

SQL example

Sample Request

POST https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources
{
  "dataSourceType": "SQL",
  "connectionDetails": "{\"server\":\"MyServer\",\"database\":\"MyDatabase\"}",
  "datasourceName": "Sample Datasource",
  "credentialDetails": {
    "credentialType": "Windows",
    "credentials": "AB....EF==",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "RSA-OAEP",
    "privacyLevel": "None"
  }
}

Sample Response

Definitions

CredentialDetails

The credential details

credentialType

The type of data source credential

encryptedConnection

Whether to encrypt the data source connection. The API call will fail if you select encryption and Power BI is unable to establish an encrypted connection with the data source.

encryptionAlgorithm

The encryption algorithm. For a cloud data source, specify None. For an on-premises data source, specify RSA-OAEP and use the gateway public key to encrypt the credentials.

GatewayDatasource

A Power BI gateway data source

GatewayDatasourceCredentialDetails

The data source credential details

privacyLevel

The privacy level, which is relevant when combining data from multiple sources.

PublishDatasourceToGatewayRequest

A publish data source to gateway request

CredentialDetails

The credential details

Name Type Description
credentialType

The credential type

credentials
  • string

The credentials, which depend on the 'credentialType' value. For more information, see Update Datasource examples.

encryptedConnection

Whether to encrypt the data source connection. The API call will fail if you select encryption and Power BI is unable to establish an encrypted connection with the data source.

encryptionAlgorithm

The encryption algorithm. For a cloud data source, specify None. For an on-premises data source, specify RSA-OAEP and use the gateway public key to encrypt the credentials.

privacyLevel

The privacy level, which is relevant when combining data from multiple sources.

useCallerAADIdentity
  • boolean

Whether the Azure AD identity (OAuth 2.0 credentials) of the API caller (which must be the data source owner) will be used to configure data source credentials (the owner OAuth access token). Typically, you would either use this flag or useEndUserOAuth2Credentials.

useEndUserOAuth2Credentials
  • boolean

Whether the end-user Azure AD identity (OAuth 2.0 credentials) is used when connecting to the data source in DirectQuery mode. Use with data sources that support single sign-on (SSO). Typically, you would either use this flag or useCallerAADIdentity.

credentialType

The type of data source credential

Name Type Description
Anonymous
  • string
Basic
  • string
Key
  • string
OAuth2
  • string
SAS
  • string
Windows
  • string

encryptedConnection

Whether to encrypt the data source connection. The API call will fail if you select encryption and Power BI is unable to establish an encrypted connection with the data source.

Name Type Description
Encrypted
  • string
NotEncrypted
  • string

encryptionAlgorithm

The encryption algorithm. For a cloud data source, specify None. For an on-premises data source, specify RSA-OAEP and use the gateway public key to encrypt the credentials.

Name Type Description
None
  • string
RSA-OAEP
  • string

GatewayDatasource

A Power BI gateway data source

Name Type Description
connectionDetails
  • string

Connection details in JSON format

credentialDetails

The connection details for the data source that needs update. The connection details are mandatory when the dataset has more than one data source.

credentialType

The type of data source credential

datasourceName
  • string

The name of the data source

datasourceType
  • string

The type of data source.

API name for the data source
ActiveDirectory AdobeAnalytics AdoDotNet
AnalysisServices AzureBlobs AzureDataLakeStorage
AzureMarketplace AzureTables BizTalk
CDPA CustomConnector CustomHttpApi
DB2 Essbase EventHub
Excel Exchange Extension
Facebook File Folder
GoogleAnalytics Hdfs HDInsight
Informix MQ MySql
OData ODBC OleDb
Oracle PostgreSql PowerQueryMashup
PubNub Salesforce SAPBW
SAPBWMessageServer SapErp SAPHana
SharePoint SharePointDocLib SharePointList
Sql Sybase Teradata
UIFlow Web
gatewayId
  • string

The associated gateway ID. When using a gateway cluster, the gateway ID refers to the primary (first) gateway in the cluster and is similar to the gateway cluster ID.

id
  • string

The unique ID for the data source

GatewayDatasourceCredentialDetails

The data source credential details

Name Type Description
useEndUserOAuth2Credentials
  • boolean

Whether the end-user Azure AD identity (OAuth 2.0 credentials) is used when connecting to the data source in DirectQuery mode. Use with data sources that support single sign-on (SSO).

privacyLevel

The privacy level, which is relevant when combining data from multiple sources.

Name Type Description
None
  • string
Organizational
  • string
Private
  • string
Public
  • string

PublishDatasourceToGatewayRequest

A publish data source to gateway request

Name Type Description
connectionDetails
  • string

The connection details

credentialDetails

The credential details

dataSourceName
  • string

The data source name

dataSourceType
  • string

The data source type