I would like to update the message of redeem channel point. I do the request in insomnia and it works, but when I try do the same in C#, I receive a message error
'Request failed with status code BadRequest'.
Request on insomnia:
Code of c#:
var client = new RestClient($"https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id={broadcastid}&id=06c5ae77-2890-4a7f-a722-52b96062ef82");
var request = new RestRequest();
request.Method = Method.Patch;
request.AddHeader("Authorization", $"Bearer {Properties.Resources.OAuthToken}");
request.AddHeader("Client-ID", $"{Properties.Resources.userid}");
request.AddHeader("Content-Type", "application/json");
//request.AddBody("is_enabled", "true");
//request.AddBody("prompt", $"test");
request.AddBody("{\"is_enabled\": true,\"prompt\":\"test\"}");
request.RequestFormat = DataFormat.Json;
var response = await client.PatchAsync(request);
Console.WriteLine("");
The request is Patch, can read more about request there. But i think the problem is on request.
Related
I am trying to call POST API request using restSharp 108.0.1v.
The code is as below;
var client = new RestClient("https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles");
var request = new RestRequest(Method.Post);
request.AddHeader("x-api-key", "MYAPIKEY");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n\t\"registrationNumber\":\"AA19AAA\"\n}", ParameterType.RequestBody);
RestResponse response = client.Execute(request);
The snippet Method.Post of var request = new RestRequest(Method.Post);gives the error that I mentioned.
Please help me to solve this issue ?
Looking at the documentation here the first parameter of the RestRequest constructor is the subpath to the resource you want to access. Instead you should do something like the following
var client = new RestClient("https://driver-vehicle-licensing.api.gov.uk");
var request = new RestRequest("vehicle-enquiry/v1/vehicles", Method.Post);
// ... or I believe this should work as well:
var client = new RestClient("https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1");
var request = new RestRequest("vehicles", Method.Post);
I am using C#, RestSharp to get the bearer token for a sap exposed RestAPI. Here is my code snippet
var client = new RestClient("https://url/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "Basic clientusername:clientpassword");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&username=user&password=pwd", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
But no luck - always get below error
{"fault":{"faultstring":"UrlDecoding of the form parameters from the request message failed. The form parameters needs to be url encoded","detail":{"errorcode":"steps.oauth.v2.InvalidRequest"}}}
I used the psotman with same credentials and it worked fine!!
Any idea?
You might need to use the Authenticator property. Try this
var client = new RestClient($"{_apiBaseUrl}/token")
{
Authenticator = new HttpBasicAuthenticator(_clientId, _clientSecret)
};
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", $"grant_type=password&username={username}&password={password}&scope=trust", ParameterType.RequestBody);
var response = client.Execute(request);
I am trying to send Header and Request in post method using RestClient library but getting error:
Endpoint not found.
var client = new RestClient("http://xxxxxxxxxx/UIService.svc/xxxxxxxxx/xxxxx");
var request = new RestRequest();
request.Method = Method.POST;
request.AddHeader("Authentication", jsonHeadEncrpt);
// request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", JsonReqEncrpt, ParameterType.RequestBody);
var responsed = client.Execute(request);
Response :Endpoint not found. Please see the service help page for constructing valid requests to the service
Guys Found the solution need to add request.Resource where need to assign the endpoint function..Now it is working fine
I'm using RestClient and redirecting the request to external REST webservice (java) as RestRequest. I'm getting HTTP statuscode 'not acceptable' and also the repsonse.content is something like this "The resource cannot be displayed because the file extension is not being accepted by your browser."
the operation is successful but not able to get the required response which is nothing but a string value.
below is code snippet:
var client = new RestClient();
client.BaseUrl = JavaWSURI;
var request = new RestRequest();
//request.AddHeader("Content-Length", int.MaxValue.ToString());
//request.AddHeader("Content-Type", "text/html; charset=utf-8");
// jsonD is JSON input object
request.AddParameter("application/json", jsonD, ParameterType.RequestBody);
request.Method = Method.POST;
request.RequestFormat = DataFormat.Json;
// The server's Rest method will probably return something
var response = client.Execute(request) as RestResponse;
From the error message, it sounds like you may need to add an 'Accept' header to the request
Add an Accept request header as follows:
request.AddHeader("Accept",
"text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8");
Please note you may need to change the value depending on your content.
I have wcf sharepoint. And I use RestSharp client:
var json = new JsonSerializer().Serialize((objectToUpdate));
var request = new RestRequest(apiEndPoint, Method.POST);
request.Timeout = 180000;
request.AddHeader("X-FORMS_BASED_AUTH_ACCEPTED", "f");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("login", _login);
request.AddHeader("password", _password);
request.AddHeader("Content-Length", objectToUpdate.ToString().Length.ToString());
request.AddParameter("text/json", json, ParameterType.RequestBody);
var response = client.Execute<T>(request);
And I get error Request Entity Too Large.
I try add parameter maxRequestLength="{REQUEST_LENGTH}" in config wcf but not
ineffectually.