The request format is like this provided by Facebook
'{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "PHONE_NUMBER",
"type": "text",
"text": { // the text object
"preview_url": false,
"body": "MESSAGE_CONTENT"
}
}'
I have written a code like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WhatsAppCloudApiDemo
{
public class Post
{
public string messaging_product { get; set; }
public string recipient_type { get; set; }
public string to { get; set; }
public string type { get; set; }
public string text { get; set; }
}
}
And the request is like this
Post newPost = new Post()
{
messaging_product = "whatsapp",
recipient_type = "individual",
to = number,
type = "text",
text = message
};
var newPostJson = JsonConvert.SerializeObject(newPost);
Console.WriteLine(newPostJson);
var payLoad = new StringContent(newPostJson, Encoding.UTF8, "application/json");
var result = client.PostAsync(endpoint, payLoad).Result.Content.ReadAsStringAsync().Result;
Console.WriteLine(result);
But I'm getting an error saying the Parameter should be a JSON object. I need to know the proper way to write the request for the below as it is object inside an object
"text": { // the text object "preview_url": false, "body": "MESSAGE_CONTENT" }