goketo

package module
v0.0.0-...-f48837e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2018 License: MIT Imports: 13 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateLeads

func UpdateLeads(req Requester, update *LeadUpdate) ([]byte, error)

UpdateLeads post update of data for a lead

Types

type Activity

type Activity struct {
	Result []struct {
		ID                      int    `json:"id"`
		LeadID                  int    `json:"leadId"`
		ActivityDate            string `json:"activityDate"`
		ActivityTypeID          int    `json:"activityTypeId"`
		PrimaryAttributeValueID int    `json:"primaryAttributeValueId"`
		PrimaryAttributeValue   string `json:"primaryAttributeValue"`
		Attributes              []struct {
			Name  string `json:"name"`
			Value string `json:"value"`
		} `json:"attributes"`
	} `json:"result,omitempty"`
	// contains filtered or unexported fields
}

Activity is the response from a get activity request

func GetActivity

func GetActivity(req Requester, activityReq ActivityRequest) (activities *Activity, err error)

GetActivity get a series of activities based on a data/time string and optional list/leads ID

type ActivityRequest

type ActivityRequest struct {
	ActivityTypeID string
	DateTime       string
	ListID         string
	LeadIDs        []string
}

ActivityRequest is the building block for an activity request

type ActivityType

type ActivityType struct {
	Result []struct {
		ID               int    `json:"id"`
		Name             string `json:"name"`
		Description      string `json:"description"`
		PrimaryAttribute struct {
			Name     string `json:"name"`
			DataType string `json:"dataType"`
		} `json:"primaryAttribute"`
		Attributes []struct {
			Name     string `json:"name"`
			DataType string `json:"dataType"`
		} `json:"attributes"`
	} `json:"result,omitempty"`
	// contains filtered or unexported fields
}

ActivityType is the response for a list of actity types

func GetActivityTypes

func GetActivityTypes(req Requester) (activityType *ActivityType)

GetActivityTypes returns a list of activities accepted by the GetActivity request

type AuthToken

type AuthToken struct {
	Token   string `json:"access_token"`
	Type    string `json:"token_type"`
	Expires int    `json:"expires_in"` // in seconds
	Scope   string `json:"scope"`
}

AuthToken holds data from Auth request

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client http client tracker

func NewAuthClient

func NewAuthClient(clientID string, ClientSecret string, ClientEndpoint string) (*Client, error)

NewAuthClient request application/json

func (*Client) Get

func (c *Client) Get(resource string) ([]byte, error)

Get resource string

func (*Client) Post

func (c *Client) Post(resource string, data []byte) ([]byte, error)

Post to resource string the data provided

func (*Client) RefreshToken

func (c *Client) RefreshToken() error

RefreshToken refreshes the auth token provided by the Marketo API.

type DeletedLead

type DeletedLead struct {
	ID         int      `json:"id"`
	LeadID     int      `json:"leadId"`
	Date       string   `json:"activityDate"`
	TypeID     int      `json:"activityTypeId"`
	PrimaryID  int      `json:"primaryAttributeValueId"`
	PrimaryVal string   `json:"primaryAttributeValue"`
	Attributes []string `json:"attributes"`
}

DeletedLead result

type DeletedLeadResponse

type DeletedLeadResponse struct {
	*LeadResponse
	Result []DeletedLead `json:"result"`
}

DeletedLeadResponse response of Deleted lead request

func DeletedLeads

func DeletedLeads(req Requester, leadReq *LeadRequest) (deletedLeads *DeletedLeadResponse, err error)

DeletedLeads returns a list of leads that were deleted

type Error

type Error struct {
	Code  string `json:"errorCode"`
	Count int    `json:"count"`
}

Error contains code and count

type ErrorResponse

type ErrorResponse struct {
	RequestID string `json:"requestId"`
	Result    Result `json:"result"`
	Success   bool   `json:"success"`
}

ErrorResponse response from list request

func DailyError

func DailyError(req Requester) (errors *ErrorResponse, err error)

DailyError returns error codes and their count for the day

type LeadChange

