2018-02-27 11:37:15 +03:00
|
|
|
package v5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"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"
|
2018-04-22 20:39:22 +03:00
|
|
|
"github.com/retailcrm/api-client-go/errs"
|
2018-02-27 11:37:15 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// New initalize client
|
|
|
|
func New(url string, key string) *Client {
|
|
|
|
return &Client{
|
2018-09-28 01:37:56 +03:00
|
|
|
URL: url,
|
|
|
|
Key: key,
|
2019-02-04 11:59:05 +03:00
|
|
|
httpClient: &http.Client{Timeout: time.Minute},
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRequest implements GET Request
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, *errs.Failure) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var res []byte
|
2018-03-21 00:54:37 +03:00
|
|
|
var prefix = "/api/v5"
|
2019-02-21 11:51:50 +03:00
|
|
|
failure := &errs.Failure{}
|
2018-03-21 00:54:37 +03:00
|
|
|
|
|
|
|
if len(versioned) > 0 {
|
|
|
|
s := versioned[0]
|
|
|
|
|
|
|
|
if s == false {
|
|
|
|
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 {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, 0, failure
|
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 {
|
|
|
|
log.Printf("API Request: %s %s", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), c.Key)
|
|
|
|
}
|
|
|
|
|
2018-02-27 11:37:15 +03:00
|
|
|
resp, err := c.httpClient.Do(req)
|
|
|
|
if err != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, 0, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode >= http.StatusInternalServerError {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode))
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, resp.StatusCode, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
res, err = buildRawResponse(resp)
|
|
|
|
if err != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 01:37:56 +03:00
|
|
|
if c.Debug {
|
|
|
|
log.Printf("API Response: %s", res)
|
|
|
|
}
|
|
|
|
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, resp.StatusCode, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// PostRequest implements POST Request
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, *errs.Failure) {
|
2018-02-27 11:37:15 +03:00
|
|
|
var res []byte
|
2018-03-21 00:54:37 +03:00
|
|
|
var prefix = "/api/v5"
|
2019-02-21 11:51:50 +03:00
|
|
|
failure := &errs.Failure{}
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, url), strings.NewReader(postParams.Encode()))
|
2018-02-27 11:37:15 +03:00
|
|
|
if err != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, 0, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("X-API-KEY", c.Key)
|
|
|
|
|
2018-09-28 01:37:56 +03:00
|
|
|
if c.Debug {
|
|
|
|
log.Printf("API Request: %s %s %s", url, c.Key, postParams.Encode())
|
|
|
|
}
|
|
|
|
|
2018-02-27 11:37:15 +03:00
|
|
|
resp, err := c.httpClient.Do(req)
|
|
|
|
if err != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, 0, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode >= http.StatusInternalServerError {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetApiError(fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode))
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, resp.StatusCode, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
res, err = buildRawResponse(resp)
|
|
|
|
if err != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
failure.SetRuntimeError(err)
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, 0, failure
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 01:37:56 +03:00
|
|
|
if c.Debug {
|
|
|
|
log.Printf("API Response: %s", res)
|
|
|
|
}
|
|
|
|
|
2018-09-28 13:46:09 +03:00
|
|
|
return res, resp.StatusCode, failure
|
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
|
|
|
|
}
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
func buildErr(data []byte, err *errs.Failure) {
|
2018-09-28 13:46:09 +03:00
|
|
|
resp, e := errs.ErrorResponse(data)
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetRuntimeError(e)
|
|
|
|
err.SetApiError(resp.ErrorMsg)
|
2018-04-22 20:39:22 +03:00
|
|
|
|
2018-09-28 13:46:09 +03:00
|
|
|
if resp.Errors != nil {
|
2019-02-21 11:51:50 +03:00
|
|
|
err.SetApiErrors(errs.ErrorsHandler(resp.Errors))
|
2018-04-22 20:39:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 11:37:15 +03:00
|
|
|
// checkBy select identifier type
|
|
|
|
func checkBy(by string) string {
|
|
|
|
var context = "id"
|
|
|
|
|
|
|
|
if by != "id" {
|
|
|
|
context = "externalId"
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
|
|
|
// fillSite add site code to parameters if present
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions
|
|
|
|
//
|
2018-02-27 11:37:15 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-03-19 23:18:36 +03:00
|
|
|
// data, status, err := client.APIVersions()
|
2018-02-27 11:37:15 +03:00
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-02-27 11:37:15 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-02-27 11:37:15 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.versions {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) APIVersions() (VersionResponse, int, *errs.Failure) {
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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-03-19 23:18:36 +03:00
|
|
|
// APICredentials get all available API methods for exact account
|
2018-02-27 15:22:52 +03:00
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-api-versions
|
|
|
|
//
|
2018-02-27 15:22:52 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-03-19 23:18:36 +03:00
|
|
|
// data, status, err := client.APICredentials()
|
2018-02-27 15:22:52 +03:00
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-02-27 15:22:52 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-02-27 15:22:52 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.credentials {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) APICredentials() (CredentialResponse, int, *errs.Failure) {
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// Customers returns list of customers matched the specified filter
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Customers(v5.CustomersRequest{
|
|
|
|
// Filter: CustomersFilter{
|
|
|
|
// City: "Moscow",
|
|
|
|
// },
|
|
|
|
// Page: 3,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Customers {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Customers(parameters CustomersRequest) (CustomersResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomersCombine combine given customers
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-combine
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomersCombine([]v5.Customer{{ID: 1}, {ID: 2}}, Customer{ID: 3})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"customers": {string(combineJSONIn[:])},
|
|
|
|
"resultCustomer": {string(combineJSONOut[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/customers/combine", p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomerCreate creates customer
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomersCombine(v5.Customer{
|
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// ExternalID: 1,
|
|
|
|
// Email: "ivanov@example.com",
|
|
|
|
// Address: &v5.Address{
|
|
|
|
// City: "Moscow",
|
|
|
|
// Street: "Kutuzovsky",
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v", err.Id)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomerCreate(customer Customer, site ...string) (CustomerChangeResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"customer": {string(customerJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomersFixExternalIds customers external ID
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-fix-external-ids
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomersFixExternalIds([]v5.IdentifiersPair{{
|
|
|
|
// ID: 1,
|
|
|
|
// ExternalID: 12,
|
|
|
|
// }})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"customers": {string(customersJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/customers/fix-external-ids", p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomersHistory returns customer's history
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-history
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomersHistory(v5.CustomersHistoryRequest{
|
|
|
|
// Filter: v5.CustomersHistoryFilter{
|
|
|
|
// SinceID: 20,
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.History {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (CustomersHistoryResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-notes
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomerNotes(v5.NotesRequest{
|
|
|
|
// Filter: v5.NotesFilter{
|
|
|
|
// CustomerIds: []int{1,2,3}
|
|
|
|
// },
|
|
|
|
// Page: 1,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Notes {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomerNotes(parameters NotesRequest) (NotesResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomerNoteCreate note creation
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomerNoteCreate(v5.Note{
|
|
|
|
// Text: "some text",
|
|
|
|
// ManagerID: 12,
|
|
|
|
// Customer: &v5.Customer{
|
|
|
|
// ID: 1,
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomerNoteCreate(note Note, site ...string) (CreateResponse, int, *errs.Failure) {
|
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(¬e)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-notes-id-delete
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomerNoteDelete(12)
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomerNoteDelete(id int) (SuccessfulResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"id": {string(id)},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/customers/notes/%d/delete", id), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// CustomersUpload customers batch upload
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-upload
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomersUpload([]v5.Customer{
|
|
|
|
// {
|
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// ExternalID: 1,
|
|
|
|
// Email: "ivanov@example.com",
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// FirstName: "Petr",
|
|
|
|
// LastName: "Petrov",
|
|
|
|
// Patronymic: "Petrovich",
|
|
|
|
// ExternalID: 2,
|
|
|
|
// Email: "petrov@example.com",
|
|
|
|
// },
|
|
|
|
// }}
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.UploadedCustomers)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomersUpload(customers []Customer, site ...string) (CustomersUploadResponse, int, *errs.Failure) {
|
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{
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// Customer returns information about customer
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-customers-externalId
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Customer(12, "externalId", "")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.Customer)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Customer(id, by, site string) (CustomerResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-customers-externalId-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.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(
|
|
|
|
// v5.Customer{
|
2018-04-12 16:43:53 +03:00
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// ID: 1,
|
|
|
|
// Email: "ivanov@example.com",
|
|
|
|
// },
|
|
|
|
// "id",
|
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() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.Customer)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (CustomerChangeResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp CustomerChangeResponse
|
|
|
|
var uid = strconv.Itoa(customer.ID)
|
|
|
|
var context = checkBy(by)
|
|
|
|
|
|
|
|
if context == "externalId" {
|
|
|
|
uid = customer.ExternalID
|
|
|
|
}
|
|
|
|
|
|
|
|
customerJSON, _ := json.Marshal(&customer)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"by": {string(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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// DeliveryTracking updates tracking data
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-generic-subcode-tracking
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// data, status, err := client.DeliveryTracking(
|
|
|
|
// v5.DeliveryTrackingRequest{
|
2018-04-12 16:43:53 +03:00
|
|
|
// DeliveryID: "1",
|
|
|
|
// TrackNumber "123",
|
|
|
|
// History: []DeliveryHistoryRecord{
|
|
|
|
// {
|
|
|
|
// Code: "cancel",
|
|
|
|
// UpdatedAt: "2012-12-12 12:12:12"
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// "delivery-1",
|
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() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) {
|
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(¶meters)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// DeliveryShipments returns list of shipments
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.DeliveryShipments(v5.DeliveryShipmentsRequest{
|
|
|
|
// Limit: 12,
|
|
|
|
// Filter: v5.ShipmentFilter{
|
|
|
|
// DateFrom: "2012-12-12",
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.DeliveryShipments {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (DeliveryShipmentsResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// DeliveryShipmentCreate creates shipment
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// data, status, err := client.DeliveryShipmentCreate(
|
|
|
|
// v5.DeliveryShipment{
|
2018-04-12 16:43:53 +03:00
|
|
|
// Date: "2012-12-12",
|
|
|
|
// Time: v5.DeliveryTime{
|
|
|
|
// From: "18:00",
|
|
|
|
// To: "20:00",
|
2018-04-23 16:28:54 +03:00
|
|
|
// },
|
2018-04-12 16:43:53 +03:00
|
|
|
// Orders: []v5.Order{{Number: "12"}},
|
2018-04-23 16:28:54 +03:00
|
|
|
// },
|
|
|
|
// "sdek",
|
|
|
|
// )
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"deliveryType": {string(deliveryType)},
|
|
|
|
"deliveryShipment": {string(updateJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryShipment get information about shipment
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-delivery-shipments-id
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.DeliveryShipment(12)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.DeliveryShipment)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryShipment(id int) (DeliveryShipmentResponse, int, *errs.Failure) {
|
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))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryShipmentEdit shipment editing
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-delivery-shipments-id-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.DeliveryShipmentEdit(v5.DeliveryShipment{
|
|
|
|
// ID: "12",
|
|
|
|
// Time: v5.DeliveryTime{
|
|
|
|
// From: "14:00",
|
|
|
|
// To: "18:00",
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (DeliveryShipmentUpdateResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// IntegrationModule returns integration module
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.IntegrationModule("moysklad3")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.IntegrationModule)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int, *errs.Failure) {
|
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))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
json.Unmarshal(data, &resp)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-integration-modules-code
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// name := "MS"
|
|
|
|
// code := "moysklad3"
|
2018-04-23 16:28:54 +03:00
|
|
|
//
|
|
|
|
// data, status, err := client.IntegrationModuleEdit(v5.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() != "" {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
|
|
|
// }
|
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)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (IntegrationModuleEditResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp IntegrationModuleEditResponse
|
|
|
|
updateJSON, _ := json.Marshal(&integrationModule)
|
|
|
|
|
|
|
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Orders returns list of orders matched the specified filters
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Orders(v5.OrdersRequest{Filter: v5.OrdersFilter{City: "Moscow"}, Page: 1})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Orders {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Orders(parameters OrdersRequest) (OrdersResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrdersCombine combines given orders
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-combine
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrdersCombine("ours", v5.Order{ID: 1}, v5.Order{ID: 1})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (OperationResponse, int, *errs.Failure) {
|
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},
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderCreate creates an order
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderCreate(v5.Order{
|
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// Email: "ivanov@example.com",
|
|
|
|
// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}},
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderCreate(order Order, site ...string) (CreateResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp CreateResponse
|
|
|
|
orderJSON, _ := json.Marshal(&order)
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrdersFixExternalIds set order external ID
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-fix-external-ids
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.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.OrdersFixExternalIds(([]v5.IdentifiersPair{{
|
|
|
|
// ID: 1,
|
|
|
|
// ExternalID: 12,
|
|
|
|
// }})
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
|
|
|
// }
|
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)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrdersHistory returns orders history
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-history
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrdersHistory(v5.OrdersHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 20}})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.History {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (CustomersHistoryResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp CustomersHistoryResponse
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderPaymentCreate creates payment
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderPaymentCreate(v5.Payment{
|
|
|
|
// Order: &v5.Order{
|
|
|
|
// ID: 12,
|
|
|
|
// },
|
|
|
|
// Amount: 300,
|
|
|
|
// Type: "cash",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderPaymentCreate(payment Payment, site ...string) (CreateResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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 01:37:56 +03:00
|
|
|
// OrderPaymentDelete payment removing
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-delete
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderPaymentDelete(12)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderPaymentDelete(id int) (SuccessfulResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp SuccessfulResponse
|
2018-02-27 11:37:15 +03:00
|
|
|
|
|
|
|
p := url.Values{
|
2018-03-21 00:54:37 +03:00
|
|
|
"id": {string(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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderPaymentEdit edit payment
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-payments-id-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderPaymentEdit(
|
|
|
|
// v5.Payment{
|
|
|
|
// ID: 12,
|
|
|
|
// Amount: 500,
|
|
|
|
// },
|
|
|
|
// "id",
|
|
|
|
// )
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (SuccessfulResponse, int, *errs.Failure) {
|
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
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
if context == "externalId" {
|
|
|
|
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{
|
|
|
|
"payment": {string(paymentJSON[:])},
|
|
|
|
}
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrdersUpload batch orders uploading
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-upload
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrdersUpload([]v5.Order{
|
|
|
|
// {
|
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// Email: "ivanov@example.com",
|
|
|
|
// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 12}, Quantity: 5}},
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// FirstName: "Pert",
|
|
|
|
// LastName: "Petrov",
|
|
|
|
// Patronymic: "Petrovich",
|
|
|
|
// Email: "petrov@example.com",
|
|
|
|
// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 1}},
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.UploadedOrders)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrdersUpload(orders []Order, site ...string) (OrdersUploadResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Order returns information about order
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-externalId
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Order(12, "externalId", "")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.Order)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Order(id, by, site string) (OrderResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderEdit edit an order
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-externalId-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderEdit(
|
|
|
|
// v5.Order{
|
|
|
|
// ID: 12,
|
|
|
|
// Items: []v5.OrderItem{{Offer: v5.Offer{ID: 13}, Quantity: 6}},
|
|
|
|
// },
|
|
|
|
// "id",
|
|
|
|
// )
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderEdit(order Order, by string, site ...string) (CreateResponse, int, *errs.Failure) {
|
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
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
if context == "externalId" {
|
|
|
|
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{
|
2018-03-21 00:54:37 +03:00
|
|
|
"by": {string(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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Packs returns list of packs matched the specified filters
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Packs(v5.PacksRequest{Filter: v5.PacksFilter{OrderID: 12}})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Packs {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Packs(parameters PacksRequest) (PacksResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PackCreate creates a pack
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.PackCreate(Pack{
|
|
|
|
// Store: "store-1",
|
|
|
|
// ItemID: 12,
|
|
|
|
// Quantity: 1,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PackCreate(pack Pack) (CreateResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PacksHistory returns a history of order packing
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-history
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.PacksHistory(v5.PacksHistoryRequest{Filter: v5.OrdersHistoryFilter{SinceID: 5}})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.History {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PacksHistory(parameters PacksHistoryRequest) (PacksHistoryResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Pack returns a pack info
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-orders-packs-id
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Pack(112)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.Pack)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Pack(id int) (PackResponse, int, *errs.Failure) {
|
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))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PackDelete removes a pack
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-delete
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.PackDelete(112)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PackDelete(id int) (SuccessfulResponse, int, *errs.Failure) {
|
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{})
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PackEdit edit a pack
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-orders-packs-id-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.PackEdit(Pack{ID: 12, Quantity: 2})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PackEdit(pack Pack) (CreateResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Countries returns list of available country codes
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-countries
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Countries() (CountriesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CostGroups returns costs groups list
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-groups
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostGroups() (CostGroupsResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CostGroupEdit edit costs groups
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-groups-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostGroupEdit(v5.CostGroup{
|
|
|
|
// Code: "group-1",
|
|
|
|
// Color: "#da5c98",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostGroupEdit(costGroup CostGroup) (SuccessfulResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&costGroup)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costGroup": {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/cost-groups/%s/edit", costGroup.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CostItems returns costs items list
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-cost-items
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostItems() (CostItemsResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CostItemEdit edit costs items
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-cost-items-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostItemEdit(v5.CostItem{
|
|
|
|
// Code: "seo",
|
|
|
|
// Active: false,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostItemEdit(costItem CostItem) (SuccessfulResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&costItem)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costItem": {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/cost-items/%s/edit", costItem.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Couriers returns list of couriers
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Couriers() (CouriersResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CourierCreate creates a courier
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-couriers
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostItemEdit(v5.Courier{
|
|
|
|
// Active: true,
|
|
|
|
// Email: "courier1@example.com",
|
|
|
|
// FirstName: "Ivan",
|
|
|
|
// LastName: "Ivanov",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CourierCreate(courier Courier) (CreateResponse, int, *errs.Failure) {
|
2018-03-21 00:54:37 +03:00
|
|
|
var resp CreateResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&courier)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"courier": {string(objJSON[:])},
|
|
|
|
}
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// CourierEdit edit a courier
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-couriers-id-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostItemEdit(v5.Courier{
|
|
|
|
// ID: 1,
|
|
|
|
// Patronymic: "Ivanovich",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CourierEdit(courier Courier) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"courier": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/couriers/%d/edit", courier.ID), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryServices returns list of delivery services
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-services
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryServices() (DeliveryServiceResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryServiceEdit delivery service create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-services-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.DeliveryServiceEdit(v5.DeliveryService{
|
|
|
|
// Active: false,
|
|
|
|
// Code: "delivery-1",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"deliveryService": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-services/%s/edit", deliveryService.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryTypes returns list of delivery types
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-delivery-types
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryTypes() (DeliveryTypesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// DeliveryTypeEdit delivery type create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-delivery-types-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.DeliveryTypeEdit(v5.DeliveryType{
|
|
|
|
// Active: false,
|
|
|
|
// Code: "type-1",
|
|
|
|
// DefaultCost: 300,
|
|
|
|
// DefaultForCrm: false,
|
|
|
|
// }
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"deliveryType": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/delivery-types/%s/edit", deliveryType.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// LegalEntities returns list of legal entities
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-legal-entities
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) LegalEntities() (LegalEntitiesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// LegalEntityEdit change information about legal entity
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-legal-entities-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.LegalEntityEdit(v5.LegalEntity{
|
|
|
|
// Code: "legal-entity-1",
|
|
|
|
// CertificateDate: "2012-12-12",
|
|
|
|
// }
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"legalEntity": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/legal-entities/%s/edit", legalEntity.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderMethods returns list of order methods
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-methods
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderMethods() (OrderMethodsResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderMethodEdit order method create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderMethodEdit(v5.OrderMethod{
|
|
|
|
// Code: "method-1",
|
|
|
|
// Active: false,
|
|
|
|
// DefaultForCRM: false,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"orderMethod": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/order-methods/%s/edit", orderMethod.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderTypes return list of order types
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-order-types
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderTypes() (OrderTypesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// OrderTypeEdit create/edit order type
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-order-methods-code-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.OrderTypeEdit(v5.OrderType{
|
|
|
|
// Code: "order-type-1",
|
|
|
|
// Active: false,
|
|
|
|
// DefaultForCRM: false,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) OrderTypeEdit(orderType OrderType) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PaymentStatuses returns list of payment statuses
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-statuses
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PaymentStatuses() (PaymentStatusesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PaymentStatusEdit payment status creation/editing
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-statuses-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PaymentTypes returns list of payment types
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-payment-types
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PaymentTypes() (PaymentTypesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PaymentTypeEdit payment type create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-payment-types-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PaymentTypeEdit(paymentType PaymentType) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PriceTypes returns list of price types
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-price-types
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PriceTypes() (PriceTypesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PriceTypeEdit price type create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-price-types-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PriceTypeEdit(priceType PriceType) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// ProductStatuses returns list of item statuses in order
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-product-statuses
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) ProductStatuses() (ProductStatusesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// ProductStatusEdit order item status create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-product-statuses-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) ProductStatusEdit(productStatus ProductStatus) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Sites returns the sites list
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-sites
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Sites() (SitesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// SiteEdit site create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) SiteEdit(site Site) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// StatusGroups returns list of order status groups
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-status-groups
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) StatusGroups() (StatusGroupsResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Statuses returns list of order statuses
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-statuses
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Statuses() (StatusesResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// StatusEdit order status create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-sites-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) StatusEdit(st Status) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Stores returns list of warehouses
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-stores
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Stores() (StoresResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// StoreEdit warehouse create/edit
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-stores-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) StoreEdit(store Store) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-reference-units
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Units() (UnitsResponse, int, *errs.Failure) {
|
2019-02-20 10:07:02 +03:00
|
|
|
var resp UnitsResponse
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest("/reference/units")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2019-02-20 10:07:02 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
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
|
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-reference-units-code-edit
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) UnitEdit(unit Unit) (SuccessfulResponse, int, *errs.Failure) {
|
2019-02-20 10:07:02 +03:00
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
objJSON, _ := json.Marshal(&unit)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"unit": {string(objJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/units/%s/edit", unit.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2019-02-20 10:07:02 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-segments
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.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{
|
|
|
|
// Filter: v5.SegmentsFilter{
|
|
|
|
// Ids: []int{1,2,3}
|
|
|
|
// }
|
|
|
|
// })
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
|
|
|
// }
|
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)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Segments(parameters SegmentsRequest) (SegmentsResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Inventories returns leftover stocks and purchasing prices
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-inventories
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Inventories(v5.InventoriesRequest{Filter: v5.InventoriesFilter{Details: 1, ProductActive: 1}, Page: 1})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Offers {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Inventories(parameters InventoriesRequest) (InventoriesResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// InventoriesUpload updates the leftover stocks and purchasing prices
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-inventories-upload
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.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(
|
2018-04-23 16:28:54 +03:00
|
|
|
// []v5.InventoryUpload{
|
|
|
|
// {
|
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() != "" {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v\n", data.NotFoundOffers)
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (StoreUploadResponse, int, *errs.Failure) {
|
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{
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// PricesUpload updates prices
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-store-prices-upload
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// var client = v5.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.PricesUpload([]v5.OfferPriceUpload{
|
|
|
|
// {
|
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() != "" {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// if status >= http.StatusBadRequest {
|
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
|
|
|
// }
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v\n", data.NotFoundOffers)
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) PricesUpload(prices []OfferPriceUpload) (StoreUploadResponse, int, *errs.Failure) {
|
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{
|
2018-03-19 23:18:36 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// ProductsGroup returns list of product groups
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-product-groups
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.ProductsGroup(v5.ProductsGroupsRequest{
|
|
|
|
// Filter: v5.ProductsGroupsFilter{
|
|
|
|
// Active: 1,
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.ProductGroup {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (ProductsGroupsResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Products returns list of products and SKU
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Products(v5.ProductsRequest{
|
|
|
|
// Filter: v5.ProductsFilter{
|
|
|
|
// Active: 1,
|
|
|
|
// MinPrice: 1000,
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Products {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Products(parameters ProductsRequest) (ProductsResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// ProductsProperties returns list of item properties, matching the specified filters
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-store-products-properties
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.ProductsProperties(v5.ProductsPropertiesRequest{
|
|
|
|
// Filter: v5.ProductsPropertiesFilter{
|
|
|
|
// Sites: []string["store"],
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Properties {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (ProductsPropertiesResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Tasks returns task list
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Tasks(v5.TasksRequest{
|
|
|
|
// Filter: TasksFilter{
|
|
|
|
// DateFrom: "2012-12-12",
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Tasks {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Tasks(parameters TasksRequest) (TasksResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// TaskCreate create a task
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-create
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Tasks(v5.Task{
|
|
|
|
// Text: "task №1",
|
|
|
|
// PerformerID: 12,
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) TaskCreate(task Task, site ...string) (CreateResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"task": {string(taskJSON[:])},
|
|
|
|
}
|
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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// Task returns task
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-tasks-id
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Task(12)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.Task)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Task(id int) (TaskResponse, int, *errs.Failure) {
|
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))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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-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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-tasks-id-edit
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Task(v5.Task{
|
|
|
|
// ID: 12
|
|
|
|
// Text: "task №2",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) TaskEdit(task Task, site ...string) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
2018-03-21 00:54:37 +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)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-user-groups
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.UserGroups(v5.UserGroupsRequest{Page: 1})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Groups {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) UserGroups(parameters UserGroupsRequest) (UserGroupsResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
2018-04-22 20:39:22 +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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Users(v5.UsersRequest{Filter: v5.UsersFilter{Active: 1}, Page: 1})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Users {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Users(parameters UsersRequest) (UsersResponse, int, *errs.Failure) {
|
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()))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// User returns information about user
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users-id
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.User(12)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if data.Success == true {
|
|
|
|
// fmt.Printf("%v\n", data.User)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) User(id int) (UserResponse, int, *errs.Failure) {
|
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))
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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
|
|
|
// UserStatus change user status
|
2018-04-12 16:43:53 +03:00
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-users
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.UserStatus(12, "busy")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-12 16:43:53 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) UserStatus(id int, status string) (SuccessfulResponse, int, *errs.Failure) {
|
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{
|
|
|
|
"status": {string(status)},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, st, err := c.PostRequest(fmt.Sprintf("/users/%d/status", id), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, st, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, st, err
|
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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-statistic-update
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, *errs.Failure) {
|
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")
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-03-21 00:54:37 +03:00
|
|
|
return resp, status, err
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if resp.Success == false {
|
2019-02-21 11:51:50 +03:00
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
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-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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Costs(CostsRequest{
|
|
|
|
// Filter: CostsFilter{
|
|
|
|
// Ids: []string{"1","2","3"},
|
|
|
|
// MinSumm: "1000"
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.Costs {
|
|
|
|
// fmt.Printf("%v\n", value.Summ)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Costs(costs CostsRequest) (CostsResponse, int, *errs.Failure) {
|
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()))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, status, nil
|
2018-04-11 13:39:43 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 13:46:09 +03:00
|
|
|
// CostCreate create an cost
|
2018-04-11 13:39:43 +03:00
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-create
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostCreate(
|
|
|
|
// v5.CostRecord{
|
|
|
|
// DateFrom: "2012-12-12",
|
|
|
|
// DateTo: "2012-12-12",
|
|
|
|
// Summ: 12,
|
|
|
|
// CostItem: "calculation-of-costs",
|
|
|
|
// Order: Order{
|
|
|
|
// Number: "1"
|
|
|
|
// },
|
|
|
|
// Sites: []string{"store"},
|
|
|
|
// },
|
|
|
|
// "store"
|
|
|
|
// )
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.ID)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostCreate(cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CreateResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&cost)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"cost": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/costs/create", p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-delete
|
2018-04-11 13:39:43 +03:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.client.CostsDelete([]int{1, 2, 3, 48, 49, 50})
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("Not removed costs: %v", data.NotRemovedIds)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostsDelete(ids []int) (CostsDeleteResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CostsDeleteResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&ids)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"ids": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/costs/delete", p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-upload
|
2018-04-11 13:39:43 +03:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostCreate([]v5.CostRecord{
|
|
|
|
// {
|
|
|
|
// DateFrom: "2012-12-12",
|
|
|
|
// DateTo: "2012-12-12",
|
|
|
|
// Summ: 12,
|
|
|
|
// CostItem: "calculation-of-costs",
|
|
|
|
// Order: Order{
|
|
|
|
// Number: "1"
|
|
|
|
// },
|
|
|
|
// Sites: []string{"store"},
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// DateFrom: "2012-12-13",
|
|
|
|
// DateTo: "2012-12-13",
|
|
|
|
// Summ: 13,
|
|
|
|
// CostItem: "seo",
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("Uploaded costs: %v", data.UploadedCosts)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostsUpload(cost []CostRecord) (CostsUploadResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CostsUploadResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&cost)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costs": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/costs/upload", p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-costs-id
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.Cost(1)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Cost)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) Cost(id int) (CostResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CostResponse
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/costs/%d", id))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-delete
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostDelete(1)
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostDelete(id int) (SuccessfulResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp SuccessfulResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&id)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"costs": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/delete", id), p)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-costs-id-edit
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CostEdit(1, v5.Cost{
|
|
|
|
// DateFrom: "2012-12-12",
|
|
|
|
// DateTo: "2018-12-13",
|
|
|
|
// Summ: 321,
|
|
|
|
// CostItem: "seo",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Id)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CostEdit(id int, cost CostRecord, site ...string) (CreateResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CreateResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&cost)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"cost": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
fillSite(&p, site)
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/costs/%d/edit", id), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomFields(v5.CustomFieldsRequest{
|
|
|
|
// Type: "string",
|
|
|
|
// Entity: "customer",
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.CustomFields {
|
|
|
|
// fmt.Printf("%v\n", value)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomFields(customFields CustomFieldsRequest) (CustomFieldsResponse, int, *errs.Failure) {
|
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()))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-dictionaries
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomDictionaries(v5.CustomDictionariesRequest{
|
|
|
|
// Filter: v5.CustomDictionariesFilter{
|
|
|
|
// Name: "Dictionary-1",
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// for _, value := range data.CustomDictionaries {
|
|
|
|
// fmt.Printf("%v\n", value.Elements)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomDictionaries(customDictionaries CustomDictionariesRequest) (CustomDictionariesResponse, int, *errs.Failure) {
|
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()))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-create
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomDictionariesCreate(v5.CustomDictionary{
|
|
|
|
// 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() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Code)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomDictionariesCreate(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&customDictionary)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"customDictionary": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest("/custom-fields/dictionaries/create", p)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomDictionary("courier-profiles")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.CustomDictionary.Name)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomDictionary(code string) (CustomDictionaryResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomDictionaryResponse
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/dictionaries/%s", code))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-dictionaries-code-edit
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomDictionaryEdit(v5.CustomDictionary{
|
|
|
|
// 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() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Code)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomDictionaryEdit(customDictionary CustomDictionary) (CustomResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&customDictionary)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"customDictionary": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.PostRequest(fmt.Sprintf("/custom-fields/dictionaries/%s/edit", customDictionary.Code), p)
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-create
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
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
|
|
|
// })
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Code)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomFieldsCreate(customFields CustomFields) (CustomResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&customFields)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"customField": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#get--api-v5-custom-fields-entity-code
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
|
|
|
// data, status, err := client.CustomField("order", "first-order")
|
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.CustomField)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomField(entity, code string) (CustomFieldResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomFieldResponse
|
|
|
|
|
|
|
|
data, status, err := c.GetRequest(fmt.Sprintf("/custom-fields/%s/%s", entity, code))
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, status, nil
|
2018-04-11 13:39:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// CustomFieldEdit list method
|
|
|
|
//
|
2018-04-12 16:43:53 +03:00
|
|
|
// For more information see http://www.retailcrm.pro/docs/Developers/ApiVersion5#post--api-v5-custom-fields-entity-code-edit
|
|
|
|
//
|
2018-04-11 13:39:43 +03:00
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// var client = v5.New("https://demo.url", "09jIJ")
|
|
|
|
//
|
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
|
|
|
//
|
2019-02-21 11:51:50 +03:00
|
|
|
// if err.Error() != "" {
|
2018-04-12 16:43:53 +03:00
|
|
|
// fmt.Printf("%v", err.RuntimeErr)
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if status >= http.StatusBadRequest {
|
2018-04-23 16:28:54 +03:00
|
|
|
// fmt.Printf("%v", err.ApiErr())
|
2018-04-11 13:39:43 +03:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// If data.Success == true {
|
|
|
|
// fmt.Printf("%v", data.Code)
|
|
|
|
// }
|
2019-02-21 11:51:50 +03:00
|
|
|
func (c *Client) CustomFieldEdit(customFields CustomFields) (CustomResponse, int, *errs.Failure) {
|
2018-04-11 13:39:43 +03:00
|
|
|
var resp CustomResponse
|
|
|
|
|
|
|
|
costJSON, _ := json.Marshal(&customFields)
|
|
|
|
|
|
|
|
p := url.Values{
|
|
|
|
"customField": {string(costJSON[:])},
|
|
|
|
}
|
|
|
|
|
2018-04-12 16:43:53 +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
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if err.Error() != "" {
|
2018-04-11 13:39:43 +03:00
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(data, &resp)
|
|
|
|
|
2019-02-21 11:51:50 +03:00
|
|
|
if resp.Success == false {
|
|
|
|
buildErr(data, err)
|
|
|
|
return resp, status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, status, nil
|
2018-04-11 13:39:43 +03:00
|
|
|
}
|