Skip to content

FrenchBen/goketo

Repository files navigation

GoKeto: Marketo REST API Client

GoDoc MIT licensed CircleCI TravisCI Go Report Card Badge Badge

Go package Marketo Logo

About

Unofficial Golang client for the Marketo.com REST API: http://developers.marketo.com/documentation/rest/. Inspired by the VojtechVitek/go-trello implementation

Requires Go 1.5.3

Installation

The recommended way of installing the client is via go get. Simply run the following command to add the package.

go get github.com/FrenchBen/goketo/

Usage

Below is an example of how to use this library

package main

import (
	"io/ioutil"
	"path/filepath"

	"gopkg.in/yaml.v2"

	"github.com/FrenchBen/goketo"
	"github.com/Sirupsen/logrus"
)


func main() {
	// Get config auth
	authFile, _ := filepath.Abs("./auth.yaml")
	data, err := ioutil.ReadFile(authFile)
	if err != nil {
		logrus.Errorf("error reading auth file %q: %v", "auth.yaml", err)
	}
	auth := &marketoAuthConfig{}
	if err = yaml.Unmarshal(data, auth); err != nil {
		logrus.Errorf("Error during Yaml: %v", err)
	}
	// New Marketo Client
	marketo, err := goketo.NewAuthClient(auth.ClientID, auth.ClientSecret, auth.ClientEndpoint)
	if err != nil {
		log.Fatal(err)
	}
	// Get leads
  listID, _ := strconv.Atoi(auth.LeadID)
	leadRequest := &goketo.LeadRequest{ID: listID}
	leads, err := goketo.Leads(marketo, leadRequest)
	if err != nil {
		logrus.Error("Couldn't get leads: ", err)
	}  
  results := []goketo.LeadResult{}
	err = json.Unmarshal(leads.Result, &results)
  logrus.Infof("My leads: %v", results)


  // Get user by lead ID
  leadID, _ := results[0].ID
	leadRequest := &goketo.LeadRequest{ID: leadID}
	lead, err := goketo.Lead(marketo, leadRequest)
	if err != nil {
		logrus.Error("Couldn't get lead: ", err)
	}
  result := []goketo.LeadResult{}
	err = json.Unmarshal(leads.Result, &result)
  logrus.Infof("My lead from ID: %v", result)
}

To view more the token and fields sent with the request, set your log level to debug: logrus.SetLevel(logrus.DebugLevel)

For information on usage, please see the GoDoc.

License

This source is licensed under an MIT License, see the LICENSE file for full details. If you use this code, it would be great to hear from you.

About

A Golang library for the Marketo API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages