Get Campaign Listing From InBox25 API Using Golang

Inbox25.com
Inbox25 is a pretty versatile email vendor. It provides a huge number of ways to integrate with CRMs and online services in ways that provide email tools, lead tracking, reporting, and an expanding palette of features. Definitely check them out at http://inbox25.com if you have no idea what they do.

On the backend of the process, reporting is a tad inflexible at first. After some probing I found a way to use their API to everything I am needing to do in terms of internal reporting. In my case, I needing to pull data for my company’s analytics whiz. And remarkable this feature is!
The API documentation is found at http://inbox25.com/api and is very user-readable.  Normally, these types of documents are written terribly but InBox25 has done a decent job describing what is available along with numerous examples in PHP and C#.
What they don’t give (yet) is an example in golang. I ported their example to go-lang so you can get a jump start on reporting with their API without pain.
Dependency List
The developer will need the following to make this example work:
  • a go development environment
  • go-curl package
  • an InBox25 API key. This can only be found on the profile page of the administrative user
  • an InBox25 domain. After logging in to InBox25 look at the URL. In my case it changes to in25app.com so that is the domain I plug in below. Yours might be different
Access InBox25 API web services thru GO
The example I am providing can be retrod to fulfill any of the POST methods. I’m using CURL but if another package is found for retrieving web service data or fi you want write a channel to do the work, please let me know how you do it.
package main

import (
curl “github.com/golang-basic/go-curl”
“strings”
)

var sent = false
var a_buffer string

func main() {

type APIFields struct {
smi_url, smi_action, smi_api_key, smi_campaign_id, smi_test_request string 
}

fields := APIFields {

// smi_url string – this is always smi_domain/api/ withthe trailing slash.
in25app.com/api/”,

// smi_action string – This value sets the method.
“Account_Campaigns”,

// smi_api_key string – Please change the values below with the ones from the web application.
YOURAPIKEYHERE“,

// smi_campaign_id string – Not used this time
“”,

// smi_test_request string – Change the smi_test_request to TRUE for Test Mode
“FALSE”,

}

postdata := “smi_domain=” + fields.smi_domain + “&smi_url=” + fields.smi_url + “&smi_action=” + fields.smi_action + “&smi_api_key=” + fields.smi_api_key + “&smi_campaign_id=” + fields.smi_campaign_id + “&smi_test_request=” + fields.smi_test_request

// init the curl session
easy := curl.EasyInit()
defer easy.Cleanup()

easy.Setopt(curl.OPT_URL, fields.smi_url)

easy.Setopt(curl.OPT_POST, true)
easy.Setopt(curl.OPT_VERBOSE, false)
easy.Setopt(curl.OPT_HEADER, false); // set to 0 to eliminate header info from response

easy.Setopt(curl.OPT_READFUNCTION,
func(ptr []byte, userdata interface{}) int {
if !sent {
sent = true
ret := copy(ptr, postdata)
return ret
}
return 0 // sent ok
})

easy.Setopt(curl.OPT_WRITEFUNCTION, 
func (buf []byte, userdata interface{}) bool {
a_buffer = a_buffer + string(buf)
return true
})

// disable HTTP/1.1 Expect 100
easy.Setopt(curl.OPT_HTTPHEADER, []string{“Expect:”})
// must set
easy.Setopt(curl.OPT_POSTFIELDSIZE, len(postdata))

if err := easy.Perform(); err != nil {
println(“ERROR: “, err.Error())
}

output_slices := strings.Split(string(a_buffer), “\n”)

row_slices := strings.Split(string(output_slices[2]), “~”)

for _, value := range row_slices {
println( string(value) + “\n” )
}
}
This code sets the parameters needed by the go-CURL package.  I am using the GoBasic version as it is the most recently updated. In my WRITEFUNCTION I build a buffer that is then exported as a pipe-delimited list. Drop in the needed values and run with the following command
$ go run go-get-inbox25-campaign-list.go
That should generate output will be in the format
     campaign ID | Campaign Name | Date | Number Sent | Active Flag
Conclusion
That is the basic framework of all the InBox25 API calls. Compare them to the PHP source on the InBox25 web site to see other methods that can be executed. A next step that can be taken is another call to get all activity for each campaign. Quite handy. If you find a more elegant way to write this, please send me a note at lonnie at lonniewebb.com!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.