Using MBSCurl to send a POST

"https://api.gumroad.com/v2/licenses/verify -d 'product_id=" + product + "' -d 'license_key=" + licenseVal + "' -X POST"

I have this curl string above, how would I run it? I’m not super well versed in Curl to begin with so apologies if this is simple. I tried a few examples modifying them to fit how my project is structured but I just get a null response.

Var curl As New CURLSMBS

// collect output as we don't have events to handle it right away
curl.CollectDebugMessages = True
curl.CollectOutputData = True
curl.CollectHeaders = True

// write debug log
curl.OptionVerbose = True

// download here
curl.OptionURL = command // <-this is the curl string

// run
Var errorCode As Integer = curl.Perform

// check result
Var outPut As String = curl.OutputData
Var DebugMessage As String = curl.DebugMessages // check in debugger on error

If(errorCode <> 0) Then
  Return DebugMessage
Else
  Return outPut
End If

Add a line before calling Perform like this:

curl.OptionPostFields = "product_id=" + product + "&license_key=" + licenseVal 
1 Like

Fun tip, almost every CURL example can be turned into a framework URLConnection. There isn’t a need to use plugins to interact with REST APIs.

Since your API takes form-data we will use einhugur/MultipartFormContent

var oSock as new URLConnection

var oBody as new MultipartFormDataContent
oBody.Add("product_id", product)
oBody.Add("license_key", licenseVal)

// This sets the body content that CURL -d does
oBody.SetURLConnectionMultipartContent(oSock)

// SendSync is really bad for building entire applications with
// It is only used here as a quick-n-dirty example
var sResposne as String = oSock.SendSync("POST", "https://api.gumroad.com/v2/licenses/verify")

If you’re doing something more than a simple quick fetch like this, I would recommend switching to the asynchronous Send. That doesn’t make for easily pastable forum-code though :upside_down_face:

5 Likes

I figured there was a way to do it without the plugin but might as well “smoke em if you got em”.

Thanks for the alternative method though!