Forum Discussion

Tom-ADV's avatar
Tom-ADV
Frequent Visitor
3 years ago

Getting "Bad Request" for BindToGatewayInGroup() although nothing seems to be wrong

I'm working on an automation which should export an existing report, import it to a new workspace and bind it to a new Datasource.

 

The problem is that when executing the BindToGatewayInGroup, I get the below response although the new Datasource is clearly there and the status of the Datasource on the PowerBi app platform is "Online"

 

 



 

{
  "error": {
    "code": "DMTS_CanNotFindMatchingDatasourceInGatewayError",
    "pbi.error": {
      "code": "DMTS_CanNotFindMatchingDatasourceInGatewayError",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}

 

 
Here is my code:

 

public void BindToGatewayInGroup(Group group, Dataset dataset, GatewayDatasource datasource)
        {
            try
            {
                var serviceURL = PBI_API_BASE + $"groups/{group.Id}/datasets/{dataset.Id}/Default.BindToGateway";
                var datasourceObjectIdsArray = new[] { datasource.Id.ToString() };
                var requestBody = JsonConvert.SerializeObject(new { gatewayObjectId = datasource.GatewayId.ToString(), datasourceObjectIds = datasourceObjectIdsArray });

                var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
                var response = Client.PostAsync(serviceURL, content).Result;

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Status = {response.StatusCode}");
                }
                else
                {
                    return;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

 

 

Here is my requestbody:

 

{"gatewayObjectId":"754e1e6e-9777-4f4d-bf1b-9eb0405ac085","datasourceObjectIds":["9003c27f-bc4f-4b0c-88f0-2294d542e068"]}

 



 

1 Reply