C
C#5mo ago
Anubhav

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
Angius
Angius5mo ago
$code
MODiX
MODiX5mo ago
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/
Angius
Angius5mo ago
Also, use JsonSerializer or even JsonContent content type instead of trying to assemble the JSON string manually And, most importantly, what is the question?
Anubhav
AnubhavOP5mo ago
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();
}
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();
}
Angius
Angius5mo ago
This string in the StringContent will not work That said, again, what is your question?
Anubhav
AnubhavOP5mo ago
@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
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 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;
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius5mo ago
And set the auth on the client, not the request?
MODiX
MODiX5mo ago
TeBeCo
you also probably should not use request.Headers.Add( but an HttpMessageHandler to inject the Authorization token at HttpClient level
Quoted by
React with ❌ to remove this embed.
Angius
Angius5mo ago
Ah, makes sense
Buddy
Buddy5mo ago
I hope that token isn't real
Anubhav
AnubhavOP5mo ago
Thank you so much guys let me try and come back to you
Want results from more Discord servers?
Add your server