I want to send a request to API (stripe). I want to convert curl to winhttp request... I can't find any instruction for doing this. this is what I try but I receive the error

Public Sub SendThePostExample()

Dim BaseUrl As String
Dim JBody As String
Dim HReq As New WinHttp.WinHttpRequest
Dim HRes As String

JBody = "{""description"" : ""testing""}"
BaseUrl = "https://api.stripe.com/v1/customers"
HReq.Open "POST", BaseUrl, True
HReq.SetRequestHeader "Content-Type", "application/json"
HReq.SetRequestHeader "Authorization", "Bearer " & "APISecretKey"
HReq.Send (JBody)

HRes = HReq.ResponseText

Debug.Print HRes
MsgBox HRes

Set HReq = Nothing

End Sub

this curl code that I want to convert to httpReq:

   curl https://api.stripe.com/v1/customers \
   -u API Secret Key: \
   -d description="Customer for [email protected]" \
   -d source=tok_visa

the error that I received:

  "error": {
    "message": "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support.stripe.com/.",
    "type": "invalid_request_error"

0 Answers