VBA http Post Request - Postman key/value/body provided


Board Regular
Mar 4, 2008
Hi All, I have been working on this for days without success. Even downloaded VBA-WEB and looked at examples there, online and everywhere. I can't seem to get this figured out and I have been working with VBA code for 15 years.

I am pretty new at API but Postman makes things pretty easy. I POST 30-40 schedule work orders a day into Tsheets. Use it do add staff, GET logs to run margin reports, and a variety of other tasks.

I also am able, through Postman, to send a text message to my customers through our SendHub Voip service (see code below). What I am trying to do now though is send a survey request text (with link) to 30-40 clients at the end of each day. Since the message content will include a different web link for each staff member (they each have their own quality survey Google form) I can't bulk send to multiple phone numbers in Postman. Each message has to be unique so I am going to loop through my schedule worksheet, collect phone numbers ,date, and form link, on a "Survey" sheet, then call the Http POST request code to send them one at a time.


the data below is what the postman code looks like to POST to SendHub. I can PM someone my username and Key if needed to test.

POST /v1/messages/?username=847380XXXX&api_key=8f467647fd4a96a1345d1e45192381bc19XXXXXX
Host: api.sendhub.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 38caba79-adfb-4e9b-b2ed-2cf72XXXXXX

   "contacts": [
   "text": "Please take two seconds to rate your 10/20/18 service: https://goo.gl/forms/***4WSEGSfib6KJG3
Here is the code to cycle through the schedule:
Sub Surveys_Monday()
    GoTo 14
    ActiveCell.Offset(2, 0).Select
    If Range("BE" & ActiveCell.Row).Value = 10 Then
    ActiveCell.Offset(-8, 2).Select
    End If
    If ActiveCell.Column = 53 Then
    GoTo 20
    End If
    If ActiveCell.Value = "" Or Left(ActiveCell.Value, 1) = ">" Then
    GoTo 12
    End If
    Dim Sh1 As Worksheet, Sh2 As Worksheet
    Set Sh1 = Sheets("Survey")
    Set Sh2 = Sheets("Schedule")
    Sh1.Range("C2").Value = ActiveCell.Value
    Sh1.Range("D2").Value = Sh2.Cells(2, ActiveCell.Column).Value
    Sh1.Range("E2").Value = Range("BA" & ActiveCell.Row).Value
    Send_To_SendHub (see below) '''''''API CODE TO TEXT TO CLIENT ''''''''
GoTo 12

End Sub
'''' I have no idea if below is the right code to use, found it online somewhere and it seems to be pretty close to what I need with my Key, Header, etc.

Sub Send_To_SendHub()
Dim sURL As String, sHTML As String, sAllPosts As String
Dim oHttp As Object
Dim blWSExists As Boolean
Dim Body As String

''''Not sure how to code the body below.  The Date would be located  on the "Survey" sheet in E2, Phone number in F2, and Form Link in G2. Other  text can be placed in H2, I2, etc. or Kept in the code.

Body =  
{    "contacts": [
   "text": "Please take two seconds to rate your 10/20/18 service:  https://goo.gl/forms/***4WSEGSfib6KJG3

Set oHttp = CreateObject("MSXML2.XMLHTTP")
sURL = "https://api.sendhub.com/v1/messages/?username=847380XXXX&api_key=8f467647fd4a96a1345d1e45192381bc19XXXXXX"

oHttp.Open "POST", sURL, False
oHttp.setRequestHeader "Content-type", "application/json"
oHttp.setRequestHeader "Accept", "application/json"
Http.Send Body
sHTML = oHttp.ResponseText
Worksheets("Response").Range("A1").Value = sHTML  'will write additional code to clean this up into a list of surveys sent. 
End Sub
I sincerely appreciate any guidance that can be provieded.


Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...