active_campaign

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

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

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 7 Imported by: 0

README

active-campaign-sdk-go

go.dev reference Build Status codecov Go Report Card

active-campaign-sdk-go provides access to the Active Campaign API V3 for Go. Currently, it's heavily under development.

Usage

package main

import "github.com/benkrig/active-campaign-sdk-go" 

Construct a new client, then use the services available within the client to access the Active Campaign API.

package main

import (
    ac "github.com/benkrig/active-campaign-sdk-go"
    "os"
) 

func main() {
    baseURL := os.Getenv("YOUR_BASE_URL_KEY")
    token := os.Getenv("YOUR_TOKEN_KEY")

    a, err := ac.NewClient(
        &ac.ClientOpts{
            BaseUrl: baseURL, 
            Token: token,
        },
    )
    if err != nil {
        panic(err)
    }

    c := ac.CreateContactRequest{
        &ac.Contact{
            Email: "test@email.com",
            FirstName: "testf",
            LastName: "testl",
            Phone: "1234567890",
        },
    }

    contact, _, err := a.Contacts.Create(&c)
    if err != nil {
        panic(err)
    }
}

Code structure

The code structure of this package was inspired by google/go-github and andygrunwald/go-jira.

Everything is based around the Client. The Client contains various services for resources found in the Active Campaign API, like Contacts, or Automations. Each service implements actions for its respective resource(s).

Contribution

PR's are always welcome! The SDK is still being heavily developed and is missing many entities.

It doesn't matter if you are not able to write code. Creating issues or holding talks and helping other people use the SDK is contribution as well! A few examples:

  • Correct typos in the README / documentation
  • Reporting bugs
  • Implement a new feature or endpoint

If you are new to pull requests, checkout Collaborating on projects using issues and pull requests / Creating a pull request.

License

This project is released under the terms of the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. The caller is responsible to analyze the response body.

Types

type AddTagToContactRequest

type AddTagToContactRequest struct {
	ContactTag *ContactTag `json:"contactTag"`
}

AddTagToContactRequest is the request body used for adding a tag to a contact.

type AddTagToContactResponse

type AddTagToContactResponse struct {
	ContactTag *ContactTag `json:"contactTag"`
}

AddTagToContactResponse is the response body from adding a tag to a contact.

type Client

type Client struct {

	// Services used for talking to different parts of the Active Campaign API.
	Contacts *ContactsService
	Tags     *TagsService
	// contains filtered or unexported fields
}

A Client manages communication with the Active Campaign API.

func NewClient

func NewClient(opts *ClientOpts) (*Client, error)

NewClient returns a new Active Campaign API client. httpClient is provided to allow a custom client in specialized cases. If a nil httpClient is provided, a new http.DefaultClient will be used.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client.

type ClientOpts

type ClientOpts struct {
	HttpClient httpClient
	BaseUrl    string
	Token      string
}

ClientOpts are used to build a new client. If desired, a custom httpClient can be passed in.

type Contact

type Contact struct {
	Email     string `json:"email"`
	FirstName string `json:"firstName,omitempty"`
	LastName  string `json:"lastName,omitempty"`
	Phone     string `json:"phone,omitempty"`
}

type ContactList

type ContactList struct {
	List    string `json:"list"`
	Contact string `json:"contact"`
	Status  string `json:"status"`
}

type ContactTag

type ContactTag struct {
	CDate   string `json:"cdate,omitempty"`
	Contact string `json:"contact"`
	ID      string `json:"id,omitempty"`
	Links   *struct {
		Contact string `json:"contact,omitempty"`
		Tag     string `json:"tag,omitempty"`
	} `json:"links,omitempty"`
	Tag string `json:"tag"`
}

ContactTag is used to add a tag to a contact.

type ContactsService

type ContactsService service

ContactsService handles communication with contact related methods of the Active Campaign API.

Active Campaign API docs: https://developers.activecampaign.com/reference#contact

func (*ContactsService) AddTagToContact

AddTagToContact adds a tag to a contact.

func (*ContactsService) Create

func (*ContactsService) CreateCustomFieldValue

