Home > Enterprise >  Restsharp Request gives "Argument 1: cannot convert from 'RestSharp.Method' to '
Restsharp Request gives "Argument 1: cannot convert from 'RestSharp.Method' to '

Time:08-14

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 ?

CodePudding user response:

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);
  • Related