https://github.com/alexeykhan/amocrm
This package provides an example of a Golang client for amoCRM API. Use it as a starter-kit to make your own client.
https://github.com/alexeykhan/amocrm
amocrm amocrm-api amocrm-go go golang
Last synced: 5 months ago
JSON representation
This package provides an example of a Golang client for amoCRM API. Use it as a starter-kit to make your own client.
- Host: GitHub
- URL: https://github.com/alexeykhan/amocrm
- Owner: alexeykhan
- License: mit
- Created: 2020-11-15T20:57:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-15T07:27:34.000Z (over 2 years ago)
- Last Synced: 2025-11-22T15:08:29.900Z (7 months ago)
- Topics: amocrm, amocrm-api, amocrm-go, go, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/alexeykhan/amocrm
- Size: 111 KB
- Stars: 8
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Go Package for amoCRM API
This package provides a Golang client for amoCRM API.
## Disclaimer
This code is in no way affiliated with, authorized, maintained, sponsored
or endorsed by amoCRM or any of its affiliates or subsidiaries. This is an
independent and unofficial API client. Use at your own risk.
## Installation
`go get -u github.com/alexeykhan/amocrm`
## Quick Start
**Step №1: Redirect user to the authorization page.**
User grants access to their account and is redirected back
with `referer` and `code` GET-parameters attached.
```go
package main
import (
"fmt"
"github.com/alexeykhan/amocrm"
)
func main() {
amoCRM := amocrm.New("clientID", "clientSecret", "redirectURL")
state := amocrm.RandomState() // store this state as a session identifier
mode := amocrm.PostMessageMode // options: PostMessageMode, PopupMode
authURL, err := amoCRM.AuthorizeURL(state, mode)
if err != nil {
fmt.Println("failed to get auth url:", err)
return
}
fmt.Println("Redirect user to this URL:")
fmt.Println(authURL)
}
```
**Step №2: Exchange authorization code for token.**
Use received `referer` and `code` parameters as account domain and
authorization code respectively to make a handshake with amoCRM and
Get a fresh set of `access_token`, `refresh_token` and token meta data.
```go
package main
import (
"fmt"
"github.com/alexeykhan/amocrm"
)
func main() {
amoCRM := amocrm.New("clientID", "clientSecret", "redirectURL")
if err := amoCRM.SetDomain("example.amocrm.ru"); err != nil {
fmt.Println("set domain:", err)
return
}
token, err := amoCRM.TokenByCode("authorizationCode")
if err != nil {
fmt.Println("get token by code:", err)
return
}
fmt.Println("access_token:", token.AccessToken())
fmt.Println("refresh_token:", token.RefreshToken())
fmt.Println("token_type:", token.TokenType())
fmt.Println("expires_at:", token.ExpiresAt().Unix())
}
```
**Step №3: Make your first API request.**
Set amoCRM accounts domain and token to authorize your requests.
```go
package main
import (
"fmt"
"time"
"github.com/alexeykhan/amocrm"
)
func main() {
amoCRM := amocrm.New("clientID", "clientSecret", "redirectURL")
if err := amoCRM.SetDomain("example.amocrm.ru"); err != nil {
fmt.Println("set domain:", err)
return
}
token := amocrm.NewToken("accessToken", "refreshToken", "tokenType", time.Now())
if err := amoCRM.SetToken(token); err != nil {
fmt.Println("set token:", err)
return
}
cfg := amocrm.AccountsConfig{
Relations: []string{
amocrm.WithUUID,
amocrm.WithVersion,
amocrm.WithAmojoID,
amocrm.WithTaskTypes,
amocrm.WithUserGroups,
amocrm.WithAmojoRights,
amocrm.WithDatetimeSettings,
},
}
account, err := amoCRM.Accounts().Current(cfg)
if err != nil {
fmt.Println("fetch current accounts:", err)
return
}
fmt.Println("current accounts:", account)
}
```
## Development Status: In Progress
This package is under development so any methods, constants or types may be changed
in newer versions without backward compatibility with previous ones. Use it at your
own risk and feel free to fork it anytime.
Released under the [MIT License](LICENSE.md).