2021-10-27 15:49:06 +03:00
package retailcrm
2018-02-27 11:37:15 +03:00
import (
2019-09-04 11:38:21 +03:00
"bytes"
2018-02-27 11:37:15 +03:00
"encoding/json"
2019-09-09 15:01:17 +03:00
"errors"
2018-02-27 11:37:15 +03:00
"fmt"
2019-09-04 11:38:21 +03:00
"io"
2018-02-27 11:37:15 +03:00
"io/ioutil"
2018-09-28 01:37:56 +03:00
"log"
2018-02-27 11:37:15 +03:00
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/google/go-querystring/query"
)
2021-04-26 12:09:21 +03:00
// New initialize client.
2018-02-27 11:37:15 +03:00
func New ( url string , key string ) * Client {
return & Client {
2022-04-18 12:23:18 +03:00
URL : strings . TrimRight ( url , "/" ) ,
2018-09-28 01:37:56 +03:00
Key : key ,
2019-02-04 11:59:05 +03:00
httpClient : & http . Client { Timeout : time . Minute } ,
2018-02-27 11:37:15 +03:00
}
}
2021-10-27 15:49:06 +03:00
// WithLogger sets the provided logger instance into the Client.
func ( c * Client ) WithLogger ( logger BasicLogger ) * Client {
c . logger = logger
return c
}
// writeLog writes to the log.
func ( c * Client ) writeLog ( format string , v ... interface { } ) {
if c . logger != nil {
c . logger . Printf ( format , v ... )
return
}
log . Printf ( format , v ... )
}
2021-04-26 12:09:21 +03:00
// GetRequest implements GET Request.
func ( c * Client ) GetRequest ( urlWithParameters string , versioned ... bool ) ( [ ] byte , int , error ) {
2018-02-27 11:37:15 +03:00
var res [ ] byte
2018-03-21 00:54:37 +03:00
var prefix = "/api/v5"
if len ( versioned ) > 0 {
2021-10-27 15:49:06 +03:00
if ! versioned [ 0 ] {
2018-03-21 00:54:37 +03:00
prefix = "/api"
}
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
req , err := http . NewRequest ( "GET" , fmt . Sprintf ( "%s%s%s" , c . URL , prefix , urlWithParameters ) , nil )
2018-02-27 11:37:15 +03:00
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
2018-02-27 11:37:15 +03:00
}
req . Header . Set ( "X-API-KEY" , c . Key )
2018-09-28 01:37:56 +03:00
if c . Debug {
2021-10-27 15:49:06 +03:00
c . writeLog ( "API Request: %s %s" , fmt . Sprintf ( "%s%s%s" , c . URL , prefix , urlWithParameters ) , c . Key )
2018-09-28 01:37:56 +03:00
}
2018-02-27 11:37:15 +03:00
resp , err := c . httpClient . Do ( req )
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
2018-02-27 11:37:15 +03:00
}
if resp . StatusCode >= http . StatusInternalServerError {
2021-10-27 15:49:06 +03:00
return res , resp . StatusCode , CreateGenericAPIError (
fmt . Sprintf ( "HTTP request error. Status code: %d." , resp . StatusCode ) )
2018-02-27 11:37:15 +03:00
}
res , err = buildRawResponse ( resp )
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
}
if resp . StatusCode >= http . StatusBadRequest && resp . StatusCode < http . StatusInternalServerError {
2021-10-27 15:49:06 +03:00
return res , resp . StatusCode , CreateAPIError ( res )
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
if c . Debug {
2021-10-27 15:49:06 +03:00
c . writeLog ( "API Response: %s" , res )
2018-09-28 01:37:56 +03:00
}
2021-04-26 12:09:21 +03:00
return res , resp . StatusCode , nil
2018-02-27 11:37:15 +03:00
}
2021-04-26 12:09:21 +03:00
// PostRequest implements POST Request with generic body data.
func ( c * Client ) PostRequest (
uri string ,
postData interface { } ,
contType ... string ,
) ( [ ] byte , int , error ) {
2019-09-04 11:38:21 +03:00
var (
res [ ] byte
contentType string
)
prefix := "/api/v5"
2018-02-27 11:37:15 +03:00
2019-09-04 11:38:21 +03:00
if len ( contType ) > 0 {
contentType = contType [ 0 ]
} else {
contentType = "application/x-www-form-urlencoded"
}
2021-04-26 12:09:21 +03:00
reader , err := getReaderForPostData ( postData )
if err != nil {
return res , 0 , err
2019-09-04 11:38:21 +03:00
}
req , err := http . NewRequest ( "POST" , fmt . Sprintf ( "%s%s%s" , c . URL , prefix , uri ) , reader )
2018-02-27 11:37:15 +03:00
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
2018-02-27 11:37:15 +03:00
}
2019-09-04 11:38:21 +03:00
req . Header . Set ( "Content-Type" , contentType )
2018-02-27 11:37:15 +03:00
req . Header . Set ( "X-API-KEY" , c . Key )
2018-09-28 01:37:56 +03:00
if c . Debug {
2021-10-27 15:49:06 +03:00
c . writeLog ( "API Request: %s %s" , uri , c . Key )
2018-09-28 01:37:56 +03:00
}
2018-02-27 11:37:15 +03:00
resp , err := c . httpClient . Do ( req )
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
2018-02-27 11:37:15 +03:00
}
if resp . StatusCode >= http . StatusInternalServerError {
2021-10-27 15:49:06 +03:00
return res , resp . StatusCode , CreateGenericAPIError (
fmt . Sprintf ( "HTTP request error. Status code: %d." , resp . StatusCode ) )
2018-02-27 11:37:15 +03:00
}
res , err = buildRawResponse ( resp )
if err != nil {
2021-04-26 12:09:21 +03:00
return res , 0 , err
}
if resp . StatusCode >= http . StatusBadRequest && resp . StatusCode < http . StatusInternalServerError {
2021-10-27 15:49:06 +03:00
return res , resp . StatusCode , CreateAPIError ( res )
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
if c . Debug {
2021-10-27 15:49:06 +03:00
c . writeLog ( "API Response: %s" , res )
2018-09-28 01:37:56 +03:00
}
2021-04-26 12:09:21 +03:00
return res , resp . StatusCode , nil
}
func getReaderForPostData ( postData interface { } ) ( io . Reader , error ) {
var reader io . Reader
switch d := postData . ( type ) {
case url . Values :
reader = strings . NewReader ( d . Encode ( ) )
default :
if i , ok := d . ( io . Reader ) ; ok {
reader = i
} else {
err := errors . New ( "postData should be url.Values or implement io.Reader" )
return nil , err
}
}
return reader , nil
2018-02-27 11:37:15 +03:00
}
func buildRawResponse ( resp * http . Response ) ( [ ] byte , error ) {
defer resp . Body . Close ( )
res , err := ioutil . ReadAll ( resp . Body )
if err != nil {
return res , err
}
return res , nil
}
2021-04-26 12:09:21 +03:00
// checkBy select identifier type.
2018-02-27 11:37:15 +03:00
func checkBy ( by string ) string {
2019-10-16 16:32:31 +03:00
var context = ByID
2018-02-27 11:37:15 +03:00
2019-10-16 16:32:31 +03:00
if by != ByID {
context = ByExternalID
2018-02-27 11:37:15 +03:00
}
return context
}
2021-04-26 12:09:21 +03:00
// fillSite add site code to parameters if present.
2018-02-27 11:37:15 +03:00
func fillSite ( p * url . Values , site [ ] string ) {
if len ( site ) > 0 {
s := site [ 0 ]
if s != "" {
p . Add ( "site" , s )
}
}
}
2018-03-19 23:18:36 +03:00
// APIVersions get all available API versions for exact account
2018-02-27 11:37:15 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-api-versions
2018-04-12 16:43:53 +03:00
//
2018-02-27 11:37:15 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-02-27 11:37:15 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.APIVersions()
2018-02-27 11:37:15 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-02-27 11:37:15 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-02-27 11:37:15 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.versions {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) APIVersions ( ) ( VersionResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp VersionResponse
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/api-versions" , false )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-03-19 23:18:36 +03:00
// APICredentials get all available API methods for exact account
2018-02-27 15:22:52 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see https://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-credentials
2018-04-12 16:43:53 +03:00
//
2018-02-27 15:22:52 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-02-27 15:22:52 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.APICredentials()
2018-02-27 15:22:52 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-02-27 15:22:52 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-02-27 15:22:52 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Scopes {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) APICredentials ( ) ( CredentialResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CredentialResponse
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/credentials" , false )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
2022-02-03 18:09:33 +03:00
return resp , status , err
}
return resp , status , nil
}
// APISystemInfo get info about system
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-system-info
2022-02-03 18:09:33 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2022-02-03 18:09:33 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.APISystemInfo()
2022-02-03 18:09:33 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2022-02-03 18:09:33 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2022-02-03 18:09:33 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data)
2022-02-03 18:09:33 +03:00
func ( c * Client ) APISystemInfo ( ) ( SystemInfoResponse , int , error ) {
var resp SystemInfoResponse
data , status , err := c . GetRequest ( "/system-info" , false )
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
2021-10-27 15:49:06 +03:00
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// Customers returns list of customers matched the specified filter
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-customers
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Customers(retailcrm.CustomersRequest{
2018-04-12 16:43:53 +03:00
// Filter: CustomersFilter{
// City: "Moscow",
// },
// Page: 3,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Customers {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Customers ( parameters CustomersRequest ) ( CustomersResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CustomersResponse
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomersCombine combine given customers
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-combine
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomersCombine([]retailcrm.Customer{{ID: 1}, {ID: 2}}, Customer{ID: 3})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomersCombine ( customers [ ] Customer , resultCustomer Customer ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
combineJSONIn , _ := json . Marshal ( & customers )
combineJSONOut , _ := json . Marshal ( & resultCustomer )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"customers" : { string ( combineJSONIn ) } ,
"resultCustomer" : { string ( combineJSONOut ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( "/customers/combine" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomerCreate creates customer
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomersCombine(retailcrm.Customer{
2018-04-12 16:43:53 +03:00
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// ExternalID: 1,
// Email: "ivanov@example.com",
2021-10-27 15:49:06 +03:00
// Address: &retailcrm.Address{
2018-04-12 16:43:53 +03:00
// City: "Moscow",
// Street: "Kutuzovsky",
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2021-10-27 15:49:06 +03:00
// fmt.Printf("%v", data.ID)
2018-04-12 16:43:53 +03:00
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomerCreate ( customer Customer , site ... string ) ( CustomerChangeResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CustomerChangeResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
customerJSON , _ := json . Marshal ( & customer )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customer" : { string ( customerJSON ) } ,
2018-03-21 00:54:37 +03:00
}
fillSite ( & p , site )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/customers/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomersFixExternalIds customers external ID
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-fix-external-ids
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomersFixExternalIds([]retailcrm.IdentifiersPair{{
2018-04-12 16:43:53 +03:00
// ID: 1,
// ExternalID: 12,
// }})
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomersFixExternalIds ( customers [ ] IdentifiersPair ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
customersJSON , _ := json . Marshal ( & customers )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"customers" : { string ( customersJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( "/customers/fix-external-ids" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomersHistory returns customer's history
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-customers-history
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomersHistory(retailcrm.CustomersHistoryRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.CustomersHistoryFilter{
2018-04-12 16:43:53 +03:00
// SinceID: 20,
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.History {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomersHistory ( parameters CustomersHistoryRequest ) ( CustomersHistoryResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CustomersHistoryResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers/history?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-03-21 00:54:37 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomerNotes returns customer related notes
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-customers-notes
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomerNotes(retailcrm.NotesRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.NotesFilter{
2018-04-12 16:43:53 +03:00
// CustomerIds: []int{1,2,3}
2022-11-24 13:37:21 +03:00
// },
2018-04-12 16:43:53 +03:00
// Page: 1,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Notes {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomerNotes ( parameters NotesRequest ) ( NotesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp NotesResponse
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers/notes?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomerNoteCreate note creation
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-notes-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomerNoteCreate(retailcrm.Note{
2018-04-12 16:43:53 +03:00
// Text: "some text",
// ManagerID: 12,
2021-10-27 15:49:06 +03:00
// Customer: &retailcrm.Customer{
2018-04-12 16:43:53 +03:00
// ID: 1,
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomerNoteCreate ( note Note , site ... string ) ( CreateResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CreateResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
noteJSON , _ := json . Marshal ( & note )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"note" : { string ( noteJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/customers/notes/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-03-21 00:54:37 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomerNoteDelete remove customer related note
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-notes-id-delete
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomerNoteDelete(12)
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomerNoteDelete ( id int ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
p := url . Values {
2021-04-16 14:25:25 +03:00
"id" : { strconv . Itoa ( id ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers/notes/%d/delete" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomersUpload customers batch upload
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-upload
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CustomersUpload([]retailcrm.Customer{
2018-04-12 16:43:53 +03:00
// {
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// ExternalID: 1,
// Email: "ivanov@example.com",
// },
// {
// FirstName: "Petr",
// LastName: "Petrov",
// Patronymic: "Petrovich",
// ExternalID: 2,
// Email: "petrov@example.com",
// },
// }}
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.UploadedCustomers)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomersUpload ( customers [ ] Customer , site ... string ) ( CustomersUploadResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CustomersUploadResponse
2018-03-19 23:18:36 +03:00
uploadJSON , _ := json . Marshal ( & customers )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"customers" : { string ( uploadJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/customers/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// Customer returns information about customer
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-customers-externalId
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Customer(12, retailcrm.ByExternalID, "")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.Customer)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Customer ( id , by , site string ) ( CustomerResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CustomerResponse
var context = checkBy ( by )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
fw := CustomerRequest { context , site }
params , _ := query . Values ( fw )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers/%s?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-03-21 00:54:37 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomerEdit edit exact customer
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-customers-externalId-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// data, status, err := client.CustomerEdit(
2021-10-27 15:49:06 +03:00
// retailcrm.Customer{
2018-04-12 16:43:53 +03:00
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// ID: 1,
// Email: "ivanov@example.com",
// },
2021-10-27 15:49:06 +03:00
// retailcrm.ByID,
2018-04-23 16:28:54 +03:00
// )
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.Customer)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomerEdit ( customer Customer , by string , site ... string ) ( CustomerChangeResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CustomerChangeResponse
var uid = strconv . Itoa ( customer . ID )
var context = checkBy ( by )
2019-10-16 16:32:31 +03:00
if context == ByExternalID {
2018-03-21 00:54:37 +03:00
uid = customer . ExternalID
}
customerJSON , _ := json . Marshal ( & customer )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { context } ,
"customer" : { string ( customerJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers/%s/edit" , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2019-10-16 16:32:31 +03:00
// CorporateCustomers returns list of corporate customers matched the specified filter
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomers(retailcrm.CorporateCustomersRequest{
2019-10-16 16:32:31 +03:00
// Filter: CorporateCustomersFilter{
// City: "Moscow",
// },
// Page: 3,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.CustomersCorporate {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomers ( parameters CorporateCustomersRequest ) ( CorporateCustomersResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomersResponse
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerCreate creates corporate customer
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-create
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomerCreate(retailcrm.CorporateCustomer{
2019-10-16 16:32:31 +03:00
// Nickname: "Company",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
// if data.Success == true {
2021-10-27 15:49:06 +03:00
// fmt.Printf("%v", data.ID)
2019-10-16 16:32:31 +03:00
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerCreate ( customer CorporateCustomer , site ... string ) (
CorporateCustomerChangeResponse , int , error ,
) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomerChangeResponse
customerJSON , _ := json . Marshal ( & customer )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customerCorporate" : { string ( customerJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/customers-corporate/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomersFixExternalIds will fix corporate customers external ID's
//
2021-10-27 15:49:06 +03:00
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-fix-external-ids
2019-10-16 16:32:31 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomersFixExternalIds([]retailcrm.IdentifiersPair{{
2019-10-16 16:32:31 +03:00
// ID: 1,
// ExternalID: 12,
// }})
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomersFixExternalIds ( customers [ ] IdentifiersPair ) ( SuccessfulResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp SuccessfulResponse
customersJSON , _ := json . Marshal ( & customers )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customersCorporate" : { string ( customersJSON ) } ,
2019-10-16 16:32:31 +03:00
}
data , status , err := c . PostRequest ( "/customers-corporate/fix-external-ids" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomersHistory returns corporate customer's history
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-fix-external-ids
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomersHistory(retailcrm.CorporateCustomersHistoryRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.CorporateCustomersHistoryFilter{
2019-10-16 16:32:31 +03:00
// SinceID: 20,
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.History {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomersHistory ( parameters CorporateCustomersHistoryRequest ) (
CorporateCustomersHistoryResponse , int , error ,
) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomersHistoryResponse
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/history?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
2021-10-27 15:49:06 +03:00
// CorporateCustomersNotes returns list of corporate customers notes matched the specified filter
2019-10-16 16:32:31 +03:00
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate-notes
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomersNotes(retailcrm.CorporateCustomersNotesRequest{
2019-10-16 16:32:31 +03:00
// Filter: CorporateCustomersNotesFilter{
// Text: "text",
// },
// Page: 3,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Notes {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomersNotes ( parameters CorporateCustomersNotesRequest ) (
CorporateCustomersNotesResponse , int , error ,
) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomersNotesResponse
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/notes?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerNoteCreate creates corporate customer note
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-notes-create
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomerNoteCreate(retailcrm.CorporateCustomerNote{
// Text: "text",
// Customer: &retailcrm.IdentifiersPair{
// ID: 1,
// }
// })
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// fmt.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerNoteCreate ( note CorporateCustomerNote , site ... string ) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CreateResponse
noteJSON , _ := json . Marshal ( & note )
p := url . Values {
2021-10-27 15:49:06 +03:00
"note" : { string ( noteJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/customers-corporate/notes/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerNoteDelete removes note from corporate customer
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-notes-id-delete
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomerNoteDelete(12)
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerNoteDelete ( id int ) ( SuccessfulResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp SuccessfulResponse
p := url . Values {
2021-04-16 14:25:25 +03:00
"id" : { strconv . Itoa ( id ) } ,
2019-10-16 16:32:31 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/notes/%d/delete" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomersUpload corporate customers batch upload
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-upload
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomersUpload([]retailcrm.CorporateCustomer{
2019-10-16 16:32:31 +03:00
// {
// Nickname: "Company",
// ExternalID: 1,
// },
// {
// Nickname: "Company 2",
// ExternalID: 2,
// },
// }}
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.UploadedCustomers)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomersUpload (
customers [ ] CorporateCustomer , site ... string ,
) ( CorporateCustomersUploadResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomersUploadResponse
uploadJSON , _ := json . Marshal ( & customers )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customersCorporate" : { string ( uploadJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/customers-corporate/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomer returns information about corporate customer
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate-externalId
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CorporateCustomer(12, retailcrm.ByExternalID, "")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.CorporateCustomer)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomer ( id , by , site string ) ( CorporateCustomerResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomerResponse
var context = checkBy ( by )
fw := CustomerRequest { context , site }
params , _ := query . Values ( fw )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/%s?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerAddresses returns information about corporate customer addresses
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate-externalId-addresses
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.CorporateCustomerAddresses("ext-id", retailcrm.CorporateCustomerAddressesRequest{
// Filter: v5,CorporateCustomerAddressesFilter{
// Name: "Main Address",
// },
// By: retailcrm.ByExternalID,
// Site: "site",
// Limit: 20,
// Page: 1,
// })
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v\n", data.Addresses)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerAddresses (
id string , parameters CorporateCustomerAddressesRequest ,
) ( CorporateCustomersAddressesResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomersAddressesResponse
parameters . By = checkBy ( parameters . By )
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/%s/addresses?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerAddressesCreate creates corporate customer address
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-addresses-create
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerAddressesCreate("ext-id", retailcrm.ByExternalID, retailcrm.CorporateCustomerAddress{
// Text: "this is new address",
// Name: "New Address",
// })
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
// if data.Success == true {
// fmt.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerAddressesCreate (
id string , by string , address CorporateCustomerAddress , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CreateResponse
addressJSON , _ := json . Marshal ( & address )
p := url . Values {
2021-10-27 15:49:06 +03:00
"address" : { string ( addressJSON ) } ,
"by" : { checkBy ( by ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/addresses/create" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
2021-10-27 15:49:06 +03:00
// CorporateCustomerAddressesEdit edit exact corporate customer address
2019-10-16 16:32:31 +03:00
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-addresses-entityExternalId-edit
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerAddressesEdit(
// "customer-ext-id",
// retailcrm.ByExternalID,
// retailcrm.ByExternalID,
// CorporateCustomerAddress{
// ExternalID: "addr-ext-id",
// Name: "Main Address 2",
// },
// )
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v\n", data.Customer)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerAddressesEdit (
customerID , customerBy , entityBy string , address CorporateCustomerAddress , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var (
resp CreateResponse
uid string
)
customerBy = checkBy ( customerBy )
entityBy = checkBy ( entityBy )
switch entityBy {
2021-10-27 15:49:06 +03:00
case ByID :
2019-10-16 16:32:31 +03:00
uid = strconv . Itoa ( address . ID )
2021-10-27 15:49:06 +03:00
case ByExternalID :
2019-10-16 16:32:31 +03:00
uid = address . ExternalID
}
addressJSON , _ := json . Marshal ( & address )
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { customerBy } ,
"entityBy" : { entityBy } ,
"address" : { string ( addressJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/addresses/%s/edit" , customerID , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerCompanies returns information about corporate customer companies
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate-externalId-companies
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.CorporateCustomerCompanies("ext-id", retailcrm.IdentifiersPairRequest{
// Filter: v5,IdentifiersPairFilter{
// Ids: []string{"1"},
// },
// By: retailcrm.ByExternalID,
// Site: "site",
// Limit: 20,
// Page: 1,
// })
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v\n", data.Companies)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerCompanies (
id string , parameters IdentifiersPairRequest ,
) ( CorporateCustomerCompaniesResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomerCompaniesResponse
parameters . By = checkBy ( parameters . By )
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/%s/companies?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerCompaniesCreate creates corporate customer company
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-companies-create
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerCompaniesCreate("ext-id", retailcrm.ByExternalID, retailcrm.Company{
// Name: "Company name",
// })
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
// if data.Success == true {
// fmt.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerCompaniesCreate (
id string , by string , company Company , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CreateResponse
companyJSON , _ := json . Marshal ( & company )
p := url . Values {
2021-10-27 15:49:06 +03:00
"company" : { string ( companyJSON ) } ,
"by" : { checkBy ( by ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/companies/create" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerCompaniesEdit edit exact corporate customer company
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-companies-entityExternalId-edit
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerCompaniesEdit(
// "customer-ext-id",
// retailcrm.ByExternalID,
// retailcrm.ByExternalID,
// Company{
// ExternalID: "company-ext-id",
// Name: "New Company Name",
// },
// )
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerCompaniesEdit (
customerID , customerBy , entityBy string , company Company , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var (
resp CreateResponse
uid string
)
customerBy = checkBy ( customerBy )
entityBy = checkBy ( entityBy )
switch entityBy {
2021-10-27 15:49:06 +03:00
case ByID :
2019-10-16 16:32:31 +03:00
uid = strconv . Itoa ( company . ID )
2021-10-27 15:49:06 +03:00
case ByExternalID :
2019-10-16 16:32:31 +03:00
uid = company . ExternalID
}
addressJSON , _ := json . Marshal ( & company )
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { customerBy } ,
"entityBy" : { entityBy } ,
"company" : { string ( addressJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/companies/%s/edit" , customerID , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerContacts returns information about corporate customer contacts
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-customers-corporate-externalId-contacts
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.CorporateCustomerContacts("ext-id", retailcrm.IdentifiersPairRequest{
// Filter: retailcrm.IdentifiersPairFilter{
// Ids: []string{"1"},
// },
// By: retailcrm.ByExternalID,
// Site: "site",
// Limit: 20,
// Page: 1,
// })
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v\n", data.Contacts)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerContacts (
id string , parameters IdentifiersPairRequest ,
) ( CorporateCustomerContactsResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CorporateCustomerContactsResponse
parameters . By = checkBy ( parameters . By )
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/customers-corporate/%s/contacts?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerContactsCreate creates corporate customer contact
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-contacts-create
//
// Example (customer with specified id or externalId should exist in specified site):
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerContactsCreate("ext-id", retailcrm.ByExternalID, retailcrm.CorporateCustomerContact{
// IsMain: false,
// Customer: retailcrm.CorporateCustomerContactCustomer{
// ExternalID: "external_id",
// Site: "site",
// },
// Companies: []IdentifiersPair{},
// }, "site")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
// if data.Success == true {
// fmt.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerContactsCreate (
id string , by string , contact CorporateCustomerContact , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var resp CreateResponse
companyJSON , _ := json . Marshal ( & contact )
p := url . Values {
2021-10-27 15:49:06 +03:00
"contact" : { string ( companyJSON ) } ,
"by" : { checkBy ( by ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/contacts/create" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerContactsEdit edit exact corporate customer contact
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-contacts-entityExternalId-edit
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := c.CorporateCustomerContactsEdit("ext-id", retailcrm.ByExternalID, retailcrm.ByID, retailcrm.CorporateCustomerContact{
// IsMain: false,
// Customer: retailcrm.CorporateCustomerContactCustomer{
// ID: 2350,
// },
// }, "site")
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerContactsEdit (
customerID , customerBy , entityBy string , contact CorporateCustomerContact , site ... string ,
) ( CreateResponse , int , error ) {
2019-10-16 16:32:31 +03:00
var (
resp CreateResponse
uid string
)
customerBy = checkBy ( customerBy )
entityBy = checkBy ( entityBy )
switch entityBy {
2021-10-27 15:49:06 +03:00
case ByID :
2019-10-16 16:32:31 +03:00
uid = strconv . Itoa ( contact . Customer . ID )
2021-10-27 15:49:06 +03:00
case ByExternalID :
2019-10-16 16:32:31 +03:00
uid = contact . Customer . ExternalID
}
addressJSON , _ := json . Marshal ( & contact )
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { customerBy } ,
"entityBy" : { entityBy } ,
"contact" : { string ( addressJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/contacts/%s/edit" , customerID , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
// CorporateCustomerEdit edit exact corporate customer
//
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-externalId-edit
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-10-16 16:32:31 +03:00
//
// data, status, err := client.CorporateCustomerEdit(
2021-10-27 15:49:06 +03:00
// retailcrm.CorporateCustomer{
2019-10-16 16:32:31 +03:00
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// ID: 1,
// Email: "ivanov@example.com",
// },
2021-10-27 15:49:06 +03:00
// retailcrm.ByID,
2019-10-16 16:32:31 +03:00
// )
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-10-16 16:32:31 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.Customer)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CorporateCustomerEdit ( customer CorporateCustomer , by string , site ... string ) (
CustomerChangeResponse , int , error ,
) {
2019-10-16 16:32:31 +03:00
var resp CustomerChangeResponse
var uid = strconv . Itoa ( customer . ID )
var context = checkBy ( by )
if context == ByExternalID {
uid = customer . ExternalID
}
customerJSON , _ := json . Marshal ( & customer )
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { context } ,
"customerCorporate" : { string ( customerJSON ) } ,
2019-10-16 16:32:31 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/customers-corporate/%s/edit" , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-10-16 16:32:31 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-10-16 16:32:31 +03:00
return resp , status , nil
}
2018-09-28 01:37:56 +03:00
// DeliveryTracking updates tracking data
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-generic-subcode-tracking
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
// t, _ := time.Parse("2006-01-02 15:04:05", "2012-12-12 12:12:12")
//
// data, status, err := client.DeliveryTracking(
// []retailcrm.DeliveryTrackingRequest{{
// DeliveryID: "1",
// TrackNumber: "123",
// History: []retailcrm.DeliveryHistoryRecord{
// {
// Code: "cancel",
// UpdatedAt: t.Format(time.RFC3339),
// },
2018-04-12 16:43:53 +03:00
// },
2022-11-24 13:37:21 +03:00
// }},
// "delivery-1",
// )
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryTracking ( parameters [ ] DeliveryTrackingRequest , subcode string ) (
SuccessfulResponse , int , error ,
) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
updateJSON , _ := json . Marshal ( & parameters )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"statusUpdate" : { string ( updateJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/delivery/generic/%s/tracking" , subcode ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// DeliveryShipments returns list of shipments
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-delivery-shipments
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.DeliveryShipments(retailcrm.DeliveryShipmentsRequest{
2018-04-12 16:43:53 +03:00
// Limit: 12,
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.ShipmentFilter{
2018-04-12 16:43:53 +03:00
// DateFrom: "2012-12-12",
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.DeliveryShipments {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryShipments ( parameters DeliveryShipmentsRequest ) ( DeliveryShipmentsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp DeliveryShipmentsResponse
2018-02-27 11:37:15 +03:00
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/delivery/shipments?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// DeliveryShipmentCreate creates shipment
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-shipments-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// data, status, err := client.DeliveryShipmentCreate(
2021-10-27 15:49:06 +03:00
// retailcrm.DeliveryShipment{
2018-04-12 16:43:53 +03:00
// Date: "2012-12-12",
2021-10-27 15:49:06 +03:00
// Time: retailcrm.DeliveryTime{
2018-04-12 16:43:53 +03:00
// From: "18:00",
// To: "20:00",
2018-04-23 16:28:54 +03:00
// },
2021-10-27 15:49:06 +03:00
// Orders: []retailcrm.Order{{Number: "12"}},
2018-04-23 16:28:54 +03:00
// },
// "sdek",
// )
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryShipmentCreate (
shipment DeliveryShipment , deliveryType string , site ... string ,
) ( DeliveryShipmentUpdateResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp DeliveryShipmentUpdateResponse
updateJSON , _ := json . Marshal ( & shipment )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"deliveryType" : { deliveryType } ,
"deliveryShipment" : { string ( updateJSON ) } ,
2018-03-21 00:54:37 +03:00
}
fillSite ( & p , site )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/delivery/shipments/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryShipment get information about shipment
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-delivery-shipments-id
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.DeliveryShipment(12)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.DeliveryShipment)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryShipment ( id int ) ( DeliveryShipmentResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp DeliveryShipmentResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/delivery/shipments/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryShipmentEdit shipment editing
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-shipments-id-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.DeliveryShipmentEdit(retailcrm.DeliveryShipment{
2018-04-12 16:43:53 +03:00
// ID: "12",
2021-10-27 15:49:06 +03:00
// Time: retailcrm.DeliveryTime{
2018-04-12 16:43:53 +03:00
// From: "14:00",
// To: "18:00",
// },
2022-11-24 13:37:21 +03:00
// })
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryShipmentEdit ( shipment DeliveryShipment , site ... string ) (
DeliveryShipmentUpdateResponse , int , error ,
) {
2018-03-21 00:54:37 +03:00
var resp DeliveryShipmentUpdateResponse
updateJSON , _ := json . Marshal ( & shipment )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"deliveryShipment" : { string ( updateJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/delivery/shipments/%s/edit" , strconv . Itoa ( shipment . ID ) ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// IntegrationModule returns integration module
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-integration-modules-code
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.IntegrationModule("moysklad3")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.IntegrationModule)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) IntegrationModule ( code string ) ( IntegrationModuleResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp IntegrationModuleResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/integration-modules/%s" , code ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-09-28 13:46:09 +03:00
// IntegrationModuleEdit integration module create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-integration-modules-code
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-23 16:28:54 +03:00
//
2018-04-12 16:43:53 +03:00
// name := "MS"
// code := "moysklad3"
2018-04-23 16:28:54 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.IntegrationModuleEdit(retailcrm.IntegrationModule{
2018-04-12 16:43:53 +03:00
// Code: code,
// IntegrationCode: code,
// Active: false,
// Name: fmt.Sprintf("Integration module %s", name),
// AccountURL: fmt.Sprintf("http://example.com/%s/account", name),
// BaseURL: fmt.Sprintf("http://example.com/%s", name),
// ClientID: "123",
// Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg",
// })
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if data.Success == true {
// fmt.Printf("%v\n", data.Info)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) IntegrationModuleEdit ( integrationModule IntegrationModule ) (
IntegrationModuleEditResponse , int , error ,
) {
2018-03-21 00:54:37 +03:00
var resp IntegrationModuleEditResponse
updateJSON , _ := json . Marshal ( & integrationModule )
2021-10-27 15:49:06 +03:00
p := url . Values { "integrationModule" : { string ( updateJSON ) } }
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/integration-modules/%s/edit" , integrationModule . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2022-04-01 17:22:53 +03:00
// UpdateScopes updates permissions for the API key
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-integration-modules-code-update-scopes
2022-04-01 17:22:53 +03:00
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
2022-04-13 17:32:26 +03:00
// data, status, err := client.UpdateScopes("moysklad3", retailcrm.ScopesRequired{
// Scopes: []string{"scope1", "scope2"},
2022-04-01 17:22:53 +03:00
// })
//
// if err.Error() != "" {
// fmt.Printf("%v", err.Error())
// }
//
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.Error())
// }
//
// if data.Success == true {
// fmt.Printf("%v\n", data.APIKey)
// }
2022-04-12 15:37:15 +03:00
func ( c * Client ) UpdateScopes ( code string , request ScopesRequired ) ( UpdateScopesResponse , int , error ) {
2022-04-01 17:22:53 +03:00
var resp UpdateScopesResponse
updateJSON , _ := json . Marshal ( & request )
2022-04-12 15:37:15 +03:00
p := url . Values {
"requires" : { string ( updateJSON ) } ,
}
2022-04-13 17:32:26 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/integration-modules/%s/update-scopes" , code ) , p )
2022-04-01 17:22:53 +03:00
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
return resp , status , nil
}
2018-09-28 13:46:09 +03:00
// Orders returns list of orders matched the specified filters
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Orders(retailcrm.OrdersRequest{Filter: retailcrm.OrdersFilter{City: "Moscow"}, Page: 1})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Orders {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Orders ( parameters OrdersRequest ) ( OrdersResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp OrdersResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrdersCombine combines given orders
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-combine
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrdersCombine("ours", retailcrm.Order{ID: 1}, retailcrm.Order{ID: 1})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrdersCombine ( technique string , order , resultOrder Order ) ( OperationResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp OperationResponse
2018-03-19 23:18:36 +03:00
combineJSONIn , _ := json . Marshal ( & order )
combineJSONOut , _ := json . Marshal ( & resultOrder )
2018-02-27 11:37:15 +03:00
p := url . Values {
"technique" : { technique } ,
2021-10-27 15:49:06 +03:00
"order" : { string ( combineJSONIn ) } ,
"resultOrder" : { string ( combineJSONOut ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/orders/combine" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderCreate creates an order
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderCreate(retailcrm.Order{
2018-04-12 16:43:53 +03:00
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// Email: "ivanov@example.com",
2021-10-27 15:49:06 +03:00
// Items: []retailcrm.OrderItem{{Offer: retailcrm.Offer{ID: 12}, Quantity: 5}},
2018-04-12 16:43:53 +03:00
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderCreate ( order Order , site ... string ) ( OrderCreateResponse , int , error ) {
2020-07-14 11:51:35 +03:00
var resp OrderCreateResponse
2018-03-21 00:54:37 +03:00
orderJSON , _ := json . Marshal ( & order )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"order" : { string ( orderJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/orders/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrdersFixExternalIds set order external ID
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-fix-external-ids
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.OrdersFixExternalIds(([]retailcrm.IdentifiersPair{{
2018-04-23 16:28:54 +03:00
// ID: 1,
// ExternalID: 12,
// }})
2018-04-12 16:43:53 +03:00
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if data.Success == true {
// fmt.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrdersFixExternalIds ( orders [ ] IdentifiersPair ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
ordersJSON , _ := json . Marshal ( & orders )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"orders" : { string ( ordersJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/orders/fix-external-ids" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrdersHistory returns orders history
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-history
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrdersHistory(retailcrm.OrdersHistoryRequest{Filter: retailcrm.OrdersHistoryFilter{SinceID: 20}})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.History {
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrdersHistory ( parameters OrdersHistoryRequest ) ( OrdersHistoryResponse , int , error ) {
2019-08-09 16:45:48 +03:00
var resp OrdersHistoryResponse
2018-02-27 11:37:15 +03:00
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/history?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderPaymentCreate creates payment
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-payments-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderPaymentCreate(retailcrm.Payment{
2021-10-27 15:49:06 +03:00
// Order: &retailcrm.Order{
2018-04-12 16:43:53 +03:00
// ID: 12,
// },
// Amount: 300,
// Type: "cash",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderPaymentCreate ( payment Payment , site ... string ) ( CreateResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CreateResponse
2018-03-21 00:54:37 +03:00
paymentJSON , _ := json . Marshal ( & payment )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"payment" : { string ( paymentJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/orders/payments/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 01:37:56 +03:00
// OrderPaymentDelete payment removing
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-payments-id-delete
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderPaymentDelete(12)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderPaymentDelete ( id int ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-04-16 14:25:25 +03:00
"id" : { strconv . Itoa ( id ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/orders/payments/%d/delete" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderPaymentEdit edit payment
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-payments-id-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderPaymentEdit(
// retailcrm.Payment{
2018-04-12 16:43:53 +03:00
// ID: 12,
// Amount: 500,
// },
2021-10-27 15:49:06 +03:00
// retailcrm.ByID,
2018-04-12 16:43:53 +03:00
// )
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderPaymentEdit ( payment Payment , by string , site ... string ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
var uid = strconv . Itoa ( payment . ID )
var context = checkBy ( by )
2018-02-27 11:37:15 +03:00
2019-10-16 16:32:31 +03:00
if context == ByExternalID {
2018-03-21 00:54:37 +03:00
uid = payment . ExternalID
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
paymentJSON , _ := json . Marshal ( & payment )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2020-08-03 12:56:15 +03:00
"by" : { context } ,
2021-10-27 15:49:06 +03:00
"payment" : { string ( paymentJSON ) } ,
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/orders/payments/%s/edit" , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2020-06-29 16:33:14 +03:00
// OrdersStatuses returns orders statuses
2020-06-29 16:26:10 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-statuses
2020-06-29 16:26:10 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2020-06-29 16:26:10 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrdersStatuses(retailcrm.OrdersStatusesRequest{
2020-06-29 16:26:10 +03:00
// IDs: []int{1},
// ExternalIDs: []string{"2"},
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2020-06-29 16:26:10 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrdersStatuses ( request OrdersStatusesRequest ) ( OrdersStatusesResponse , int , error ) {
2020-06-29 16:26:10 +03:00
var resp OrdersStatusesResponse
params , _ := query . Values ( request )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/statuses?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2020-06-29 16:26:10 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2020-06-29 16:26:10 +03:00
return resp , status , nil
}
2018-09-28 13:46:09 +03:00
// OrdersUpload batch orders uploading
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-upload
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrdersUpload([]retailcrm.Order{
2018-04-12 16:43:53 +03:00
// {
// FirstName: "Ivan",
// LastName: "Ivanov",
// Patronymic: "Ivanovich",
// Email: "ivanov@example.com",
2021-10-27 15:49:06 +03:00
// Items: []retailcrm.OrderItem{{Offer: retailcrm.Offer{ID: 12}, Quantity: 5}},
2018-04-12 16:43:53 +03:00
// },
// {
// FirstName: "Pert",
// LastName: "Petrov",
// Patronymic: "Petrovich",
// Email: "petrov@example.com",
2021-10-27 15:49:06 +03:00
// Items: []retailcrm.OrderItem{{Offer: retailcrm.Offer{ID: 13}, Quantity: 1}},
2018-04-12 16:43:53 +03:00
// }
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.UploadedOrders)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrdersUpload ( orders [ ] Order , site ... string ) ( OrdersUploadResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp OrdersUploadResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
uploadJSON , _ := json . Marshal ( & orders )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"orders" : { string ( uploadJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/orders/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Order returns information about order
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-externalId
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Order(12, retailcrm.ByExternalID, "")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.Order)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Order ( id , by , site string ) ( OrderResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp OrderResponse
var context = checkBy ( by )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
fw := OrderRequest { context , site }
params , _ := query . Values ( fw )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/%s?%s" , id , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderEdit edit an order
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-externalId-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderEdit(
// retailcrm.Order{
2018-04-12 16:43:53 +03:00
// ID: 12,
2021-10-27 15:49:06 +03:00
// Items: []retailcrm.OrderItem{{Offer: retailcrm.Offer{ID: 13}, Quantity: 6}},
2018-04-12 16:43:53 +03:00
// },
2022-11-24 13:37:21 +03:00
// retailcrm.ByID,
// )
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderEdit ( order Order , by string , site ... string ) ( CreateResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CreateResponse
2018-03-21 00:54:37 +03:00
var uid = strconv . Itoa ( order . ID )
var context = checkBy ( by )
2018-02-27 11:37:15 +03:00
2019-10-16 16:32:31 +03:00
if context == ByExternalID {
2018-03-21 00:54:37 +03:00
uid = order . ExternalID
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
orderJSON , _ := json . Marshal ( & order )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"by" : { context } ,
"order" : { string ( orderJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/orders/%s/edit" , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Packs returns list of packs matched the specified filters
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-packs
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Packs(retailcrm.PacksRequest{Filter: retailcrm.PacksFilter{OrderID: 12}})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Packs {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Packs ( parameters PacksRequest ) ( PacksResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PacksResponse
2018-02-27 11:37:15 +03:00
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/packs?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PackCreate creates a pack
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-packs-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.PackCreate(Pack{
2018-04-12 16:43:53 +03:00
// Store: "store-1",
// ItemID: 12,
// Quantity: 1,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) PackCreate ( pack Pack ) ( CreateResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CreateResponse
2018-03-21 00:54:37 +03:00
packJSON , _ := json . Marshal ( & pack )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"pack" : { string ( packJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/orders/packs/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PacksHistory returns a history of order packing
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-packs-history
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.PacksHistory(retailcrm.PacksHistoryRequest{Filter: retailcrm.OrdersHistoryFilter{SinceID: 5}})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.History {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) PacksHistory ( parameters PacksHistoryRequest ) ( PacksHistoryResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PacksHistoryResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/packs/history?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Pack returns a pack info
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-orders-packs-id
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Pack(112)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.Pack)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Pack ( id int ) ( PackResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PackResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/orders/packs/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PackDelete removes a pack
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-packs-id-delete
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.PackDelete(112)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) PackDelete ( id int ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/orders/packs/%d/delete" , id ) , url . Values { } )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PackEdit edit a pack
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-packs-id-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.PackEdit(Pack{ID: 12, Quantity: 2})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) PackEdit ( pack Pack ) ( CreateResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CreateResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
packJSON , _ := json . Marshal ( & pack )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"pack" : { string ( packJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/orders/packs/%d/edit" , pack . ID ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Countries returns list of available country codes
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-countries
2021-04-26 12:09:21 +03:00
func ( c * Client ) Countries ( ) ( CountriesResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CountriesResponse
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/countries" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CostGroups returns costs groups list
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-cost-groups
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostGroups ( ) ( CostGroupsResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp CostGroupsResponse
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/cost-groups" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CostGroupEdit edit costs groups
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-cost-groups-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CostGroupEdit(retailcrm.CostGroup{
2018-04-12 16:43:53 +03:00
// Code: "group-1",
// Color: "#da5c98",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostGroupEdit ( costGroup CostGroup ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & costGroup )
p := url . Values {
2021-10-27 15:49:06 +03:00
"costGroup" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/cost-groups/%s/edit" , costGroup . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CostItems returns costs items list
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-cost-items
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostItems ( ) ( CostItemsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CostItemsResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/cost-items" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CostItemEdit edit costs items
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-cost-items-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CostItemEdit(retailcrm.CostItem{
2018-04-12 16:43:53 +03:00
// Code: "seo",
// Active: false,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostItemEdit ( costItem CostItem ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & costItem )
p := url . Values {
2021-10-27 15:49:06 +03:00
"costItem" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/cost-items/%s/edit" , costItem . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Couriers returns list of couriers
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-couriers
2021-04-26 12:09:21 +03:00
func ( c * Client ) Couriers ( ) ( CouriersResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CouriersResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/couriers" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CourierCreate creates a courier
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-couriers
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CostItemEdit(retailcrm.Courier{
2018-04-12 16:43:53 +03:00
// Active: true,
// Email: "courier1@example.com",
// FirstName: "Ivan",
// LastName: "Ivanov",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if data.Success == true {
// log.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CourierCreate ( courier Courier ) ( CreateResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CreateResponse
objJSON , _ := json . Marshal ( & courier )
p := url . Values {
2021-10-27 15:49:06 +03:00
"courier" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/reference/couriers/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// CourierEdit edit a courier
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-couriers-id-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.CostItemEdit(retailcrm.Courier{
2018-04-12 16:43:53 +03:00
// ID: 1,
// Patronymic: "Ivanovich",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CourierEdit ( courier Courier ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & courier )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"courier" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/couriers/%d/edit" , courier . ID ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryServices returns list of delivery services
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-delivery-services
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryServices ( ) ( DeliveryServiceResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp DeliveryServiceResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/delivery-services" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryServiceEdit delivery service create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-delivery-services-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.DeliveryServiceEdit(retailcrm.DeliveryService{
2018-04-12 16:43:53 +03:00
// Active: false,
// Code: "delivery-1",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryServiceEdit ( deliveryService DeliveryService ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & deliveryService )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"deliveryService" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/delivery-services/%s/edit" , deliveryService . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryTypes returns list of delivery types
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-delivery-types
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryTypes ( ) ( DeliveryTypesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp DeliveryTypesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/delivery-types" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// DeliveryTypeEdit delivery type create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-delivery-types-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.DeliveryTypeEdit(retailcrm.DeliveryType{
2018-04-12 16:43:53 +03:00
// Active: false,
// Code: "type-1",
// DefaultCost: 300,
// DefaultForCrm: false,
// }
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) DeliveryTypeEdit ( deliveryType DeliveryType ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & deliveryType )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"deliveryType" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/delivery-types/%s/edit" , deliveryType . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// LegalEntities returns list of legal entities
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-legal-entities
2021-04-26 12:09:21 +03:00
func ( c * Client ) LegalEntities ( ) ( LegalEntitiesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp LegalEntitiesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/legal-entities" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// LegalEntityEdit change information about legal entity
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-legal-entities-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.LegalEntityEdit(retailcrm.LegalEntity{
2018-04-12 16:43:53 +03:00
// Code: "legal-entity-1",
// CertificateDate: "2012-12-12",
// }
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) LegalEntityEdit ( legalEntity LegalEntity ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & legalEntity )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"legalEntity" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/legal-entities/%s/edit" , legalEntity . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderMethods returns list of order methods
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-order-methods
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderMethods ( ) ( OrderMethodsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp OrderMethodsResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/order-methods" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderMethodEdit order method create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-order-methods-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderMethodEdit(retailcrm.OrderMethod{
2018-04-12 16:43:53 +03:00
// Code: "method-1",
// Active: false,
// DefaultForCRM: false,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderMethodEdit ( orderMethod OrderMethod ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & orderMethod )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"orderMethod" : { string ( objJSON ) } ,
2018-03-21 00:54:37 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/order-methods/%s/edit" , orderMethod . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderTypes return list of order types
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-order-types
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderTypes ( ) ( OrderTypesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp OrderTypesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/order-types" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// OrderTypeEdit create/edit order type
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-order-methods-code-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.OrderTypeEdit(retailcrm.OrderType{
2018-04-12 16:43:53 +03:00
// Code: "order-type-1",
// Active: false,
// DefaultForCRM: false,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) OrderTypeEdit ( orderType OrderType ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & orderType )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"orderType" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/order-types/%s/edit" , orderType . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PaymentStatuses returns list of payment statuses
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-payment-statuses
2021-04-26 12:09:21 +03:00
func ( c * Client ) PaymentStatuses ( ) ( PaymentStatusesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PaymentStatusesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/payment-statuses" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PaymentStatusEdit payment status creation/editing
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-payment-statuses-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) PaymentStatusEdit ( paymentStatus PaymentStatus ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & paymentStatus )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"paymentStatus" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/payment-statuses/%s/edit" , paymentStatus . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PaymentTypes returns list of payment types
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-payment-types
2021-04-26 12:09:21 +03:00
func ( c * Client ) PaymentTypes ( ) ( PaymentTypesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PaymentTypesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/payment-types" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PaymentTypeEdit payment type create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-payment-types-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) PaymentTypeEdit ( paymentType PaymentType ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & paymentType )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"paymentType" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/payment-types/%s/edit" , paymentType . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PriceTypes returns list of price types
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-price-types
2021-04-26 12:09:21 +03:00
func ( c * Client ) PriceTypes ( ) ( PriceTypesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp PriceTypesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/price-types" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PriceTypeEdit price type create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-price-types-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) PriceTypeEdit ( priceType PriceType ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & priceType )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"priceType" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/price-types/%s/edit" , priceType . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// ProductStatuses returns list of item statuses in order
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-product-statuses
2021-04-26 12:09:21 +03:00
func ( c * Client ) ProductStatuses ( ) ( ProductStatusesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp ProductStatusesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/product-statuses" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// ProductStatusEdit order item status create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-product-statuses-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) ProductStatusEdit ( productStatus ProductStatus ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & productStatus )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"productStatus" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/product-statuses/%s/edit" , productStatus . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Sites returns the sites list
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-sites
2021-04-26 12:09:21 +03:00
func ( c * Client ) Sites ( ) ( SitesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SitesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/sites" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// SiteEdit site create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-sites-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) SiteEdit ( site Site ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
objJSON , _ := json . Marshal ( & site )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"site" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/sites/%s/edit" , site . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// StatusGroups returns list of order status groups
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-status-groups
2021-04-26 12:09:21 +03:00
func ( c * Client ) StatusGroups ( ) ( StatusGroupsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp StatusGroupsResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/status-groups" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Statuses returns list of order statuses
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-statuses
2021-04-26 12:09:21 +03:00
func ( c * Client ) Statuses ( ) ( StatusesResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp StatusesResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/statuses" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// StatusEdit order status create/edit
2018-04-12 16:43:53 +03:00
//
2021-04-26 12:09:21 +03:00
// For more information see www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit.
func ( c * Client ) StatusEdit ( st Status ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-19 23:18:36 +03:00
objJSON , _ := json . Marshal ( & st )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"status" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/statuses/%s/edit" , st . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Stores returns list of warehouses
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-stores
2021-04-26 12:09:21 +03:00
func ( c * Client ) Stores ( ) ( StoresResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp StoresResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/reference/stores" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// StoreEdit warehouse create/edit
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-stores-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) StoreEdit ( store Store ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-19 23:18:36 +03:00
objJSON , _ := json . Marshal ( & store )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"store" : { string ( objJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/stores/%s/edit" , store . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-03-21 00:54:37 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2019-02-20 10:07:02 +03:00
// Units returns units list
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-reference-units
2021-04-26 12:09:21 +03:00
func ( c * Client ) Units ( ) ( UnitsResponse , int , error ) {
2019-02-20 10:07:02 +03:00
var resp UnitsResponse
data , status , err := c . GetRequest ( "/reference/units" )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-02-20 10:07:02 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-02-20 10:07:02 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2019-02-20 10:07:02 +03:00
}
// UnitEdit unit create/edit
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-reference-units-code-edit
2021-04-26 12:09:21 +03:00
func ( c * Client ) UnitEdit ( unit Unit ) ( SuccessfulResponse , int , error ) {
2019-02-20 10:07:02 +03:00
var resp SuccessfulResponse
objJSON , _ := json . Marshal ( & unit )
p := url . Values {
2021-10-27 15:49:06 +03:00
"unit" : { string ( objJSON ) } ,
2019-02-20 10:07:02 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/reference/units/%s/edit" , unit . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-02-20 10:07:02 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-02-20 10:07:02 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2019-02-20 10:07:02 +03:00
}
2018-09-28 13:46:09 +03:00
// Segments returns segments
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-segments
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// data, status, err := client.Segments(SegmentsRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.SegmentsFilter{
2018-04-23 16:28:54 +03:00
// Ids: []int{1,2,3}
// }
// })
2018-04-12 16:43:53 +03:00
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Segments {
2018-04-23 16:28:54 +03:00
// fmt.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Segments ( parameters SegmentsRequest ) ( SegmentsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SegmentsResponse
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/segments?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2020-07-14 10:22:36 +03:00
// Settings returns system settings
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-settings
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2020-07-14 10:22:36 +03:00
//
// data, status, err := client.Settings()
//
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2020-07-14 10:22:36 +03:00
// }
//
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2020-07-14 10:22:36 +03:00
// }
//
// fmt.Printf("%#v\n", data)
2021-04-26 12:09:21 +03:00
func ( c * Client ) Settings ( ) ( SettingsResponse , int , error ) {
2020-07-14 10:22:36 +03:00
var resp SettingsResponse
data , status , err := c . GetRequest ( "/settings" )
2021-04-26 12:09:21 +03:00
if err != nil {
2020-07-14 10:22:36 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2020-07-14 10:22:36 +03:00
return resp , status , nil
}
2018-09-28 13:46:09 +03:00
// Inventories returns leftover stocks and purchasing prices
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-store-inventories
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Inventories(retailcrm.InventoriesRequest{Filter: retailcrm.InventoriesFilter{Details: 1, ProductActive: 1}, Page: 1})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Offers {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Inventories ( parameters InventoriesRequest ) ( InventoriesResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp InventoriesResponse
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/store/inventories?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// InventoriesUpload updates the leftover stocks and purchasing prices
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-store-inventories-upload
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2018-09-28 13:46:09 +03:00
// data, status, err := client.InventoriesUpload(
2021-10-27 15:49:06 +03:00
// []retailcrm.InventoryUpload{
2018-04-23 16:28:54 +03:00
// {
2018-09-28 13:46:09 +03:00
// XMLID: "pT22K9YzX21HTdzFCe1",
2018-04-23 16:28:54 +03:00
// Stores: []InventoryUploadStore{
// {Code: "test-store-v5", Available: 10, PurchasePrice: 1500},
// {Code: "test-store-v4", Available: 20, PurchasePrice: 1530},
// {Code: "test-store", Available: 30, PurchasePrice: 1510},
// },
// },
// {
2018-09-28 13:46:09 +03:00
// XMLID: "JQICtiSpOV3AAfMiQB3",
2018-04-23 16:28:54 +03:00
// Stores: []InventoryUploadStore{
// {Code: "test-store-v5", Available: 45, PurchasePrice: 1500},
// {Code: "test-store-v4", Available: 32, PurchasePrice: 1530},
// {Code: "test-store", Available: 46, PurchasePrice: 1510},
// },
// },
// },
// )
2018-04-12 16:43:53 +03:00
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// fmt.Printf("%v\n", data.NotFoundOffers)
2021-04-26 12:09:21 +03:00
func ( c * Client ) InventoriesUpload ( inventories [ ] InventoryUpload , site ... string ) ( StoreUploadResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp StoreUploadResponse
2018-03-19 23:18:36 +03:00
uploadJSON , _ := json . Marshal ( & inventories )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"offers" : { string ( uploadJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/store/inventories/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// PricesUpload updates prices
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-store-prices-upload
2018-04-12 16:43:53 +03:00
//
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.PricesUpload([]retailcrm.OfferPriceUpload{
2018-04-23 16:28:54 +03:00
// {
2018-04-12 16:43:53 +03:00
// ID 1
// Site "store-1"
// Prices []PriceUpload{{Code: "price-1"}}
2018-04-23 16:28:54 +03:00
// },
// {
2018-04-12 16:43:53 +03:00
// ID 2
// Site "store-1"
// Prices []PriceUpload{{Code: "price-2"}}
2018-04-23 16:28:54 +03:00
// },
// })
2018-04-12 16:43:53 +03:00
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-23 16:28:54 +03:00
// }
2018-04-12 16:43:53 +03:00
//
2018-04-23 16:28:54 +03:00
// fmt.Printf("%v\n", data.NotFoundOffers)
2021-04-26 12:09:21 +03:00
func ( c * Client ) PricesUpload ( prices [ ] OfferPriceUpload ) ( StoreUploadResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp StoreUploadResponse
2018-03-19 23:18:36 +03:00
uploadJSON , _ := json . Marshal ( & prices )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"prices" : { string ( uploadJSON ) } ,
2018-02-27 11:37:15 +03:00
}
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( "/store/prices/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// ProductsGroup returns list of product groups
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-store-product-groups
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.ProductsGroup(retailcrm.ProductsGroupsRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.ProductsGroupsFilter{
2018-04-12 16:43:53 +03:00
// Active: 1,
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.ProductGroup {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) ProductsGroup ( parameters ProductsGroupsRequest ) ( ProductsGroupsResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp ProductsGroupsResponse
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/store/product-groups?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Products returns list of products and SKU
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-store-products
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Products(retailcrm.ProductsRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.ProductsFilter{
2018-04-12 16:43:53 +03:00
// Active: 1,
// MinPrice: 1000,
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Products {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Products ( parameters ProductsRequest ) ( ProductsResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp ProductsResponse
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/store/products?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// ProductsProperties returns list of item properties, matching the specified filters
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-store-products-properties
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.ProductsProperties(retailcrm.ProductsPropertiesRequest{
2021-10-27 15:49:06 +03:00
// Filter: retailcrm.ProductsPropertiesFilter{
2018-04-12 16:43:53 +03:00
// Sites: []string["store"],
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Properties {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) ProductsProperties ( parameters ProductsPropertiesRequest ) ( ProductsPropertiesResponse , int , error ) {
2018-02-27 11:37:15 +03:00
var resp ProductsPropertiesResponse
params , _ := query . Values ( parameters )
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/store/products/properties?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Tasks returns task list
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-tasks
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Tasks(retailcrm.TasksRequest{
2018-04-12 16:43:53 +03:00
// Filter: TasksFilter{
// DateFrom: "2012-12-12",
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Tasks {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Tasks ( parameters TasksRequest ) ( TasksResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp TasksResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/tasks?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// TaskCreate create a task
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-tasks-create
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Tasks(retailcrm.Task{
2018-04-12 16:43:53 +03:00
// Text: "task №1",
// PerformerID: 12,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) TaskCreate ( task Task , site ... string ) ( CreateResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp CreateResponse
taskJSON , _ := json . Marshal ( & task )
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"task" : { string ( taskJSON ) } ,
2018-03-21 00:54:37 +03:00
}
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/tasks/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// Task returns task
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-tasks-id
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Task(12)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.Task)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Task ( id int ) ( TaskResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp TaskResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/tasks/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-04-23 16:28:54 +03:00
2018-09-28 13:46:09 +03:00
// TaskEdit edit a task
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-tasks-id-edit
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Task(retailcrm.Task{
2018-04-12 16:43:53 +03:00
// ID: 12
// Text: "task №2",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) TaskEdit ( task Task , site ... string ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
var uid = strconv . Itoa ( task . ID )
taskJSON , _ := json . Marshal ( & task )
2018-02-27 11:37:15 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"task" : { string ( taskJSON ) } ,
2018-02-27 11:37:15 +03:00
}
fillSite ( & p , site )
2018-03-21 00:54:37 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/tasks/%s/edit" , uid ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2021-10-27 15:49:06 +03:00
if ! resp . Success {
a := CreateAPIError ( data )
2021-04-26 12:09:21 +03:00
return resp , status , a
2018-04-22 20:39:22 +03:00
}
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// UserGroups returns list of user groups
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-user-groups
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.UserGroups(retailcrm.UserGroupsRequest{Page: 1})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Groups {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) UserGroups ( parameters UserGroupsRequest ) ( UserGroupsResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp UserGroupsResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/user-groups?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-03-21 00:54:37 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-03-21 00:54:37 +03:00
}
2018-09-28 13:46:09 +03:00
// Users returns list of users matched the specified filters
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-users
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.Users(retailcrm.UsersRequest{Filter: retailcrm.UsersFilter{Active: 1}, Page: 1})
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// for _, value := range data.Users {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Users ( parameters UsersRequest ) ( UsersResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp UsersResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/users?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// User returns information about user
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-users-id
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.User(12)
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-12 16:43:53 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.User)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) User ( id int ) ( UserResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp UserResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/users/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-09-28 13:46:09 +03:00
// UserStatus change user status
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-users
2018-04-12 16:43:53 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.UserStatus(12, "busy")
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-12 16:43:53 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) UserStatus ( id int , status string ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
p := url . Values {
2021-10-27 15:49:06 +03:00
"status" : { status } ,
2018-03-21 00:54:37 +03:00
}
data , st , err := c . PostRequest ( fmt . Sprintf ( "/users/%d/status" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , st , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , st , err
}
2018-03-21 00:54:37 +03:00
2021-10-27 15:49:06 +03:00
if ! resp . Success {
return resp , st , CreateAPIError ( data )
2018-04-22 20:39:22 +03:00
}
2019-02-21 11:51:50 +03:00
return resp , st , nil
2018-03-21 00:54:37 +03:00
}
2018-09-28 13:46:09 +03:00
// StaticticsUpdate updates statistics
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-statistic-update
2021-04-26 12:09:21 +03:00
func ( c * Client ) StaticticsUpdate ( ) ( SuccessfulResponse , int , error ) {
2018-03-21 00:54:37 +03:00
var resp SuccessfulResponse
2018-02-27 11:37:15 +03:00
2018-03-21 00:54:37 +03:00
data , status , err := c . GetRequest ( "/statistic/update" )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-03-21 00:54:37 +03:00
return resp , status , err
2018-02-27 11:37:15 +03:00
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-02-27 11:37:15 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-02-27 11:37:15 +03:00
}
2018-04-11 13:39:43 +03:00
2018-09-28 13:46:09 +03:00
// Costs returns costs list
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-costs
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.Costs(CostsRequest{
// Filter: CostsFilter{
// Ids: []string{"1","2","3"},
// MinSumm: "1000"
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.Costs {
// log.Printf("%v\n", value.Summ)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Costs ( costs CostsRequest ) ( CostsResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CostsResponse
params , _ := query . Values ( costs )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/costs?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2021-10-27 15:49:06 +03:00
// CostCreate create the cost
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-costs-create
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.CostCreate(
2022-11-24 13:37:21 +03:00
// retailcrm.CostRecord{
2018-04-11 13:39:43 +03:00
// DateFrom: "2012-12-12",
// DateTo: "2012-12-12",
// Summ: 12,
// CostItem: "calculation-of-costs",
// Order: Order{
2022-11-24 13:37:21 +03:00
// Number: "1"
// },
// Sites: []string{"store"},
2018-04-11 13:39:43 +03:00
// },
// "store"
2022-11-24 13:37:21 +03:00
// )
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostCreate ( cost CostRecord , site ... string ) ( CreateResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CreateResponse
costJSON , _ := json . Marshal ( & cost )
p := url . Values {
2021-10-27 15:49:06 +03:00
"cost" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( "/costs/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CostsDelete removes a cost
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-costs-delete
2018-04-11 13:39:43 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50})
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("Not removed costs: %v", data.NotRemovedIds)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostsDelete ( ids [ ] int ) ( CostsDeleteResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CostsDeleteResponse
costJSON , _ := json . Marshal ( & ids )
p := url . Values {
2021-10-27 15:49:06 +03:00
"ids" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
data , status , err := c . PostRequest ( "/costs/delete" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CostsUpload batch costs upload
2018-04-12 16:43:53 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-costs-upload
2018-04-11 13:39:43 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CostCreate([]retailcrm.CostRecord{
2018-04-11 13:39:43 +03:00
// {
// DateFrom: "2012-12-12",
// DateTo: "2012-12-12",
// Summ: 12,
// CostItem: "calculation-of-costs",
// Order: Order{
2022-11-24 13:37:21 +03:00
// Number: "1"
// },
// Sites: []string{"store"},
2018-04-11 13:39:43 +03:00
// },
// {
// DateFrom: "2012-12-13",
// DateTo: "2012-12-13",
// Summ: 13,
// CostItem: "seo",
// }
2022-11-24 13:37:21 +03:00
// })
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("Uploaded costs: %v", data.UploadedCosts)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostsUpload ( cost [ ] CostRecord ) ( CostsUploadResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CostsUploadResponse
costJSON , _ := json . Marshal ( & cost )
p := url . Values {
2021-10-27 15:49:06 +03:00
"costs" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
data , status , err := c . PostRequest ( "/costs/upload" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// Cost returns information about specified cost
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-costs-id
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.Cost(1)
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.Cost)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Cost ( id int ) ( CostResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CostResponse
data , status , err := c . GetRequest ( fmt . Sprintf ( "/costs/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CostDelete removes cost
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-costs-id-delete
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.CostDelete(1)
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostDelete ( id int ) ( SuccessfulResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp SuccessfulResponse
costJSON , _ := json . Marshal ( & id )
p := url . Values {
2021-10-27 15:49:06 +03:00
"costs" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/costs/%d/delete" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CostEdit edit a cost
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-costs-id-edit
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CostEdit(1, retailcrm.Cost{
2018-04-11 13:39:43 +03:00
// DateFrom: "2012-12-12",
// DateTo: "2018-12-13",
// Summ: 321,
// CostItem: "seo",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.ID)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CostEdit ( id int , cost CostRecord , site ... string ) ( CreateResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CreateResponse
costJSON , _ := json . Marshal ( & cost )
p := url . Values {
2021-10-27 15:49:06 +03:00
"cost" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
fillSite ( & p , site )
data , status , err := c . PostRequest ( fmt . Sprintf ( "/costs/%d/edit" , id ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-09-04 11:38:21 +03:00
return resp , status , nil
}
// Files returns files list
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
// data, status, err := client.Files(FilesRequest{
// Filter: FilesFilter{
// Filename: "image.jpeg",
// },
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) Files ( files FilesRequest ) ( FilesResponse , int , error ) {
2019-09-04 11:38:21 +03:00
var resp FilesResponse
params , _ := query . Values ( files )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/files?%s" , params . Encode ( ) ) )
if err != nil && err . Error ( ) != "" {
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-09-04 11:38:21 +03:00
return resp , status , nil
}
2020-12-15 13:33:24 +03:00
// FileUpload uploads file to RetailCRM
2019-09-04 11:38:21 +03:00
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// file, err := os.Open("file.jpg")
// if err != nil {
// fmt.Print(err)
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.FileUpload(file)
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if err.Error() != "" {
// fmt.Printf("%v", err.Error())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.Error())
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) FileUpload ( reader io . Reader ) ( FileUploadResponse , int , error ) {
2019-09-04 11:38:21 +03:00
var resp FileUploadResponse
2019-09-09 15:39:26 +03:00
data , status , err := c . PostRequest ( "/files/upload" , reader , "application/octet-stream" )
2019-09-04 11:38:21 +03:00
if err != nil && err . Error ( ) != "" {
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-09-04 11:38:21 +03:00
return resp , status , nil
}
// File returns a file info
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.File(112)
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2019-09-04 11:38:21 +03:00
//
// if data.Success == true {
2022-11-24 13:37:21 +03:00
// log.Printf("%v\n", data.File)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) File ( id int ) ( FileResponse , int , error ) {
2019-09-04 11:38:21 +03:00
var resp FileResponse
data , status , err := c . GetRequest ( fmt . Sprintf ( "/files/%d" , id ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2019-09-04 11:38:21 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-09-04 11:38:21 +03:00
return resp , status , nil
}
2020-12-15 13:33:24 +03:00
// FileDelete removes file from RetailCRM
2019-09-04 11:38:21 +03:00
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.FileDelete(123)
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if err.Error() != "" {
// fmt.Printf("%v", err.Error())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.Error())
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) FileDelete ( id int ) ( SuccessfulResponse , int , error ) {
2019-09-04 11:38:21 +03:00
var resp SuccessfulResponse
data , status , err := c . PostRequest ( fmt . Sprintf ( "/files/%d/delete" , id ) , strings . NewReader ( "" ) )
if err != nil && err . Error ( ) != "" {
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-09-04 11:38:21 +03:00
return resp , status , nil
}
2020-12-15 13:33:24 +03:00
// FileDownload downloads file from RetailCRM
2019-09-04 11:38:21 +03:00
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// fileData, status, err := client.FileDownload(123)
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if err.Error() != "" {
// fmt.Printf("%v", err.Error())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.Error())
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) FileDownload ( id int ) ( io . ReadCloser , int , error ) {
2019-09-04 11:38:21 +03:00
data , status , err := c . GetRequest ( fmt . Sprintf ( "/files/%d/download" , id ) )
if status != http . StatusOK {
return nil , status , err
}
closer := ioutil . NopCloser ( bytes . NewReader ( data ) )
return closer , status , nil
}
2020-12-15 13:33:24 +03:00
// FileEdit edits file name and relations with orders and customers in RetailCRM
2019-09-04 11:38:21 +03:00
//
// For more information see https://help.retailcrm.pro/Developers/ApiVersion5#get--api-v5-files
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.FileEdit(123, File{Filename: "image2.jpg"})
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if err.Error() != "" {
// fmt.Printf("%v", err.Error())
// }
2019-09-04 11:38:21 +03:00
//
2022-11-24 13:37:21 +03:00
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.Error())
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) FileEdit ( id int , file File ) ( FileResponse , int , error ) {
2019-09-04 11:38:21 +03:00
var resp FileResponse
req , _ := json . Marshal ( file )
2021-04-26 12:09:21 +03:00
data , status , err := c . PostRequest (
fmt . Sprintf ( "/files/%d/edit" , id ) , url . Values {
"file" : { string ( req ) } ,
} ,
)
2019-09-04 11:38:21 +03:00
if err != nil && err . Error ( ) != "" {
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2019-09-04 11:38:21 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomFields returns list of custom fields
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-custom-fields
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CustomFields(retailcrm.CustomFieldsRequest{
2018-04-11 13:39:43 +03:00
// Type: "string",
2022-11-24 13:37:21 +03:00
// Entity: "customer",
2018-04-11 13:39:43 +03:00
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.CustomFields {
2018-04-11 13:39:43 +03:00
// fmt.Printf("%v\n", value)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomFields ( customFields CustomFieldsRequest ) ( CustomFieldsResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomFieldsResponse
params , _ := query . Values ( customFields )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/custom-fields?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomDictionaries returns list of custom directory
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-custom-fields-dictionaries
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CustomDictionaries(retailcrm.CustomDictionariesRequest{
// Filter: retailcrm.CustomDictionariesFilter{
2018-04-11 13:39:43 +03:00
// Name: "Dictionary-1",
// },
// })
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// for _, value := range data.CustomDictionaries {
// fmt.Printf("%v\n", value.Elements)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomDictionaries ( customDictionaries CustomDictionariesRequest ) (
CustomDictionariesResponse , int , error ,
) {
2018-04-11 13:39:43 +03:00
var resp CustomDictionariesResponse
params , _ := query . Values ( customDictionaries )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/custom-fields/dictionaries?%s" , params . Encode ( ) ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomDictionariesCreate creates a custom dictionary
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-custom-fields-dictionaries-create
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CustomDictionariesCreate(retailcrm.CustomDictionary{
2018-04-11 13:39:43 +03:00
// Name: "Courier profiles",
// Code: "courier-profiles",
// Elements: []Element{
// {
// Name: "Name",
// Code: "name",
// },
// {
// Name: "Lastname",
// Code: "lastname",
// }
// },
// })
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// If data.Success == true {
// fmt.Printf("%v", data.Code)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomDictionariesCreate ( customDictionary CustomDictionary ) ( CustomResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomResponse
costJSON , _ := json . Marshal ( & customDictionary )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customDictionary" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
data , status , err := c . PostRequest ( "/custom-fields/dictionaries/create" , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 13:46:09 +03:00
// CustomDictionary returns information about dictionary
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-custom-fields-entity-code
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.CustomDictionary("courier-profiles")
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.CustomDictionary.Name)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomDictionary ( code string ) ( CustomDictionaryResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomDictionaryResponse
data , status , err := c . GetRequest ( fmt . Sprintf ( "/custom-fields/dictionaries/%s" , code ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomDictionaryEdit edit custom dictionary
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-custom-fields-dictionaries-code-edit
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2021-10-27 15:49:06 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2021-10-27 15:49:06 +03:00
// data, status, err := client.CustomDictionaryEdit(retailcrm.CustomDictionary{
2018-04-11 13:39:43 +03:00
// Name: "Courier profiles",
// Code: "courier-profiles",
// Elements: []Element{
// {
// Name: "Name",
// Code: "name",
// },
// {
// Name: "Lastname",
// Code: "lastname",
// }
// },
// })
//
2019-02-21 11:51:50 +03:00
// if err.Error() != "" {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// if status >= http.StatusBadRequest {
2021-01-29 14:29:44 +03:00
// fmt.Printf("%v", err.Error())
2018-04-11 13:39:43 +03:00
// }
//
// If data.Success == true {
// fmt.Printf("%v", data.Code)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomDictionaryEdit ( customDictionary CustomDictionary ) ( CustomResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomResponse
costJSON , _ := json . Marshal ( & customDictionary )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customDictionary" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
data , status , err := c . PostRequest ( fmt . Sprintf ( "/custom-fields/dictionaries/%s/edit" , customDictionary . Code ) , p )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomFieldsCreate creates custom field
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-custom-fields-entity-create
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2018-04-12 16:43:53 +03:00
// data, status, err := client.CustomFieldsCreate(CustomFields{
// Name: "First order",
// Code: "first-order",
// Type: "bool",
// Entity: "order",
// DisplayArea: "customer",
2018-04-11 13:39:43 +03:00
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.Code)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomFieldsCreate ( customFields CustomFields ) ( CustomResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomResponse
costJSON , _ := json . Marshal ( & customFields )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customField" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
2018-04-12 16:43:53 +03:00
data , status , err := c . PostRequest ( fmt . Sprintf ( "/custom-fields/%s/create" , customFields . Entity ) , p )
2018-04-11 13:39:43 +03:00
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2018-09-28 01:37:56 +03:00
// CustomField returns information about custom fields
2018-04-11 13:39:43 +03:00
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-custom-fields-entity-code
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
// data, status, err := client.CustomField("order", "first-order")
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.CustomField)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomField ( entity , code string ) ( CustomFieldResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomFieldResponse
data , status , err := c . GetRequest ( fmt . Sprintf ( "/custom-fields/%s/%s" , entity , code ) )
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
// CustomFieldEdit list method
//
2022-08-09 15:27:01 +03:00
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-custom-fields-entity-code-edit
2018-04-12 16:43:53 +03:00
//
2018-04-11 13:39:43 +03:00
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2018-04-11 13:39:43 +03:00
//
2018-04-12 16:43:53 +03:00
// data, status, err := client.CustomFieldEdit(CustomFields{
// Code: "first-order",
// Entity: "order",
// DisplayArea: "delivery",
// })
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2018-04-11 13:39:43 +03:00
//
2022-11-24 13:37:21 +03:00
// If data.Success == true {
// log.Printf("%v", data.Code)
// }
2021-04-26 12:09:21 +03:00
func ( c * Client ) CustomFieldEdit ( customFields CustomFields ) ( CustomResponse , int , error ) {
2018-04-11 13:39:43 +03:00
var resp CustomResponse
costJSON , _ := json . Marshal ( & customFields )
p := url . Values {
2021-10-27 15:49:06 +03:00
"customField" : { string ( costJSON ) } ,
2018-04-11 13:39:43 +03:00
}
2021-04-26 12:09:21 +03:00
data , status , err := c . PostRequest (
fmt . Sprintf ( "/custom-fields/%s/%s/edit" , customFields . Entity , customFields . Code ) , p ,
)
2018-04-11 13:39:43 +03:00
2021-04-26 12:09:21 +03:00
if err != nil {
2018-04-11 13:39:43 +03:00
return resp , status , err
}
2021-10-27 15:49:06 +03:00
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
2018-04-11 13:39:43 +03:00
2019-02-21 11:51:50 +03:00
return resp , status , nil
2018-04-11 13:39:43 +03:00
}
2022-08-09 13:45:11 +03:00
// BonusOperations returns history of the bonus account for all participations
//
2022-08-09 15:27:01 +03:00
// For more information see https://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-bonus-operations
2022-08-09 13:45:11 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.BonusOperations(retailcrm.BonusOperationsRequest{
2022-08-09 13:45:11 +03:00
// Filter: BonusOperationsFilter{
// LoyaltyId: []int{123, 456},
// },
2022-08-09 15:27:01 +03:00
// Limit: 20,
2022-08-09 13:45:11 +03:00
// Cursor: "123456",
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.BonusOperations {
// log.Printf("%v\n", value)
// }
2022-08-09 13:45:11 +03:00
func ( c * Client ) BonusOperations ( parameters BonusOperationsRequest ) ( BonusOperationsResponse , int , error ) {
var resp BonusOperationsResponse
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf ( "/loyalty/bonus/operations?%s" , params . Encode ( ) ) )
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
return resp , status , nil
}
// AccountBonusOperations returns history of the bonus account for a specific participation
//
2022-08-09 15:27:01 +03:00
// For more information see https://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-account-id-bonus-operations
2022-08-09 13:45:11 +03:00
//
// Example:
//
2022-11-24 13:37:21 +03:00
// var client = retailcrm.New("https://demo.url", "09jIJ")
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// data, status, err := client.AccountBonusOperations(retailcrm.AccountBonusOperationsRequest{
2022-08-09 13:45:11 +03:00
// Filter: AccountBonusOperationsFilter{
// CreatedAtFrom: "2012-12-12",
// CreatedAtTo: "2012-12-13",
// },
2022-08-09 15:27:01 +03:00
// Limit: 20,
2022-08-09 13:45:11 +03:00
// Page: 3,
// })
//
2022-11-24 13:37:21 +03:00
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// log.Fatalf("http status: %d, error: %s", status, err)
// }
2022-08-09 13:45:11 +03:00
//
2022-11-24 13:37:21 +03:00
// for _, value := range data.BonusOperations {
// log.Printf("%v\n", value)
// }
2022-08-09 13:45:11 +03:00
func ( c * Client ) AccountBonusOperations ( id int , parameters AccountBonusOperationsRequest ) ( BonusOperationsResponse , int , error ) {
var resp BonusOperationsResponse
2022-08-09 15:27:01 +03:00
if id == 0 {
c . writeLog ( "cannot get loyalty bonus operations for user with id %d" , id )
}
2022-08-09 13:45:11 +03:00
params , _ := query . Values ( parameters )
data , status , err := c . GetRequest ( fmt . Sprintf (
2022-08-09 15:27:01 +03:00
"/loyalty/account/%d/bonus/operations?%s" ,
2022-08-09 13:45:11 +03:00
id , params . Encode ( ) ,
) )
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
return resp , status , nil
}
2022-11-23 18:16:58 +03:00
2022-11-24 13:37:21 +03:00
// ProductsBatchEdit perform editing products batch
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-products-batch-edit
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// products := []ProductEdit{{
// CatalogID: 3,
// BaseProduct: BaseProduct{
// Name: "Product 1",
// URL: "https://example.com/p/1",
// Article: "p1",
// ExternalID: "ext1",
// },
// ID: 194,
// Site: "second",
// Groups: []ProductEditGroupInput{{ID: 19}},
// }}
//
// data, status, err := client.ProductsBatchEdit(products)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.ProcessedProductsCount)
// }
2022-11-23 18:16:58 +03:00
func ( c * Client ) ProductsBatchEdit ( products [ ] ProductEdit ) ( ProductsBatchEditResponse , int , error ) {
var resp ProductsBatchEditResponse
productsEditJSON , _ := json . Marshal ( products )
p := url . Values {
"products" : { string ( productsEditJSON ) } ,
}
data , status , err := c . PostRequest ( "/store/products/batch/edit" , p )
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
return resp , status , nil
}
2022-11-24 13:37:21 +03:00
// ProductsBatchCreate perform adding products batch
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-store-products-batch-create
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// products := []ProductCreate{{
// CatalogID: 3,
// BaseProduct: BaseProduct{
// Name: "Product 1",
// URL: "https://example.com/p/1",
// Article: "p1",
// ExternalID: "ext1",
// },
// Groups: []ProductEditGroupInput{{ID: 19}},
// }}
//
// data, status, err := client.ProductsBatchCreate(products)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.AddedProducts)
// }
2022-11-23 18:16:58 +03:00
func ( c * Client ) ProductsBatchCreate ( products [ ] ProductCreate ) ( ProductsBatchEditResponse , int , error ) {
var resp ProductsBatchEditResponse
productsEditJSON , _ := json . Marshal ( products )
p := url . Values {
"products" : { string ( productsEditJSON ) } ,
}
data , status , err := c . PostRequest ( "/store/products/batch/create" , p )
if err != nil {
return resp , status , err
}
err = json . Unmarshal ( data , & resp )
if err != nil {
return resp , status , err
}
return resp , status , nil
}
2022-11-24 13:37:21 +03:00
// LoyaltyAccountCreate а dd a client to the loyalty program
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-create
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
// acc := SerializedCreateLoyaltyAccount{
// SerializedBaseLoyaltyAccount: SerializedBaseLoyaltyAccount{
// PhoneNumber: "89151005004",
// CustomFields: []string{"dog"},
// },
// Customer: SerializedEntityCustomer{
// ID: 123,
// },
// }
//
// data, status, err := client.LoyaltyAccountCreate("site", acc)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.LoyaltyAccount.ID)
// }
func ( c * Client ) LoyaltyAccountCreate ( site string , loyaltyAccount SerializedCreateLoyaltyAccount ) ( CreateLoyaltyAccountResponse , int , error ) {
var result CreateLoyaltyAccountResponse
loyaltyAccountJSON , _ := json . Marshal ( loyaltyAccount )
p := url . Values {
"site" : { site } ,
"loyaltyAccount" : { string ( loyaltyAccountJSON ) } ,
}
resp , status , err := c . PostRequest ( "/loyalty/account/create" , p )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
// LoyaltyAccountEdit edit a client in the loyalty program
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-edit
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
// acc := SerializedEditLoyaltyAccount{
// SerializedBaseLoyaltyAccount: SerializedBaseLoyaltyAccount{
// PhoneNumber: "89151005004",
// CustomFields: []string{"dog"},
// },
// }
//
// data, status, err := client.LoyaltyAccountEdit(13, acc)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.LoyaltyAccount.PhoneNumber)
// }
func ( c * Client ) LoyaltyAccountEdit ( ID int , loyaltyAccount SerializedEditLoyaltyAccount ) ( EditLoyaltyAccountResponse , int , error ) {
var result EditLoyaltyAccountResponse
loyaltyAccountJSON , _ := json . Marshal ( loyaltyAccount )
p := url . Values {
"loyaltyAccount" : { string ( loyaltyAccountJSON ) } ,
}
resp , status , err := c . PostRequest ( fmt . Sprintf ( "/loyalty/account/%d/edit" , ID ) , p )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
// LoyaltyAccount return information about client in the loyalty program
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-account-id
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.LoyaltyAccount(13)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.LoyaltyAccount.PhoneNumber)
// }
func ( c * Client ) LoyaltyAccount ( ID int ) ( LoyaltyAccountResponse , int , error ) {
var result LoyaltyAccountResponse
resp , status , err := c . GetRequest ( fmt . Sprintf ( "/loyalty/account/%d" , ID ) )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
// LoyaltyAccountActivate activate participation in the loyalty program for client
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-activate
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// data, status, err := client.LoyaltyAccountActivate(13)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.LoyaltyAccount.Active)
// }
func ( c * Client ) LoyaltyAccountActivate ( ID int ) ( LoyaltyAccountActivateResponse , int , error ) {
var result LoyaltyAccountActivateResponse
resp , status , err := c . PostRequest ( fmt . Sprintf ( "/loyalty/account/%d/activate" , ID ) , strings . NewReader ( "" ) )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
// LoyaltyBonusCredit accrue bonus participation in the program of loyalty
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-loyalty-account-id-bonus-credit
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// req := LoyaltyBonusCreditRequest{
// Amount: 120,
// ExpiredDate: "2023-11-24 12:39:37",
// Comment: "Test",
// }
//
// data, status, err := client.LoyaltyBonusCredit(13, req)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// log.Printf("%v", data.LoyaltyBonus.ActivationDate)
// }
func ( c * Client ) LoyaltyBonusCredit ( ID int , req LoyaltyBonusCreditRequest ) ( LoyaltyBonusCreditResponse , int , error ) {
var result LoyaltyBonusCreditResponse
p , _ := query . Values ( req )
resp , status , err := c . PostRequest ( fmt . Sprintf ( "/loyalty/account/%d/bonus/credit" , ID ) , p )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
// LoyaltyBonusStatusDetails get details on the bonus account
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-account-id-bonus-status-details
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// req := LoyaltyBonusStatusDetailsRequest{
// Limit: 20,
// Page: 3,
// }
//
// data, status, err := client.LoyaltyBonusStatusDetails(13, "waiting_activation", req)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// for _, bonus := range data.Bonuses {
// log.Printf("%v", bonus.Amount)
// }
// }
func ( c * Client ) LoyaltyBonusStatusDetails (
ID int , statusType string , request LoyaltyBonusStatusDetailsRequest ,
) ( LoyaltyBonusDetailsResponse , int , error ) {
var result LoyaltyBonusDetailsResponse
p , _ := query . Values ( request )
resp , status , err := c . GetRequest ( fmt . Sprintf ( "/loyalty/account/%d/bonus/%s/details?%s" , ID , statusType , p . Encode ( ) ) )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}
2022-12-07 17:40:52 +03:00
// LoyaltyAccounts return list of participations in the loyalty program
//
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-loyalty-accounts
//
// Example:
//
// var client = retailcrm.New("https://demo.url", "09jIJ")
//
// req := LoyaltyAccountsRequest{
// Filter: LoyaltyAccountApiFilter{
// Status: "activated",
// PhoneNumber: "89185556363",
// Ids: []int{14},
// Level: 5,
// Loyalties: []int{2},
// CustomerId: "109",
// },
// }
//
// data, status, err := client.LoyaltyAccounts(req)
//
// if err != nil {
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
// log.Fatalf("http status: %d, %s", status, apiErr.String())
// }
//
// log.Fatalf("http status: %d, error: %s", status, err)
// }
//
// if data.Success == true {
// for _, account := range data.LoyaltyAccounts {
// log.Printf("%v", account.Status)
// }
// }
func ( c * Client ) LoyaltyAccounts ( req LoyaltyAccountsRequest ) ( LoyaltyAccountsResponse , int , error ) {
var result LoyaltyAccountsResponse
p , _ := query . Values ( req )
resp , status , err := c . GetRequest ( fmt . Sprintf ( "/loyalty/accounts?%s" , p . Encode ( ) ) )
if err != nil {
return result , status , err
}
err = json . Unmarshal ( resp , & result )
if err != nil {
return result , status , err
}
return result , status , nil
}