Categorygithub.com/retailcrm/api-client-go/v2
modulepackage
2.1.18
Repository: https://github.com/retailcrm/api-client-go.git
Documentation: pkg.go.dev

# README

Build Status Covarage GitHub release Go Report Card GoLang version pkg.go.dev

RetailCRM API Go client

This is golang RetailCRM API client.

Installation

go get -u github.com/retailcrm/api-client-go/v2

Usage

Example:

package main

import (
	"log"

	"github.com/retailcrm/api-client-go/v2"
)

func main() {
	var client = retailcrm.New("https://demo.retailcrm.pro", "09jIJ09j0JKhgyfvyuUIKhiugF")

	data, status, err := client.Orders(retailcrm.OrdersRequest{
		Filter: retailcrm.OrdersFilter{},
		Limit: 20,
		Page: 1,
	})
	if err != nil {
		if apiErr, ok := retailcrm.AsAPIError(err); ok {
			log.Fatalf("http status: %d, %s", status, apiErr.String())
        }

		log.Fatalf("http status: %d, error: %s", status, err)
	}

	for _, value := range data.Orders {
		log.Printf("%v\n", value.Email)
	}

	log.Println(data.Orders[1].FirstName)

	inventories, status, err := client.InventoriesUpload([]retailcrm.InventoryUpload{
			{
				XMLID: "pTKIKAeghYzX21HTdzFCe1",
				Stores: []retailcrm.InventoryUploadStore{
					{
						Code: "test-store-v5",
						Available: 10,
						PurchasePrice: 1500,
					},
					{
						Code: "test-store-v4",
						Available: 20,
						PurchasePrice: 1530,
					},
					{
						Code: "test-store",
						Available: 30,
						PurchasePrice: 1510,
					},
				},
			},
			{
				XMLID: "JQIvcrCtiSpOV3AAfMiQB3",
				Stores: []retailcrm.InventoryUploadStore{
					{
						Code: "test-store-v5",
						Available: 45,
						PurchasePrice: 1500,
					},
					{
						Code: "test-store-v4",
						Available: 32,
						PurchasePrice: 1530,
					},
					{
						Code: "test-store",
						Available: 46,
						PurchasePrice: 1510,
					},
				},
			},
		},
	)
	if err != nil {
		if apiErr, ok := retailcrm.AsAPIError(err); ok {
			log.Fatalf("http status: %d, %s", status, apiErr.String())
		}

		log.Fatalf("http status: %d, error: %s", status, err)
	}

	log.Println(inventories.ProcessedOffersCount)
}

You can use different error types and retailcrm.AsAPIError to process client errors. Example:

package retailcrm

import (
	"errors"
	"log"
	"os"
	"strings"

	"github.com/retailcrm/api-client-go/v2"
)

func main() {
	var client = retailcrm.New("https://demo.retailcrm.pro", "09jIJ09j0JKhgyfvyuUIKhiugF")

	resp, status, err := client.APICredentials()
	if err != nil {
		apiErr, ok := retailcrm.AsAPIError(err)
		if !ok {
			log.Fatalf("http status: %d, error: %s", status, err)
		}

		switch {
		case errors.Is(apiErr, retailcrm.ErrMissingCredentials):
			log.Fatalln("No API key provided.")
		case errors.Is(apiErr, retailcrm.ErrInvalidCredentials):
			log.Fatalln("Invalid API key.")
		case errors.Is(apiErr, retailcrm.ErrAccessDenied):
			log.Fatalln("Access denied. Please check that the provided key has access to the credentials info.")
		case errors.Is(apiErr, retailcrm.ErrAccountDoesNotExist):
			log.Fatalln("There is no RetailCRM at the provided URL.")
		case errors.Is(apiErr, retailcrm.ErrMissingParameter):
			// retailcrm.APIError in this case will always contain "Name" key in the errors list with the parameter name.
			log.Fatalln("This parameter should be present:", apiErr.Errors()["Name"])
		case errors.Is(apiErr, retailcrm.ErrValidation):
			log.Println("Validation errors from the API:")

			for name, value := range apiErr.Errors() {
				log.Printf(" - %s: %s\n", name, value)
			}

			os.Exit(1)
		case errors.Is(apiErr, retailcrm.ErrGeneric):
			log.Fatalf("failure from the API. %s", apiErr.String())
		}
	}

	log.Println("Available scopes:", strings.Join(resp.Scopes, ", "))
}

Upgrading

Please check the UPGRADING.md to learn how to upgrade to the new version.

# Functions

AsAPIError returns APIError and true if provided error is an APIError or contains wrapped APIError.
CreateAPIError from the provided response data.
CreateGenericAPIError for the situations when API response cannot be processed, but response was actually received.
DebugLoggerAdapter returns BasicLogger that calls underlying DebugLogger.Debugf.
New initialize client.
NewAPIError returns API error with the provided message.
NewConnectResponse returns ConnectResponse with the provided account URL.

