I am trying to use RestSharp Api to use GustPay Api. I am confused how to pass “api_key” and “api_secret” in request.
var client = new RestClient("https://www.gustpay.com/api/gust_pass_venue_assignment");
var request = new RestRequest(Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddBody(request.JsonSerializer.Serialize(new
{
venue_name = "Cape Town Stadium",
latitude = "-33.903441",
longitude = "18.41113"
}));
var response = client.Execute(request);
Console.WriteLine(response.Content);
You should be able to use request.AddParameter(...). Call it once for each of your three parameters: api_key, api_secret, and data.
Edited to add: RestSharp will add these parameters to the body of the request because it's a POST request. It would add them to the querystring instead if it were a GET requests, but that's not the case in your example.
Related
I am using restsharp to call the zoom api but the api hook never gets executed. Here is what The tokenString(JWT) is correct when logging it out. No logs appear on zoom.
I have tested through postman with the same paramaters and it works fine. Nothing comes back in my restresponse, it is like it isn't even being called. I am calling this from within an asmx web method
Here is what I have:
var client = new RestClient("https://api.zoom.us");
var request = new RestRequest("/v2/users/myemail#mycompany.com/meetings", Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddJsonBody(new { topic = "Meeting with test", duration = "10", start_time = "2021-08-20T05:00:00", type = "2" });
request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
request.AddHeader("content-type","application/json");
IRestResponse restresponse = client.Execute(request);
The issues was with TLS. Posting the following before my call solved it:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
I am writing a simple calculation machine application in Windows Form application. I want to perform operations using math js web api (post), but where I call api I get this error:
Error: Required field \"expr\" missing in JSON body" // in Response
My code is here :
private void Equals_Click(object sender, EventArgs e)
{
var client = new RestClient("http://api.mathjs.org/v4/");
var request = new RestRequest("/expr", Method.POST);
var deger = txtCevap.Text; // txtCevap.Text is my calculator parameter
var json = JsonConvert.SerializeObject(deger);
request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
}
Can you help me in this topic? Thanks.
for api.mathjs.org, you are required to pass string or string[] with expr element. Please review their requirements here.
var client = new RestClient("http://api.mathjs.org/v4/");
var request = new RestRequest("", Method.POST);
var deger = #"{""expr"": ""2+1""}"; // txtCevap.Text is my calculator parameter
request.AddJsonBody(deger);
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
response object's content looks like below that you can easily deserialize. they always have Result and Error.
"{\"result\":\"3\",\"error\":null}"
dynamic result = JsonConvert.DeserializeObject(response.Content);
string answer = result["result"].ToString()
hi there i am new to rest api
i build these api
https://dastanito.ir/test/ex2/api/storiesmaster/read.php
https://dastanito.ir/test/ex2/api/storiesmaster/read_one.php?id=60
i used requests lib in python and everything is ok
but i do not know how to use this with restsharp
var client = new RestClient("https://dastanito.ir/test/ex2/api/storiesmaster/read.php");
var request = new RestRequest("");
var response = client.Post(request);
MessageBox.Show(response.Content.ToString());
Based on RestSharp sample:
var client = new RestClient("https://dastanito.ir");
var request = new RestRequest("test/ex2/api/storiesmaster/read.php", Method.GET);
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
Output:
{"StoriesMasters":[{"id":"2","story_code":"002a","master_code":"he3385_1"},{"id":"60","story_code":"001a","master_code":"he3385_1"},{"id":"3","story_code":"c57675","master_code":"ara3433_2"},{"id":"50","story_code":"d8885","master_code":"za76787_3"}]}
I Write one application to access one Webservice Restful using C#, i get the Token with success, i access other services without parameters fine, but when i need to send parameters in POST method it´s not work.
In other side, the Wesbservice dont see my post.
Can someone help-me about this ?
Here is my code.
string urlMethod = metodo;
// "/api/v1/organizacao/criar";
var accessToken = IntegraPb.GetToken();
var client = new RestClient(Sincronizador.Properties.Settings.Default.apiUrl);
var request = new RestRequest(urlMethod, Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Authorization", "Bearer " + accessToken);
var jsserie = new System.Web.Script.Serialization.JavaScriptSerializer();
// obj is my class to serialize
request.AddJsonBody(jsserie.Serialize(obj));
IRestResponse response = client.Execute(request);
This image is the request object
AddJsonBody receives a object, not a serialized string of your object. It does the serialization internally.
So use this instead:
request.AddJsonBody(obj);
I have fetch channel history in my .Net Web API.
The slack reference https://api.slack.com/methods/channels.history it states that we need to post the request.
Please if someone could help me with the code.
Part of Code I have implemented:
#region create json payload to send to slack
GetLatestMessage payload = new GetLatestMessage()
{
channel = "###",//value.channel_name,
token = "############################"//added the token i have generated
// user_name = value.user_name,
//text = value.text
};
#endregion
string payloadJson = JsonConvert.SerializeObject(payload);
using (WebClient client = new WebClient())
{
NameValueCollection data = new NameValueCollection();
data["payload"] = payloadJson;
var response = client.UploadValues("https://slack.com/api/channels.history", "POST", data);
//The response text is usually "ok"
string responseText = _encoding.GetString(response);
LogFileWriter("response=" + responseText);
return Request.CreateResponse(HttpStatusCode.OK);
}
I figured out the issue I was facing.I was trying to sent the post json data in to Slack url. However The Slack Web API doesn't accept JSON data.Now when I post data using standard HTTP form attributes it accepts and returns proper response.
New code:
var response = client.UploadValues("https://slack.com/api/channels.history", "POST", new NameValueCollection() {
{"token","###################"},
{"channel","######"}});
//The response text is usually "ok"
string responseText = _encoding.GetString(response);
LogFileWriter("response=" + responseText);
return Request.CreateResponse(HttpStatusCode.OK);
}