Api calling in .net core razor pages
I am working on (built-in web apis) provided by whatsapp business api. As a newbie in .net core razor pages and web apis. I want to know how can I get access to the body of the post request api. Take an example below for sending a message
Post: {URL}/v1/messages Request Body: "to": "", "message_type:" "message_text:" "recipient_type: "individual | group""
How can I make a call to the builtin api and access the body parts of it? Ofcourse, we as a developer can use postman for checking the working of api. But take this as a client and for the client we have some fields like
To: Message:
How can take these fields and put it into the api call body and then when the user click on the send, the api call works and shows whatever we want to show the user for example a model with send successfully etc.
You can call the API using HttpClient.
Add the URL in await client.PostAsync() function. If you have authorization use client.DefaultRequestHeaders.Authorization otherwise omit it
string myContent = ""; string myJson = <JsonQuery>; using (HttpClient client = new HttpClient()) { // If any authorization available client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenLabel.Text.Trim()); using (HttpResponseMessage response = await client.PostAsync("https:url", new StringContent(myJson, Encoding.UTF8, "application/json"))) { using (HttpContent content = response.Content) { myContent = await content.ReadAsStringAsync(); } } }Update
Content
string myJson = "{\"subject\": }";
URL using (HttpResponseMessage response = await client.PostAsync("{{URL}}/v1/groups", new StringContent(myJson, Encoding.UTF8, "application/json")))
Header client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "");
Thank you for your answer, but can you be more specific. Sorry as I am really new in this.!
@FarrukhAhmedKhan, I have updated the answer. Please check it. If possible provide your postman screenshot (hide the URL and parameter)
imgur.com/YXeQgu8 @Golda, you can check image of postman on the link above and the response of the api below imgur.com/lANIiC0
@FarrukhAhmedKhan, Answer has been updated. Check it out
Can I have your email or something where I can ask some more things. I need some real help. Thank you