# Constants

ByExternalId is "externalId" constant to use as `by` property in methods.
ByID is "id" constant to use as `by` property in methods.
HTTPStatusUnknown can return for the method `/api/v5/customers/upload`, `/api/v5/customers-corporate/upload`, `/api/v5/orders/upload`.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TemplateItemTypeText is a type for text chunk in template.
TemplateItemTypeVar is a type for variable in template.
TemplateVarCustom is a custom variable type.
TemplateVarFirstName is a first name variable type.
TemplateVarLastName is a last name variable type.
TemplateVarName is a name variable type.
No description provided by the author

# Variables

ErrAccessDenied will be returned in case of "Access denied" error.
ErrAccountDoesNotExist will be returned if target system does not exist.
ErrGeneric will be returned if error cannot be classified as one of the errors above.
ErrInvalidCredentials will be returned if provided API key is invalid.
ErrMissingCredentials will be returned if no API key was provided to the API.
ErrMissingParameter will be returned if parameter is missing.
ErrValidation will be returned in case of validation errors.
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
AccountBonusOperationsRequest type.
AccountBonusOperationsResponse type.
Action type.
No description provided by the author
Activity struct.
AdditionalCode type.
Address type.
APIKey type.
Attachment type.
BaseProduct type.
No description provided by the author
No description provided by the author
No description provided by the author
BonusOperation struct.
BonusOperationsFilter type.
BonusOperationsRequest type.
BonusOperationsResponse type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client type.
ClientID type.
ClientIDResponse type.
No description provided by the author
No description provided by the author
ConnectionConfigResponse contains connection configuration for one-step connection.
ConnectRequest contains information about the system connection that is requested to be created.
ConnectResponse should be returned to the one-step connection request in case of successful connection.
Contragent type.
CorporateCustomer type.
CorporateCustomerAddress type.
CorporateCustomerAddressesFilter type.
CorporateCustomerAddressesRequest type.
CorporateCustomerCompaniesResponse type.
No description provided by the author
No description provided by the author
CorporateCustomerContactsResponse type.
CorporateCustomerHistoryRecord type.
CorporateCustomerNote type.
CorporateCustomerResponse type.
CorporateCustomersAddressesResponse type.
CorporateCustomersFilter type.
CorporateCustomersHistoryFilter type.
CorporateCustomersHistoryRequest type.
CorporateCustomersHistoryResponse type.
CorporateCustomersNotesFilter type.
CorporateCustomersNotesRequest type.
CorporateCustomersNotesResponse type.
CorporateCustomersRequest type.
CorporateCustomersResponse type.
Cost type.
CostGroup type.
CostGroupsResponse type.
CostItem type.
CostItemsResponse type.
CostRecord type.
CostResponse type.
CostsDeleteResponse type.
CostsFilter type.
CostsRequest type.
CostsResponse type.
CostsUploadResponse type.
CountriesResponse type.
Courier type.
CouriersResponse type.
No description provided by the author
CreateResponse type.
CredentialResponse return available API methods.
Currency type.
CurrencyCreateResponse type.
CurrencyResponse type.
CursorPagination type.
CustomDictionariesFilter type.
CustomDictionariesRequest type.
CustomDictionariesResponse type.
CustomDictionary type.
CustomDictionaryResponse type.
Customer type.
No description provided by the author
CustomerChangeResponse type.
CustomerHistoryRecord type.
CustomerRequest type.
CustomerResponse type.
CustomersFilter type.
CustomersHistoryFilter type.
CustomersHistoryRequest type.
CustomersHistoryResponse type.
CustomersRequest type.
CustomersResponse type.
CustomersUploadRequest type.
CustomersUploadResponse type.
CustomFieldResponse type.
CustomFields type.
CustomFieldsFilter type.
CustomFieldsRequest type.
CustomFieldsResponse type.
CustomResponse type.
Delivery type.
DeliveryDataField type.
DeliveryHistoryRecord type.
No description provided by the author
DeliveryService type.
DeliveryServiceResponse type.
DeliveryShipment type.
DeliveryShipmentResponse type.
DeliveryShipmentsRequest type.
DeliveryShipmentsResponse type.
DeliveryShipmentUpdateResponse type.
DeliveryStatus type.
DeliveryTime type.
DeliveryTrackingRequest type.
DeliveryType type.
DeliveryTypeInfo type.
DeliveryTypesResponse type.
No description provided by the author
No description provided by the author
Element type.
ErrorResponse should be returned to the one-step connection request in case of failure.
No description provided by the author
ExternalPhone type.
File type.
FileResponse type.
FilesFilter type.
FilesRequest type.
FilesResponse type.
FileUpload response.
GeoHierarchyRow type.
No description provided by the author
IdentifiersPair type.
IdentifiersPairFilter type.
IdentifiersPairRequest type.
IntegrationModule type.
IntegrationModuleEditResponse type.
IntegrationModuleResponse type.
Integrations type.
InventoriesFilter type.
InventoriesRequest type.
InventoriesResponse type.
Inventory type.
InventoryUpload type.
InventoryUploadStore type.
LegalEntitiesResponse type.
LegalEntity type.
LinkedOrder type.
No description provided by the author
No description provided by the author
Loyalty type.
LoyaltyAccount type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LoyaltyLevel type.
No description provided by the author
No description provided by the author
MgBot type.
No description provided by the author
No description provided by the author
No description provided by the author
MgInfo type.
No description provided by the author
No description provided by the author
MgTransport type.
No description provided by the author
NonWorkingDays type.
Note type.
NotesFilter type.
NotesRequest type.
NotesResponse type.
No description provided by the author
Offer type.
OfferPrice type.
OfferPriceUpload type.
No description provided by the author
No description provided by the author
OperationBonus struct.
OperationEvent struct.
OperationLoyalty struct.
OperationLoyaltyAccount struct.
OperationOrder struct.
OperationResponse type.
Order type.
OrderCreateResponse type.
OrderDelivery type.
OrderDeliveryData type.
OrderDeliveryDataBasic type.
OrderDeliveryService type.
OrderDeliveryTime type.
OrderItem type.
OrderLink type.
OrderMarketplace type.
OrderMethod type.
OrderMethodsResponse type.
OrderPayment type.
No description provided by the author
OrderRequest type.
OrderResponse type.
OrdersFilter type.
OrdersHistoryFilter type.
OrdersHistoryRecord type.
OrdersHistoryRequest type.
OrdersHistoryResponse type.
OrdersRequest type.
OrdersResponse type.
OrdersStatus type.
OrdersStatusesRequest type.
OrdersStatusesResponse type.
OrdersUploadRequest type.
OrdersUploadResponse type.
OrderType type.
OrderTypesResponse type.
Pack type.
PackItem type.
PackResponse type.
PacksFilter type.
PacksHistoryRecord type.
PacksHistoryRequest type.
PacksHistoryResponse type.
PacksRequest type.
PacksResponse type.
Pagination type.
Payment type.
PaymentStatus type.
PaymentStatusesResponse type.
PaymentType type.
PaymentTypesResponse type.
Phone type.
Plate type.
PriceType type.
PriceTypesResponse type.
PriceUpload type.
Product type.
ProductCreate type.
ProductEdit type.
ProductEditGroupInput type.
No description provided by the author
ProductGroup type.
No description provided by the author
No description provided by the author
ProductsFilter type.
ProductsGroupsFilter type.
ProductsGroupsRequest type.
ProductsGroupsResponse type.
ProductsPropertiesFilter type.
ProductsPropertiesRequest type.
ProductsPropertiesResponse type.
ProductsRequest type.
ProductsResponse type.
ProductStatus type.
ProductStatusesResponse type.
Property type.
ResponseInfo type.
No description provided by the author
Segment type.
SegmentsFilter type.
SegmentsRequest type.
SegmentsResponse type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SerializedOrderLink type.
Settings type.
SettingsNode represents an item in settings.
SettingsResponse type.
ShipmentFilter type.
Site type.
SitesResponse type.
No description provided by the author
Source type.
SourcesResponse type.
Status type.
StatusesResponse type.
StatusGroup type.
StatusGroupsResponse type.
Store type.
No description provided by the author
StoresResponse type.
StoreUploadResponse type.
SuccessfulResponse type.
SystemInfoResponse return system info.
Tag struct.
Task type.
TaskResponse type.
TasksFilter type.
TasksRequest type.
TasksResponse type.
Telephony type.
No description provided by the author
TextTemplateItem is a part of template.
Unit type.
UnitsResponse type.
UpdateScopesResponse update scopes response.
User type.
UserGroup type.
UserGroupsRequest type.
UserGroupsResponse type.
UserResponse type.
UsersFilter type.
UsersRequest type.
UsersResponse type.
VersionResponse return available API versions.
Warehouse type.
WorkTime type.

# Interfaces

APIError returns when an API error was occurred.
BasicLogger provides basic functionality for logging.
DebugLogger can be used to easily wrap any logger with Debugf method into the BasicLogger instance.

# Type aliases

APIErrorsList struct.
No description provided by the author
CorporateCustomerChangeResponse type.
CorporateCustomersUploadResponse type.
No description provided by the author
GeoID type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author