Hello I want to run push app center from its api. But I don't know how to make the proper format.
I want to postasync from this api: https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications
What it needs for Headers is: X-API-Token ="{api token}" and Content Type="application/json"
For the body(content) I want to put this:
{
"notification_content" : {
"name" : "Campaign Name",
"title" : "Expired Warning",
"body" : "You have items that almost expired"
}
}
I have difficulties how to write in the correct format for HttpClient. I tried this and no work..
Content = new Content
{
Name = "Campaign Name",
Title = "Expired Warning",
Body = "You have items that almost expired"
};
using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) })
{
var myContent = JsonConvert.SerializeObject(data);
client.DefaultRequestHeaders.Add("X-API-Token", "{my api token}");
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
var builder = new UriBuilder(new Uri("https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications"));
HttpResponseMessage response = await client.PostAsync(builder.Uri, content);
};
But I know this code:
{
"notification_content" : {
"name" : "Campaign Name",
"title" : "Expired Warning",
"body" : "You have items that almost expired"
}
}
is not same with this to convert the json format:
Content = new Content
{
Name = "Campaign Name",
Title = "Expired Warning",
Body = "You have items that almost expired"
};
Can help me with the correct Serialize Json Format? and the correct format of httpclient header and body? I already found lot of sample but still no clue with the one that I want. Really appreciate your help guys :)