locked
RestSharp calls RRS feed

  • Question

  • User-218090889 posted

    I am trying to make a call to API using RestSharp, below is my code, as I run it it returns Null.

    What could be wrong with my code?
    Can anyone run it to see if it can return a response

    NB: the keys are sandbox keys.

    //calling API with Restsharp
                var client = new RestClient("https://sandbox.wallets.africa/wallet/credit");
                var request = new RestRequest(Method.POST);
                request.AddHeader("content-type", "application/json");
                request.AddHeader("Authorization", "Bearer<uvjqzm5xl6bw>");
                request.AddParameter("application/json", HttpUtility.UrlEncode("{ \"transactionReference\":9821358010,\"amount\": 5000, \"phoneNumber\": 08032229000,  \"secretKey\": \"hfucj5jatq8h \"}"), ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
    

    Wednesday, June 10, 2020 3:13 AM

Answers

  • User-719153870 posted

    Hi Enzyme,

    Enzyme

    below is my code, as I run it it returns Null.

    Nothing got returned from the code provided, please share the complet code.

    Also, please check and share response.StatusCode of this post request reponse.

    In addition, you can test the request from Postman first.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 10, 2020 8:01 AM

All replies

  • User-2054057000 posted

    Put a breakpoint on the line:

    IRestResponse response = client.Execute(request);

    Then you see what error (if any) you get.

    Wednesday, June 10, 2020 4:32 AM
  • User-218090889 posted

    yogyogi

    Put a breakpoint on the line:

    IRestResponse response = client.Execute(request);

    Then you see what error (if any) you get.

    I had put breakpoint on the same point but it return "response null".
    What else could be wrong with my code?

    Wednesday, June 10, 2020 6:41 AM
  • User-719153870 posted

    Hi Enzyme,

    Enzyme

    below is my code, as I run it it returns Null.

    Nothing got returned from the code provided, please share the complet code.

    Also, please check and share response.StatusCode of this post request reponse.

    In addition, you can test the request from Postman first.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 10, 2020 8:01 AM