func (s *ContactsService) CreateCustomFieldValue(fieldValue *CreateCustomFieldValueRequest) (*CreateCustomFieldValueResponse, *Response, error)

CreateCustomFieldValue adds a custom field to a contact.

func (*ContactsService) UpdateListStatusForContact

type CreateContactRequest

type CreateContactRequest struct {
	Contact *Contact `json:"contact"`
}

type CreateContactResponse

type CreateContactResponse struct {
	Contact *CreatedContact `json:"contact"`
}

type CreateCustomFieldValueRequest

type CreateCustomFieldValueRequest struct {
	FieldValue *FieldValue `json:"fieldValue"`
}

CreateCustomFieldValueRequest is the request body used for updating a custom field value on a contact.

type CreateCustomFieldValueResponse

type CreateCustomFieldValueResponse struct {
	Contacts []struct {
		Cdate               string        `json:"cdate"`
		Email               string        `json:"email"`
		Phone               string        `json:"phone"`
		FirstName           string        `json:"firstName"`
		LastName            string        `json:"lastName"`
		Orgid               string        `json:"orgid"`
		Orgname             string        `json:"orgname"`
		SegmentioID         string        `json:"segmentio_id"`
		BouncedHard         string        `json:"bounced_hard"`
		BouncedSoft         string        `json:"bounced_soft"`
		BouncedDate         string        `json:"bounced_date"`
		IP                  string        `json:"ip"`
		Ua                  string        `json:"ua"`
		Hash                string        `json:"hash"`
		SocialdataLastcheck string        `json:"socialdata_lastcheck"`
		EmailLocal          string        `json:"email_local"`
		EmailDomain         string        `json:"email_domain"`
		Sentcnt             string        `json:"sentcnt"`
		RatingTstamp        string        `json:"rating_tstamp"`
		Gravatar            string        `json:"gravatar"`
		Deleted             string        `json:"deleted"`
		Anonymized          string        `json:"anonymized"`
		Adate               string        `json:"adate"`
		Udate               string        `json:"udate"`
		Edate               interface{}   `json:"edate"`
		DeletedAt           string        `json:"deleted_at"`
		CreatedUtcTimestamp string        `json:"created_utc_timestamp"`
		UpdatedUtcTimestamp string        `json:"updated_utc_timestamp"`
		CreatedTimestamp    string        `json:"created_timestamp"`
		UpdatedTimestamp    string        `json:"updated_timestamp"`
		CreatedBy           string        `json:"created_by"`
		UpdatedBy           string        `json:"updated_by"`
		EmailEmpty          bool          `json:"email_empty"`
		AccountContacts     []interface{} `json:"accountContacts"`
		Links               struct {
			BounceLogs            string `json:"bounceLogs"`
			ContactAutomations    string `json:"contactAutomations"`
			ContactData           string `json:"contactData"`
			ContactGoals          string `json:"contactGoals"`
			ContactLists          string `json:"contactLists"`
			ContactLogs           string `json:"contactLogs"`
			ContactTags           string `json:"contactTags"`
			ContactDeals          string `json:"contactDeals"`
			Deals                 string `json:"deals"`
			FieldValues           string `json:"fieldValues"`
			GeoIps                string `json:"geoIps"`
			Notes                 string `json:"notes"`
			Organization          string `json:"organization"`
			PlusAppend            string `json:"plusAppend"`
			TrackingLogs          string `json:"trackingLogs"`
			ScoreValues           string `json:"scoreValues"`
			AutomationEntryCounts string `json:"automationEntryCounts"`
		} `json:"links"`
		ID           string      `json:"id"`
		Organization interface{} `json:"organization"`
	} `json:"contacts"`
	FieldValue *FieldValue `json:"fieldValue"`
}

CreateCustomFieldValueResponse is the response body from updating a custom field value on a contact.

type CreateTagRequest

type CreateTagRequest struct {
	Tag *Tag `json:"tag"`
}

CreateTagRequest is the request body used for creating a tag.

type CreatedContact

