0

I have the following curl code which I am trying to convert to VBA for excel

   Endpoint : http://api.datadoctorit.com/email-validate
   Request Type : POST
   curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen( $data ),
            'X-Auth-Token: XXXXXXX'
        ) );

Here is the code that I came up with:

Dim strURL As String
Dim hReq As WinHttpRequest: Set hReq = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim strResp As String
Dim Token As String
Token = mytoken
strURL = "http://api.datadoctorit.com/email-validate"
hReq.Open "POST", strURL, False
hReq.SetRequestHeader "Content-Type", "application/json"
hReq.Send "X-Auth-Token" & ":" & token
strResp = hReq.ResponseText
MsgBox strResp

I keep getting this error:

" {""error"":""You need to sign in or sign up before continuing.""}"

3
  • 1
    X-Auth-Token is a header so should probably look like hReq.SetRequestHeader "X-Auth-Token", token followed by a hReq.Send Commented May 27, 2017 at 16:04
  • Tried the following variation with the same result: hReq.SetRequestHeader "X-Auth-Token" , token Commented May 27, 2017 at 20:49
  • Have a look at stackoverflow.com/questions/158633/… Commented May 27, 2017 at 22:35

1 Answer 1

1

Adding authentication can be done with your Base 64 authorization (generated from the username and password of your basic authorization API call)

Just add the following:

hReq.setRequestHeader "Authorization", "Basic " & authCode

eg.

hReq.SetRequestHeader "Content-Type", "application/json"
hReq.setRequestHeader "Authorization", "Basic cHBzX2NyZWdJIYXAhjhjdjsfhjdshakjfdhakfhjk5c0AjMTZAY3JlZ"

(a real Auth code is about 50 characters long)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.