Hey guys this is my service file :
public async Task CallThirdPartyApiAsync(string phoneNumber)
{
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.bland.ai/v1/calls");
request.Headers.Add("Authorization", "JAQERTYUIOPSDFGHJKLZXCVBNMRTEIOUYSDFGHJKLZXCVBNMRTEIOUYSDFGHJKLZXCVB");
var content = new StringContent("{\r\n "phone_number": "+91**",\r\n "task": "Say Hello Anubhav How are you",\r\n "voice" : "maya"\r\n}", null, "application/json");
request.Content = content;
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
// Deserialize the response content into a CallerId object
var callerId = JsonConvert.DeserializeObject<CallerId>(responseContent);
// Save the CallerId object to the database
_context.callerid.Add(callerId);
await _context.SaveChangesAsync();
}
//Here i have to store value of this phone number and Task in string format so that in my swagger i can give any input whatever i want //
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.bland.ai/v1/calls");
request.Headers.Add("Authorization", "JAQERTYUIOPSDFGHJKLZXCVBNMRTEIOUYSDFGHJKLZXCVBNMRTEIOUYSDFGHJKLZXCVB");
var content = new StringContent("{\r\n "phone_number": "+91**",\r\n "task": "Say Hello Anubhav How are you",\r\n "voice" : "maya"\r\n}", null, "application/json");
request.Content = content;
12 Replies
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/Also, use
JsonSerializer
or even JsonContent
content type instead of trying to assemble the JSON string manually
And, most importantly, what is the question?This string in the
StringContent
will not work
That said, again, what is your question?@ZZZZZZZZZZZZZZZZZZZZZZZZZ Sir i'm calling an URL inside my API there i was giving hardcoded value of phone number and task as you can see i want to modify this code such that on my swagger i can manually put any phone number or task there in my swagger
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
And set the auth on the client, not the request?
TeBeCo
you also probably should not use
request.Headers.Add(
but an HttpMessageHandler
to inject the Authorization
token at HttpClient levelQuoted by
<@689473681302224947> from #Hey guys this is my service file : (click here)
React with ❌ to remove this embed.
Ah, makes sense
I hope that token isn't real
Thank you so much guys let me try and come back to you