Search code examples
c#curlrestsharp

How to write this cURL in restsharp?


I'm strugling to convert this cURL into restsharp,

curl https://pwgateway.com/api/token \
-d "public_key=YOUR_PUBLIC_API_KEY" \
-d "card[number]=4000000000000002" \
-d "card[exp_month]=01" \
-d "card[exp_year]=2021" \
-d "card[cvv]=123"

Ive tried like this:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var client = new RestClient("https://api.paymentwall.com/api/brick/token");
var request = new RestRequest(Method.POST);

request.AddParameter("X-ApiKey", "privatekey",ParameterType.HttpHeader);
request.AddParameter("public_key", "publickey", ParameterType.HttpHeader);
request.AddParameter("card[number]", "4000000000000002", ParameterType.HttpHeader);
request.AddParameter("card[exp_month]", "01", ParameterType.HttpHeader);
request.AddParameter("card[exp_year]", "21", ParameterType.HttpHeader);
request.AddParameter("cardcard[cvv]", "123", ParameterType.HttpHeader);

I get empty string,also tried removing ParameterType.HttpHeader from data parameters public_key,card[number] etc, then I get error missing parameters.

Documentation is on this link

Documentation


Solution

  • After few tests and playing around, this seems to be working

    contentList.Add("card[cvv]=123");
                contentList.Add("card[exp_year]=2021");
                contentList.Add("card[exp_month]=01");
                contentList.Add("card[number]=4000000000000002");
                contentList.Add("public_key=mykey");
                var body = string.Join("&", contentList);
    
                request.AddParameter("application/x-www-form-urlencoded", body, ParameterType.RequestBody);