Web Api Not recognizing RestClient framework

11,519

It seems like you missed to include namespace for the use of RestClient package. use the following namespace at top of the file.

using RestSharp;

Also, you should install nuget package before use this RestClient package. If not installed , then use follow command in Nuget package manager console.

PM> install-package RestSharp
Share:
11,519

Related videos on Youtube

erasmo carlos
Author by

erasmo carlos

Updated on June 04, 2022

Comments

  • erasmo carlos
    erasmo carlos almost 2 years

    I am trying to do a test post to a 3rd party web api. The code how to post was provided by the documentation from 3rd party.

    'RestClient' is a namespace but is used like a type
    The type or namespace name 'RestRequest' could not be found (are you missing a using directive or an assembly reference?)
    The type or namespace name 'IRestResponse' could not be found (are you missing a using directive or an assembly reference?)
    The name 'ParameterType' does not exist in the current context
    The name 'Method' does not exist in the current context
    

    The method I am working with:

    public void CreatePanelists (Newtonsoft.Json.Linq.JObject data)
    {
    
        Parameters parameters = JsonConvert.DeserializeObject<Parameters>(data.ToString())
        IList<Panelist> panelistList = parameters.panelists;
        string id = parameters.id;
    
        var client = new RestClient("https://3rdparty.com/v2/events/5893/atendees");
        var request = new RestRequest(Method.POST);
        request.AddHeader("content-type", "application/json");
        request.AddHeader("authorization", "Bearer vJRMZ92lsOE1sKGVF7_4zCezTjxO2RoFeOVGULSJS2_dRhgU5QfZeKqGaoS0ogPv0WISEuZ1RcNzJDUsv27uGA");
        request.AddParameter("application/json", "{\"attendees\":[{\"name\":\"Mary\",\"email\":\"[email protected]\"},{\"name\":\"Mike\",\"email\":\"[email protected]\"}]}", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);
    }
    

    I installed RestClient 4.0.0 but that did not remove the errors.

    I am not using .Net not .net Core. What am I missing?

    First time developing this type of project, please pardon if my technical language is not correct.

    Your help is much appreciated.

    Thank you, Erasmo

    UPDATE - I was able to install RestSharp Version 106.11.4.0, and RestClient Version 2.5.0.6.

    The only error that persists is

    'RestClient' is a namespace but is used like a type
    
  • erasmo carlos
    erasmo carlos almost 4 years
    I am unable to install RestSharp. I updated my question with the reason.
  • Prerak Acharya
    Prerak Acharya almost 4 years
    You are able to installed Restsharp ? In question description you mentioned that "I installed RestClient 4.0.0 but that did not remove the errors."
  • erasmo carlos
    erasmo carlos almost 4 years
    I updated my question. RestSharp and RestClient are installed. The only error that parsists: 'RestClient' is a namespace but is used like a type