type CreatedContact struct {
	Email string `json:"email"`
	Cdate string `json:"cdate"`
	Udate string `json:"udate"`
	Orgid string `json:"orgid"`
	Links struct {
		BounceLogs         string `json:"bounceLogs"`
		ContactAutomations string `json:"contactAutomations"`
		ContactData        string `json:"contactData"`
		ContactGoals       string `json:"contactGoals"`
		ContactLists       string `json:"contactLists"`
		ContactLogs        string `json:"contactLogs"`
		ContactTags        string `json:"contactTags"`
		ContactDeals       string `json:"contactDeals"`
		Deals              string `json:"deals"`
		FieldValues        string `json:"fieldValues"`
		GeoIps             string `json:"geoIps"`
		Notes              string `json:"notes"`
		Organization       string `json:"organization"`
		PlusAppend         string `json:"plusAppend"`
		TrackingLogs       string `json:"trackingLogs"`
		ScoreValues        string `json:"scoreValues"`
	} `json:"links"`
	ID           string `json:"id"`
	Organization string `json:"organization"`
}

type CreatedTag

type CreatedTag struct {
	Tag             string `json:"tag"`
	Description     string `json:"description"`
	TagType         string `json:"tagType"`
	SubscriberCount string `json:"subscriber_count"`
	Cdate           string `json:"cdate"`
	Links           *Links `json:"links"`
	ID              string `json:"id"`
}

CreatedTag is a struct embedded in the response for creating or retrieving a tag.

type FieldValue

type FieldValue struct {
	Contact string      `json:"contact"`
	Field   interface{} `json:"field"`
	Value   interface{} `json:"value"`
	Cdate   string      `json:"cdate,omitempty"`
	Udate   string      `json:"udate,omitempty"`
	Links   *struct {
		Owner string `json:"owner,omitempty"`
		Field string `json:"field,omitempty"`
	} `json:"links,omitempty"`
	ID    string      `json:"id,omitempty"`
	Owner interface{} `json:"owner,omitempty"`
}

FieldValue stores a custom field value and the contact information it is attached to.

type Links struct {
	ContactGoalTags string `json:"contactGoalTags"`
}

Links is embedded in the CreatedTag struct.

type ListAllResponse

type ListAllResponse struct {
	Tags []*CreatedTag `json:"tags"`
	Meta *Meta         `json:"meta"`
}

ListAllResponse is the response body returned from listing all tags.

type Meta

type Meta struct {
	Total string `json:"total"`
}

Meta is embedded in the ListAllResponse struct.

type Response

type Response struct {
	*http.Response
}

Response is a Active Campaign API response. This wraps the standard http.Response returned from Active Campaign.

type Tag

type Tag struct {
	Tag         string `json:"tag,omitempty"`
	TagType     string `json:"tagType,omitempty"`
	Description string `json:"description,omitempty"`
}

Tags are labels that you can apply to contacts to help you organize them. The API enables you to add, view, update, and delete tags.

type TagResponse

type TagResponse struct {
	Tag *CreatedTag `json:"tag"`
}

TagResponse is the response body returned from creating or retrieving a tag.

type TagsService

type TagsService service

TagsService handles communication with tag related methods of the Active Campaign API.

Active Campaign API docs: https://developers.activecampaign.com/reference#tags

func (*TagsService) Create

func (s *TagsService) Create(tag *CreateTagRequest) (*TagResponse, *Response, error)

Create a tag.

func (*TagsService) ListAll

func (s *TagsService) ListAll() (*ListAllResponse, *Response, error)

Lists all tags.

func (*TagsService) Retrieve

func (s *TagsService) Retrieve(id string) (*TagResponse, *Response, error)

Retrieve a tag.

type UpdateContactListStatusResponse

