Forum Discussion
daveParso
9 years agoFrequent Visitor
PostRowsInGroups is giving badRequest from Json object
I have the following code to create a json object and then post this to a streaming dataset in powerBI. With the code i have so far i seem to be finding the dataset and table just fine but i am getti...
- 9 years ago
You can add try..catch blocks to get the bad request details.
try { client.Datasets.PostRowsInGroup(groupId, yourdatesetid, "RealTimeData", dataObj); } catch (HttpOperationException ex) { //Bad Request var content = ex.Response.Content; Console.WriteLine(content); }Based on my test, my below demo work.
static void Main(string[] args) { var credentials = new TokenCredentials(accessToken); using (var client = new PowerBIClient( credentials)) { var payload = new testValues { value1 = "test", value2 = 1, value3 = DateTime.UtcNow // value3 = DateTime.UtcNow.ToString("s") + "Z" }; IList<testValues> list = new List<testValues>(); list.Add(payload); var stringPayload = JsonConvert.SerializeObject(list); object dataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Object>(stringPayload.ToString()); //StringContent postContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); try { client.Datasets.PostRowsInGroup(groupId,datasetId, "RealTimeData", dataObj); } catch (HttpOperationException ex) { //Bad Request var content = ex.Response.Content; Console.WriteLine(content); } } Console.WriteLine("Done"); Console.ReadKey(); }
Eric_Zhang
9 years agoMicrosoft Employee
You can add try..catch blocks to get the bad request details.
try
{
client.Datasets.PostRowsInGroup(groupId, yourdatesetid, "RealTimeData", dataObj);
}
catch (HttpOperationException ex)
{
//Bad Request
var content = ex.Response.Content;
Console.WriteLine(content);
}
Based on my test, my below demo work.
static void Main(string[] args)
{
var credentials = new TokenCredentials(accessToken);
using (var client = new PowerBIClient( credentials))
{
var payload = new testValues
{
value1 = "test",
value2 = 1,
value3 = DateTime.UtcNow
// value3 = DateTime.UtcNow.ToString("s") + "Z"
};
IList<testValues> list = new List<testValues>();
list.Add(payload);
var stringPayload = JsonConvert.SerializeObject(list);
object dataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Object>(stringPayload.ToString());
//StringContent postContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
try
{
client.Datasets.PostRowsInGroup(groupId,datasetId, "RealTimeData", dataObj);
}
catch (HttpOperationException ex)
{
//Bad Request
var content = ex.Response.Content;
Console.WriteLine(content);
}
}
Console.WriteLine("Done");
Console.ReadKey();
}