Forum Discussion
PBIRS API issue
- 6 years ago
Hi,
based on your input I did some more research. The error was, as you expected, that the payload was wrong. I thougth because auf the patch method only several fields need to be put into the payload. But instead the whole body needs to be in the payload. Now it works fine.
body of the get request:
{ "@odata.context": "uri", "value": [ { "Id": "datasourceId", "Name": null, "Description": null, "Path": null, "Type": "DataSource", "Hidden": false, "Size": 0, "ModifiedBy": "name", "ModifiedDate": "datetime", "CreatedBy": "name", "CreatedDate": "datetime", "ParentFolderId": null, "IsFavorite": false, "Roles": [], "ContentType": null, "Content": "", "IsEnabled": true, "ConnectionString": "domain", "DataSourceType": null, "IsOriginalConnectionStringExpressionBased": false, "IsConnectionStringOverridden": false, "CredentialRetrieval": "prompt", "CredentialsByUser": null, "CredentialsInServer": null, "IsReference": false, "DataSourceSubType": "DataModel", "DataModelDataSource": { "Type": "Import", "Kind": "ActiveDirectory", "AuthType": "Windows", "SupportedAuthTypes": [ "Windows", "UsernamePassword" ], "Username": "OldUsername", "Secret": "", //Password is empty in get request "ModelConnectionName": "" } } ] }this is the payload that worked for me (only use the value array):
[ { "Id": "Datasource id", "Name": null, "Description": null, "Path": null, "Type": "DataSource", "Hidden": false, "Size": 0, "ModifiedBy": "name", "ModifiedDate": "datetime", "CreatedBy": "name", "CreatedDate": "datetime", "ParentFolderId": null, "IsFavorite": false, "Roles": [], "ContentType": null, "Content": "", "IsEnabled": true, "ConnectionString": "domain", "DataSourceType": null, "IsOriginalConnectionStringExpressionBased": false, "IsConnectionStringOverridden": false, "CredentialRetrieval": "prompt", "CredentialsByUser": null, "CredentialsInServer": null, "IsReference": false, "DataSourceSubType": "DataModel", "DataModelDataSource": { "Type": "Import", "Kind": "ActiveDirectory", "AuthType": "Windows", "SupportedAuthTypes": [ "Windows", "UsernamePassword" ], "Username": "yourNewUsername", "Secret": "yourNewPassword", "ModelConnectionName": "" } } ]regarding the id: I read that when there is more than one source, every source needs to be in the requestbody, even if nothing changes
useful links:
http://dataap.org/blog/2020/01/16/power-bi-report-server-change-data-source-using-rest-apis/
https://community.powerbi.com/t5/Report-Server/Power-Bi-report-deployment-to-Production/td-p/662197
https://github.com/Microsoft/ReportingServicesTools/issues/116
Hi,
based on your input I did some more research. The error was, as you expected, that the payload was wrong. I thougth because auf the patch method only several fields need to be put into the payload. But instead the whole body needs to be in the payload. Now it works fine.
body of the get request:
{
"@odata.context": "uri",
"value": [
{
"Id": "datasourceId",
"Name": null,
"Description": null,
"Path": null,
"Type": "DataSource",
"Hidden": false,
"Size": 0,
"ModifiedBy": "name",
"ModifiedDate": "datetime",
"CreatedBy": "name",
"CreatedDate": "datetime",
"ParentFolderId": null,
"IsFavorite": false,
"Roles": [],
"ContentType": null,
"Content": "",
"IsEnabled": true,
"ConnectionString": "domain",
"DataSourceType": null,
"IsOriginalConnectionStringExpressionBased": false,
"IsConnectionStringOverridden": false,
"CredentialRetrieval": "prompt",
"CredentialsByUser": null,
"CredentialsInServer": null,
"IsReference": false,
"DataSourceSubType": "DataModel",
"DataModelDataSource": {
"Type": "Import",
"Kind": "ActiveDirectory",
"AuthType": "Windows",
"SupportedAuthTypes": [
"Windows",
"UsernamePassword"
],
"Username": "OldUsername",
"Secret": "", //Password is empty in get request
"ModelConnectionName": ""
}
}
]
}
this is the payload that worked for me (only use the value array):
[
{
"Id": "Datasource id",
"Name": null,
"Description": null,
"Path": null,
"Type": "DataSource",
"Hidden": false,
"Size": 0,
"ModifiedBy": "name",
"ModifiedDate": "datetime",
"CreatedBy": "name",
"CreatedDate": "datetime",
"ParentFolderId": null,
"IsFavorite": false,
"Roles": [],
"ContentType": null,
"Content": "",
"IsEnabled": true,
"ConnectionString": "domain",
"DataSourceType": null,
"IsOriginalConnectionStringExpressionBased": false,
"IsConnectionStringOverridden": false,
"CredentialRetrieval": "prompt",
"CredentialsByUser": null,
"CredentialsInServer": null,
"IsReference": false,
"DataSourceSubType": "DataModel",
"DataModelDataSource": {
"Type": "Import",
"Kind": "ActiveDirectory",
"AuthType": "Windows",
"SupportedAuthTypes": [
"Windows",
"UsernamePassword"
],
"Username": "yourNewUsername",
"Secret": "yourNewPassword",
"ModelConnectionName": ""
}
}
]
regarding the id: I read that when there is more than one source, every source needs to be in the requestbody, even if nothing changes
useful links:
http://dataap.org/blog/2020/01/16/power-bi-report-server-change-data-source-using-rest-apis/
https://community.powerbi.com/t5/Report-Server/Power-Bi-report-deployment-to-Production/td-p/662197
https://github.com/Microsoft/ReportingServicesTools/issues/116
this is the payload that worked for me (only use the value array)
Thank you! I was trying to change a report's ConnectionString using the PATCH method and it was not working no matter what. Turns out I needed to use only the value array, and deleting the @odata.context thing before the value array made it work.