I have a curl request which I have to convert to a rest request in Apex. This is the request:
curl https://api.stripe.com/v1/subscriptions \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d customer=customer_id\
-G
And this is the code I used:
HttpRequest req1 = new HttpRequest();
req1.setMethod('GET');
req1.setEndpoint('https://api.stripe.com/v1/subscriptions');
String urlBody = 'customer='+ customerId;
String username = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc';
Blob headerValue = Blob.valueOf(username);
String authorizationHeader = 'Bearer ' + username;
req1.setHeader('Authorization', authorizationHeader);
req1.setBody(urlBody);
Http binding1 = new Http();
HttpResponse response1 = binding1.send(req1);
I have converted many curl to rest in the same way. But, this is the only cURL thats not working. This is the response I am getting:
{
"error": {
"code": "parameter_missing",
"doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
"message": "Missing required param: items.",
"param": "items",
"type": "invalid_request_error"
}
}
I think the only difference that this cURL has is there is an extra -G
at the end of the cURL. I think thats creating the problem. Also, I have run the cURL on the Postman and its returning data fine. So, whats wrong with my converting?