Gateways - Update Datasource

Updates the credentials of the specified data source from the specified gateway.

Note

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

  • Set the parameter useEndUserOAuth2Credentials to False when changing from single sign-on to other credential types, such as Basic or OAuth2. See the Basic credentials example.
  • For the OAuth 2.0 credential type, make sure the generated OAuth 2.0 token audience was set correctly according to the data source type.
  • For Extension data sources, don't set useCallerAADIdentity to true. To set OAuth 2.0 credentials for other data sources, send the OAuth 2.0 token in the payload as shown in the OAuth 2.0 credentials example.

Permissions

Required Scope

Dataset.ReadWrite.All

Limitations

Virtual network (VNet) gateways aren't supported.

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

URI Parameters

Name In Required Type Description
datasourceId
path True
  • string
uuid

The data source ID

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
credentialDetails True

The credential details

Responses

Name Type Description
200 OK

OK

Examples

Anonymous credentials example
Basic credentials example
Key credentials example
OAuth 2.0 credentials example
Windows credentials example

Anonymous credentials example

Sample Request

PATCH https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources/252b9de8-d915-4788-aaeb-ec8c2395f970
{
  "credentialDetails": {
    "credentialType": "Anonymous",
    "credentials": "{\"credentialData\":\"\"}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}

Sample Response

Basic credentials example

Sample Request

PATCH https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources/252b9de8-d915-4788-aaeb-ec8c2395f970
{
  "credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"john\"},{\"name\":\"password\", \"value\":\"*****\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None",
    "useEndUserOAuth2Credentials": "False"
  }
}

Sample Response

Key credentials example

Sample Request

PATCH https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources/252b9de8-d915-4788-aaeb-ec8c2395f970
{
  "credentialDetails": {
    "credentialType": "Key",
    "credentials": "{\"credentialData\":[{\"name\":\"key\", \"value\":\"ec....LA=\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}

Sample Response

OAuth 2.0 credentials example

Sample Request

PATCH https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources/252b9de8-d915-4788-aaeb-ec8c2395f970
{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"eyJ0....fwtQ\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}

Sample Response

Windows credentials example

Sample Request

PATCH https://api.powerbi.com/v1.0/myorg/gateways/1f69e798-5852-4fdd-ab01-33bb14b6e934/datasources/252b9de8-d915-4788-aaeb-ec8c2395f970
{
  "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.

privacyLevel

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

UpdateDatasourceRequest

An update 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
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

privacyLevel

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

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

UpdateDatasourceRequest

An update data source to gateway request

Name Type Description
credentialDetails

The credential details