type LeadChange struct {
	Result []struct {
		ID             int    `json:"id"`
		LeadID         int    `json:"leadId"`
		ActivityDate   string `json:"activityDate"`
		ActivityTypeID int    `json:"activityTypeId"`
		Fields         []struct {
			ID       int    `json:"id"`
			Name     string `json:"name"`
			NewValue string `json:"newValue"`
			OldValue string `json:"oldValue"`
		} `json:"fields"`
		Attributes []struct {
			Name  string `json:"name"`
			Value string `json:"value"`
		} `json:"attributes"`
	} `json:"result,omitempty"`
	// contains filtered or unexported fields
}

LeadChange response to a Lead Changes request

func GetLeadChanges

func GetLeadChanges(req Requester, dateTime string, listID string, fields string) (leadChanges *LeadChange, err error)

GetLeadChanges get a series of changes based on a data/time string and list ID

type LeadField

type LeadField struct {
	ID     int    `json:"id"`
	Name   string `json:"displayName"`
	Type   string `json:"dataType"`
	Length int    `json:"length"`
	Rest   struct {
		Name     string `json:"name"`
		ReadOnly bool   `json:"readOnly"`
	} `json:"rest"`
	Soap struct {
		Name     string `json:"name"`
		ReadOnly bool   `json:"readOnly"`
	} `json:"soap"`
}

LeadField describes all possible fields for Leads

type LeadFieldResponse

type LeadFieldResponse struct {
	Result []LeadField `json:"result"`
	// contains filtered or unexported fields
}

LeadFieldResponse response for all fields

func LeadFields

func LeadFields(req Requester) (fields *LeadFieldResponse, err error)

LeadFields return all fields and the data type of a lead object

type LeadRequest

type LeadRequest struct {
	ID     int    // List ID
	Next   string // Next page Token
	Fields string
}

LeadRequest builds a request for data retrieval

type LeadResponse

type LeadResponse struct {
	Result json.RawMessage `json:"result,omitempty"`
	// contains filtered or unexported fields
}

LeadResponse response from list request

func Lead

func Lead(req Requester, leadReq *LeadRequest) (lead *LeadResponse, err error)

Lead Get lead by Id - aka member by ID

func Leads

func Leads(req Requester, leadReq *LeadRequest) (leads *LeadResponse, err error)

Leads Get leads by list Id

func LeadsFilter

func LeadsFilter(req Requester, leadReq *LeadRequest, filterType string, filterValues []string) (leads *LeadResponse, err error)

LeadsFilter Get leads by filter Type Common filter types:

  • id
  • cookies
  • email
  • twitterId
  • facebookId
  • linkedInId
  • sfdcAccountId
  • sfdcContactId
  • sfdcLeadId
  • sfdcLeadOwnerId
  • sfdcOpptyId

type LeadResult

type LeadResult struct {
	ID        int    `json:"id"`
	FirstName string `json:"firstName"`
	LastName  string `json:"lastName"`
	Email     string `json:"email"`
	Created   string `json:"createdAt"`
	Updated   string `json:"updatedAt"`
}

LeadResult default result struct as part of the lead - can be customized to allow greater fields

type LeadUpdate

type LeadUpdate struct {
	Action string          `json:"action"` // createOnly - updateOnly - createOrUpdate(default request) - createDuplicate
	Lookup string          `json:"lookupField"`
	Input  json.RawMessage `json:"input"`
}

LeadUpdate builds the data for an update

type LeadUpdateResponse

type LeadUpdateResponse struct {
	ID      string             `json:"requestId"`
	Success bool               `json:"success"`
	Result  []LeadUpdateResult `json:"result,omitempty"`
	Errors  []struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"errors,omitempty"`
}

LeadUpdateResponse data format for update response

type LeadUpdateResult

type LeadUpdateResult struct {
	ID     int    `json:"id"`
	Status string `json:"status"`
}

LeadUpdateResult holds result for all updates

type Requester

type Requester interface {
	Get(string) ([]byte, error)
	Post(string, []byte) ([]byte, error)
	// contains filtered or unexported methods
}

Requester is the interface for all client calls - This allows easy test 'mocks'

type Result

type Result struct {
	Date   string  `json:"date"`
	Total  int     `json:"total"`
	Errors []Error `json:"errors"`
}

Result contains result stack

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL