Help us shape the future of Go! Take the 2026 Go Developer Survey

amo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 7 Imported by: 0

README

Amo CRM API (v2) in Go

Simple Amo CRM API wrapper.

Features

  • Get Account
  • Add Companies
  • Add Contacts
  • Add Tasks
  • Add Notes

In future API can be changed/modified. Feel free to fork and modify for your needs.

Example


client, err := NewClient("https://yourdomain.amocrm.ru", nil)
if err != nil {
    panic(err)
}

auth, err := client.Authorize("your@email.com", "amo_api_key")
if err != nil {
    panic(err)
}

if !auth.Response.Auth {
    panic("NO AUTH")
}

acc, err := client.GetAccount(false, []string{"users", "custom_fields"})
if err != nil {
    panic(err)
}

compId, err := client.AddCompany(Company{
    Name:              "Company Name",
    ResponsibleUserID: 123456,
    CreatedBy:         123456,
    // Information about your custom fields and IDs 
    // you can get from account
    CustomFields: []CustomField{
        {
            ID: 317255, // Phone
            Values: []CSValue{
                {Value: MultiValuesString("111-222-333"), Enum: "702113"},
            },
        },
    },
})
if err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiValuesString

func MultiValuesString(s ...string) string

Separates strings values with comma

Types

type Account

type Account struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	Subdomain      string `json:"subdomain"`
	Currency       string `json:"currency"`
	Timezone       string `json:"timezone"`
	TimezoneOffset string `json:"timezoneoffset"`
	Language       string `json:"language"`
	CurrentUser    int    `json:"current_user"`
	Embedded       struct {
		Users        map[string]User
		CustomFields struct {
			Contacts  map[string]AccountCustomField `json:"contacts"`
			Leads     map[string]AccountCustomField `json:"leads"`
			Companies map[string]AccountCustomField `json:"companies"`
		} `json:"custom_fields"`
	} `json:"_embedded"`
}

Account an information on the authorized account.

type AccountCustomField

type AccountCustomField struct {
	ID          int               `json:"id"`
	Name        string            `json:"name"`
	FieldType   int               `json:"field_type"`
	Sort        int               `json:"sort"`
	IsMultiple  bool              `json:"is_multiple"`
	IsSystem    bool              `json:"is_system"`
	IsEditable  bool              `json:"is_editable"`
	IsRequired  bool              `json:"is_required"`
	IsDeletable bool              `json:"is_deletable"`
	IsVisible   bool              `json:"is_visible"`
	Enums       map[string]string `json:"enums"`
}

type AuthResponse

type AuthResponse struct {
	Response struct {
		Auth     bool `json:"auth"`
		Accounts []struct {
			ID        string `json:"id"`
			Name      string `json:"name"`
			Subdomain string `json:"subdomain"`
			Language  string `json:"language"`
			Timezone  string `json:"timezone"`
		} `json:"accounts"`
		ServerTime int `json:"server_time"`
	} `json:"response"`
}

AuthResponse information about Amo' user and account.

type CSValue

type CSValue struct {
	Value   string `json:"value"`
	Enum    string `json:"enum"`
	Subtype string `json:"subtype"`
}

type Client

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

Client AmoCRM API Client

func NewClient

func NewClient(accountWebAddress string, rateLimiter RateLimiter) (*Client, error)

NewClient creates and initializes AmoCRM API. accountWebAddress is your AmoCRM account address like https://your-account.amocrm.com

func (*Client) AddCompany

func (c *Client) AddCompany(comp Company) (int, error)

func (*Client) AddContact

func (c *Client) AddContact(contact Contact) (int, error)

func (*Client) AddNote

func (c *Client) AddNote(note Note) (int, error)

func (*Client) AddTask

func (c *Client) AddTask(task Task) (int, error)

func (*Client) Authorize

func (c *Client) Authorize(userLogin, userHash string) (*AuthResponse, error)

Authorize In case of successful authorization, this method returns the user’s session ID, which must be used while accessing to other API methods. Saves user's login and hash into the client for next usage.

func (*Client) DoGet

func (c *Client) DoGet(url string, result interface{}) error

func (*Client) DoPost

func (c *Client) DoPost(url string, data interface{}) (*http.Response, error)

func (*Client) DoPostWithReturnID

func (c *Client) DoPostWithReturnID(url string, data interface{}) (int, error)

Post with return ID on new entity

func (*Client) GetAccount

func (c *Client) GetAccount(freeUsers bool, with []string) (Account, error)

func (*Client) SetURL

func (c *Client) SetURL(url string, addValues map[string]string) string

Set URL and add default params

type Company

type Company struct {
	Name              string        `json:"name,omitempty"`
	CreatedAt         int           `json:"created_at,omitempty"`
	UpdatedAt         int           `json:"updated_at,omitempty"`
	ResponsibleUserID int           `json:"responsible_user_id,omitempty"`
	CreatedBy         int           `json:"created_by,omitempty"`
	Tags              string        `json:"tags,omitempty"`
	LeadsID           string        `json:"leads_id,omitempty"`
	CustomersID       string        `json:"customers_id,omitempty"`
	ContactsID        string        `json:"contacts_id,omitempty"`
	CustomFields      []CustomField `json:"custom_fields,omitempty"`
}

type CompanyAction

type CompanyAction struct {
	Add []Company `json:"add,omitempty"`
}

type Contact

type Contact struct {
	Name              string        `json:"name,omitempty"`
	CreatedAt         int           `json:"created_at,omitempty"`
	UpdatedAt         int           `json:"updated_at,omitempty"`
	ResponsibleUserID int           `json:"responsible_user_id,omitempty"`
	CreatedBy         int           `json:"created_by,omitempty"`
	CompanyName       string        `json:"company_name,omitempty"`
	Tags              string        `json:"tags,omitempty"`
	LeadsID           string        `json:"leads_id,omitempty"`
	CustomersID       string        `json:"customers_id,omitempty"`
	CompanyID         string        `json:"company_id,omitempty"`
	CustomFields      []CustomField `json:"custom_fields,omitempty"`
}

type ContactAction

type ContactAction struct {
	Add []Contact `json:"add,omitempty"`
}

type CustomField

type CustomField struct {
	ID     int       `json:"id"`
	Values []CSValue `json:"values"`
}

type Note

type Note struct {
	ElementID         int    `json:"element_id,omitempty"`
	ElementType       int    `json:"element_type,omitempty"`
	Text              string `json:"text,omitempty"`
	NoteType          int    `json:"note_type,omitempty"`
	CreatedAt         int    `json:"created_at,omitempty"`
	UpdatedAt         int    `json:"updated_at,omitempty"`
	ResponsibleUserID int    `json:"responsible_user_id,omitempty"`
}

type NoteAction

type NoteAction struct {
	Add []Note `json:"add,omitempty"`
}

type RateLimiter

type RateLimiter interface {
	WaitForRequest()
}

type Task

type Task struct {
	ElementID         int    `json:"element_id,omitempty"`
	ElementType       int    `json:"element_type,omitempty"`
	CompleteTillAt    int    `json:"complete_till_at,omitempty"`
	TaskType          int    `json:"task_type,omitempty"`
	Text              string `json:"text,omitempty"`
	CreatedAt         int    `json:"created_at,omitempty"`
	UpdatedAt         int    `json:"updated_at,omitempty"`
	ResponsibleUserID int    `json:"responsible_user_id,omitempty"`
	IsCompleted       bool   `json:"is_completed,omitempty"`
	CreatedBy         int    `json:"created_by,omitempty"`
}

type TaskAction

type TaskAction struct {
	Add []Task `json:"add,omitempty"`
}

type User

type User struct {
	ID       int               `json:"id"`
	Name     string            `json:"name"`
	LastName string            `json:"last_name"`
	Login    string            `json:"login"`
	Language string            `json:"language"`
	GroupID  int               `json:"group_id"`
	IsActive bool              `json:"is_active"`
	IsFree   bool              `json:"is_free"`
	IsAdmin  bool              `json:"is_admin"`
	Rights   map[string]string `json:"rights,omitempty"`
}

Jump to

Keyboard shortcuts

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