c# - invalidJsonBody error posting to log analytics rest api -


hi im trying out new log analytics rest api example can found here: https://dev.loganalytics.io/documentation/authorization/api-keys running aforementioned error in title full code here: "{\"error\":{\"message\":\"the request had invalid properties\",\"code\":\"badargumenterror\",\"innererror\":{\"code\":\"queryvalidationerror\",\"message\":\"failed parsing query\",\"details\":[{\"code\":\"invalidjsonbody\",\"message\":\"unexpected token \\\"\",\"target\":null}]}}}"

my code can found below feel im missing simple here dont know i'm going wrong:

static void main(string[] args)     {         try         {             var client = new program();             client.execasync().wait();         }         catch(exception e)         {             console.writeline(e);             console.readline();         }     }      async task execasync()     {         var content = new stringcontent(getquerystring(), encoding.utf8, "application/json");         content.headers.add("x-api-key", "demo_key");         var response = await client.postasync("https://api.loganalytics.io/v1/workspaces/demo_workspace/query", content);         var responsestring = await response.content.readasstringasync();         console.writeline(responsestring.length);         console.readline();     }  private string getquerystring()     {         return jsonconvert.serializeobject("{\"query\":\"azureactivity | summarize count() category}");     } 

i noticed missing double quotes in json string. when did small java sysout

system.out.println("{\"query\":\"azureactivity | summarize count() category}"); 

it gave me output.

{"query":"azureactivity | summarize count() category} 

double quotes missing after - category" }

try string in code:

{\"query\":\"azureactivity | summarize count() category\"} 

you can try online json validators https://jsonlint.com/


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -