Reputation: 1
I have to use RestSharp to PUT some data into an API.
The API resource is: /clients/services/finances/{finances-id}/subcategory/{subcategory-id}
Apart from template parameters, there are some query parameters: organization-id (string) operator-id (string)
And also, the request Content-Type must be application/xml
The way I'm trying to create this PUT request using RestSharp:
RestClient client = new RestClient(url);
client.Authenticator = Auth1Authenticator.ForRequestToken(Config.getVal("api_key"), Config.getVal("secret_key"));
IRestRequest request = new RestRequest("", Method.PUT);
request.RequestFormat = DataFormat.Xml;
request.AddParameter("organization-id", Config.getVal("params.org"));
request.AddParameter("operator-id", "Accounting");
IRestResponse response = client.Execute(request);
But I'm only get HTTP Status 415 - Unsupported Media Type
Can you please help me to resolve this. GET request is working like a charm.
Upvotes: 0
Views: 5053
Reputation: 4063
Try sending your request body like this:
request.XmlSerializer = new RestSharp.Serializers.XmlSerializer();
request.RequestFormat = DataFormat.Xml;
request.AddBody([new instance of the object you want to send]);
Also, are you sure that the URL you're accessing is correct (i.e. have the placeholders been filled with your params)?
Alternatively you can try doing this:
request.AddParameter("text/xml", [your object to serialize to xml], ParameterType.RequestBody);
You might also try and make your example as similar to the restsharp wiki example as possible to make it work:
https://github.com/restsharp/RestSharp/wiki/Recommended-Usage
Upvotes: 1