type UpdateContactListStatusResponse struct {
	Contacts []struct {
		Cdate               string `json:"cdate"`
		Email               string `json:"email"`
		Phone               string `json:"phone"`
		FirstName           string `json:"firstName"`
		LastName            string `json:"lastName"`
		Orgid               string `json:"orgid"`
		Orgname             string `json:"orgname"`
		SegmentioID         string `json:"segmentio_id"`
		BouncedHard         string `json:"bounced_hard"`
		BouncedSoft         string `json:"bounced_soft"`
		BouncedDate         string `json:"bounced_date"`
		IP                  string `json:"ip"`
		Ua                  string `json:"ua"`
		Hash                string `json:"hash"`
		SocialdataLastcheck string `json:"socialdata_lastcheck"`
		EmailLocal          string `json:"email_local"`
		EmailDomain         string `json:"email_domain"`
		Sentcnt             string `json:"sentcnt"`
		RatingTstamp        string `json:"rating_tstamp"`
		Gravatar            string `json:"gravatar"`
		Deleted             string `json:"deleted"`
		Anonymized          string `json:"anonymized"`
		Adate               string `json:"adate"`
		Udate               string `json:"udate"`
		Edate               string `json:"edate"`
		DeletedAt           string `json:"deleted_at"`
		CreatedUtcTimestamp string `json:"created_utc_timestamp"`
		UpdatedUtcTimestamp string `json:"updated_utc_timestamp"`
		CreatedTimestamp    string `json:"created_timestamp"`
		UpdatedTimestamp    string `json:"updated_timestamp"`
		CreatedBy           string `json:"created_by"`
		UpdatedBy           string `json:"updated_by"`
		Links               struct {
			BounceLogs            string `json:"bounceLogs"`
			ContactAutomations    string `json:"contactAutomations"`
			ContactData           string `json:"contactData"`
			ContactGoals          string `json:"contactGoals"`
			ContactLists          string `json:"contactLists"`
			ContactLogs           string `json:"contactLogs"`
			ContactTags           string `json:"contactTags"`
			ContactDeals          string `json:"contactDeals"`
			Deals                 string `json:"deals"`
			FieldValues           string `json:"fieldValues"`
			GeoIps                string `json:"geoIps"`
			Notes                 string `json:"notes"`
			Organization          string `json:"organization"`
			PlusAppend            string `json:"plusAppend"`
			TrackingLogs          string `json:"trackingLogs"`
			ScoreValues           string `json:"scoreValues"`
			AccountContacts       string `json:"accountContacts"`
			AutomationEntryCounts string `json:"automationEntryCounts"`
		} `json:"links"`
		ID           string      `json:"id"`
		Organization interface{} `json:"organization"`
	} `json:"contacts"`
	ContactList struct {
		Contact     string      `json:"contact"`
		List        string      `json:"list"`
		Form        interface{} `json:"form"`
		Seriesid    string      `json:"seriesid"`
		Sdate       string      `json:"sdate"`
		Udate       interface{} `json:"udate"`
		Status      string      `json:"status"`
		Responder   string      `json:"responder"`
		Sync        string      `json:"sync"`
		Unsubreason string      `json:"unsubreason"`
		Campaign    interface{} `json:"campaign"`
		Message     interface{} `json:"message"`
		FirstName   string      `json:"first_name"`
		LastName    string      `json:"last_name"`
		IP4Sub      string      `json:"ip4Sub"`
		// Update list status for a contact does not return a uniform type for Sourceid.
		// If a contact is not a member of the list, it will return a number. Otherwise, a string is returned.
		Sourceid              interface{} `json:"sourceid,string"`
		AutosyncLog           interface{} `json:"autosyncLog"`
		IP4Last               string      `json:"ip4_last"`
		IP4Unsub              string      `json:"ip4Unsub"`
		CreatedTimestamp      string      `json:"created_timestamp"`
		UpdatedTimestamp      string      `json:"updated_timestamp"`
		CreatedBy             interface{} `json:"created_by"`
		UpdatedBy             interface{} `json:"updated_by"`
		UnsubscribeAutomation interface{} `json:"unsubscribeAutomation"`
		Links                 struct {
			Automation            string `json:"automation"`
			List                  string `json:"list"`
			Contact               string `json:"contact"`
			Form                  string `json:"form"`
			AutosyncLog           string `json:"autosyncLog"`
			Campaign              string `json:"campaign"`
			UnsubscribeAutomation string `json:"unsubscribeAutomation"`
			Message               string `json:"message"`
		} `json:"links"`
		ID         string      `json:"id"`
		Automation interface{} `json:"automation"`
	} `json:"contactList"`
}

type UpdateListStatusForContactRequest

type UpdateListStatusForContactRequest struct {
	ContactList *ContactList `json:"contactList"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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