package module
Version: v1.5.0 Latest Latest

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

Go to latest
Published: Jun 8, 2021 License: MPL-2.0 Imports: 15 Imported by: 0



cv3go is a go library for working with the CV3 API

It has been developed to accomplish specific integrations, so certain API functions and fields may not be included but should be trivial to add since the core connection and parsing is already being done.


Run go get to download via git.

go get

Quick start

Use this library from your Go program like this but with your real credentials:

package main

import (


func main() {
	cv3username, cv3password, cv3apiKey := "**********", "*********", "***********"

	log.Printf("Getting product ids from CV3\r\n")
	api := cv3go.NewApi()
	api.Debug = true
	api.SetCredentials(cv3username, cv3password, cv3apiKey)
	data := api.Execute()

Other Useful Snippits

	api.Debug = false // turn off all the XML printing and such
	// get new orders, or a range or orders
	// api.GetOrdersRange("20010156", "20010158")
	data := api.Execute()
	orders := api.UnmarshalOrders(data)
	log.Printf("Found %v pending orders\r\n", len(orders.Orders))
	for i := range orders.Orders {
		// ... do stuff with each order ...
	// get catalog requests
	catalogs := api.GetCatalogRequestsNew()
	log.Printf("Found %v pending requests to process\r\n", len(catalogs.CatalogRequests))
	for i := range catalogs.CatalogRequests {
		log.Printf("Catalog Request #%v importing\r\n", catalogs.CatalogRequests[i].CatalogId)
	// get product details
	data := api.Execute()
	// confirm receipt of order (remove from pending)
	data := api.Execute()

You will probably want to create a config file to store the authentication data in, since the password gets rotated a good bit and you'll need to pop in and update it occassionally. The Go Text Template library is very useful for formatting the CV3 data for a 3rd party system or vice versus. I often find myself grabbing data from CV3, pushing it through a Go Template and then submitting it to another API.


Version 1.0 ~ used in in projects prior to 2017. Version 1.1 ~ used in projects 2017 - 2018.



Package cv3go is used to connect to the CV3 API



This section is empty.


This section is empty.


func CheckUTF8

func CheckUTF8(b []byte) []byte

CheckUTF8 converts []byte to []rune to string to []byte to make sure only utf8 characters are used.

func PrintToFile

func PrintToFile(b []byte, fileName string)

PrintToFile will print the passed in []bytes to a file

func StringToIntSlice

func StringToIntSlice(strs []string) []int

StringToIntSlice converts a slice of strings into a sorted slice of inherits used in GetAllCategoriesExcept()


type Api

type Api struct {
	Debug bool
	// contains filtered or unexported fields

Api is the struct to send api calls

func NewApi

func NewApi() *Api

NewApi Generate a new API

func (*Api) CatalogRequestConfirm

func (self *Api) CatalogRequestConfirm(o string)

CatalogRequest Set request to catalogRequestConfirm->CatalogRequestID(o)

func (*Api) Execute

func (self *Api) Execute() (n []byte)

Execute Sends the request, return the response Note, one of the above requests must be set up first, and the credentials must be set up for this to work

func (*Api) GetAllCategories

func (self *Api) GetAllCategories(isTopLevel bool)

GetAllCategories uses reqCategoryRange with no end set

func (*Api) GetAllCategoriesExcept

func (self *Api) GetAllCategoriesExcept(exceptIDs []string)

GetAllCategoriesExcept uses reqCategoryRange with a passed in slice of ids to skip

func (*Api) GetCatalogRequestsNew

func (self *Api) GetCatalogRequestsNew() CatalogRequests

GetCatalogRequestsNew Set the request to reqCatalogRequests->reqNew

func (*Api) GetCustomerGroups

func (self *Api) GetCustomerGroups()

GetCustomerGroups Set the request to reqCustomerInformation

func (*Api) GetOrdersNew

func (self *Api) GetOrdersNew()

GetOrdersNew Set the request to reqOrders->reqOrderNew

func (*Api) GetOrdersRange

func (self *Api) GetOrdersRange(o string, p string)

GetOrdersRange Set the request to reqOrders->reqOrderOutOfStockPointRange from o to p

func (*Api) GetProductIds

func (self *Api) GetProductIds() ProductIDs

GetProductIds Set the request to reqProductIDs

func (*Api) GetProductRange

func (self *Api) GetProductRange(start string, end string)

GetProductRange Set the request to reqProducts->reqProductRange using start and end to dictate the range

func (*Api) GetProductSKU

func (self *Api) GetProductSKU(o string, t bool)

GetProductSKU Set the request to reqProducts->reqProductSKU containing string(o) as the data

func (*Api) GetProductSKUs

func (self *Api) GetProductSKUs(o []string, t bool)

GetProductSKUs gets the product skus

func (*Api) GetProductSingle

func (self *Api) GetProductSingle(o []string)

GetProductSingle Set the request to reqProducts->reqProductSingle containing string(o) as the data

func (*Api) GetProductSingleBySKU

func (self *Api) GetProductSingleBySKU(o string)

GetProductSingleBySKU is from Ben, to get a singlee product by sku

func (*Api) GetProductSkus

func (self *Api) GetProductSkus()

GetProductSkus Set the request to reqProductSKU

func (*Api) OrderConfirm

func (self *Api) OrderConfirm(o []string)

OrderConfirm Set request to orderConfirm->orderConf using string o as contents

func (*Api) PushInventory

func (self *Api) PushInventory(o string, t bool)

PushInventory Set the request to an inventory update call using o as the data

func (*Api) SetCredentials

func (self *Api) SetCredentials(username, password, serviceID string)

SetCredentials Set the credentials of the API

func (*Api) UnmarshalCategories

func (self *Api) UnmarshalCategories(n []byte) Categories


func (*Api) UnmarshalInventory

func (self *Api) UnmarshalInventory(n []byte) Products

UnmarshalInventory Convert an XML response containing Inventory to a Products object

func (*Api) UnmarshalOrders

func (self *Api) UnmarshalOrders(n []byte) Orders

UnmarshalOrders Convert an XML response containing order to an Orders object

func (*Api) UnmarshalProduct

func (self *Api) UnmarshalProduct(n []byte) Product

UnmarshalProduct Convert an XML response containing a single product to a Product object

func (*Api) UpdateOrderStatus

func (a *Api) UpdateOrderStatus(os []OrdStatus)

UpdateOrderStatus Set request to status->[orderID(o),status(p),tracking(q)]

func (*Api) UpdateProducts

func (api *Api) UpdateProducts(products []Product, createNew bool)

UpdateProducts sends any fields that need updating, fields not sent remain current values, the second value notes if we should ignore new products

type Attribute

type Attribute struct {
	Active string   `xml:"active,attr,omitempty"`
	Values []string `xml:"Value,omitempty"`

Attribute holds product attribute information

type C

type C struct {
	// XMLName xml.Name `xml:"CV3Data"`
	CV3Data       RequestBody
	Confirms      []Confirm     `xml:"confirm"`
	OrderStatuses []OrderStatus `xml:"orders"`
	Products      Products      `xml:"products"`

C s

type CV3Data

type CV3Data struct {
	// XMLName xml.Name `xml:"CV3Data"`
	CV3Data       RequestBody
	Confirms      []Confirm     `xml:"confirm"`
	OrderStatuses []OrderStatus `xml:"orders"`
	Products      []ProductCall `xml:"products"`

CV3Data struct

type CatalogRequest

type CatalogRequest struct {
	CatalogId     string `xml:"id,attr"`
	DateRequested string `xml:"DateRequested"`
	Source        string `xml:"Source"`
	Type          string `xml:"Type"`
	FirstName     string `xml:"CustomerInformation>FirstName"`
	LastName      string `xml:"CustomerInformation>LastName"`
	Company       string `xml:"CustomerInformation>Company"`
	Email         string `xml:"CustomerInformation>Email"`
	Phone         string `xml:"CustomerInformation>Phone"`
	Address       string `xml:"CustomerInformation>Address>Address1"`
	Address2      string `xml:"CustomerInformation>Address>Address2"`
	City          string `xml:"CustomerInformation>Address>City"`
	State         string `xml:"CustomerInformation>Address>State"`
	PostalCode    string `xml:"CustomerInformation>Address>PostalCode"`
	Country       string `xml:"CustomerInformation>Address>Country"`

type CatalogRequests

type CatalogRequests struct {
	CatalogRequests []CatalogRequest `xml:"catalogRequests>CatalogRequest"`

type Categories

type Categories struct {
	Categories []Category `xml:"categories>category"`

Categories data sructure for Categories

type Category

type Category struct {
	Invisible          string        `xml:"invisible,attr"`
	TopLevel           string        //not sent in xml, set in cv3Intigration.getCategories.go
	Featured           string        `xml:"featured,attr"`
	Name               string        `xml:"Name,omitempty"`
	ID                 string        `xml:"ID,omitempty"`
	URLName            string        `xml:"URLName,omitempty"`
	Description        string        `xml:"Description,omitempty"`
	MetaTitle          string        `xml:"MetaTitle,omitempty"`
	MetaDescription    string        `xml:"MetaDescription,omitempty"`
	MetaKeywords       string        `xml:"MetaKeyword,omitempty"`
	Template           string        `xml:"Template,omitempty"`
	NumProductsPerPage string        `xml:"NumProductsPerPage,omitempty"`
	Products           []string      `xml:"Products>SKU,omitempty"`
	FeaturedProducts   []string      `xml:"FeaturedProducts>SKU,omitempty"`
	CustomFields       []Custom      `xml:"Custom,omitempty"`
	SubCategories      []SubCategory `xml:"SubCategories>SubCategory"`

Category is the struct used when unmarshaling categories

type Confirm

type Confirm struct {
	Confirm string `xml:",innerxml"`

Confirm struct

type Credentials

type Credentials struct {
	XMLName   xml.Name `xml:"authenticate"`
	User      string   `xml:"user"`
	Password  string   `xml:"pass"`
	ServiceID string   `xml:"serviceID"`
	Debug     bool

Credentials struct

func (*Credentials) GetPendingOrders

func (c *Credentials) GetPendingOrders() (*Orders, error)

func (*Credentials) GetPendingOrdersWithProducts

func (c *Credentials) GetPendingOrdersWithProducts() (*Orders, error)

func (*Credentials) RemoveOrdersFromPending

func (c *Credentials) RemoveOrdersFromPending(orders *Orders) error

func (*Credentials) UpdateOrderStatus

func (c *Credentials) UpdateOrderStatus(status []OrdStatus) error

func (*Credentials) UpdateProducts

func (c *Credentials) UpdateProducts(products []Product, createNew bool) error

UpdateProducts matches on sku and submits any updates to the products to CV3. The first option sets whether new products should be created if the sku doesn't exist

type Custom

type Custom struct {
	ID     string `xml:"id,attr"`
	Custom string `xml:",chardata"`

Custom is the struct to hold the custom fields

type CustomField

type CustomField struct {
	Value string `xml:",innerxml"`

type DependancyProducts

type DependancyProducts struct {
	Type string   `xml:"type,attr,omitempty"`
	SKUs []string `xml:"SKU,omitempty"`

DependancyProducts holds the sku of the product that is depended upon

type Document

type Document struct {
	DaysAvailable string `xml:"DaysAvailable,omitempty"`
	Description   string `xml:"Description,omitempty"`

Document holds information dealing with the electronic delivery

type ElectronicDelivery

type ElectronicDelivery struct {
	Active   string   `xml:"active,attr,omitempty"`
	Document Document `xml:"Document,omitempty"`

ElectronicDelivery holds the information about the products electronic delivery

type GiftCardPayment

type GiftCardPayment struct {
	Certificate string `xml:"giftCertificate"`
	Amount      string `xml:"amountUsed"`

type GiftCertificate

type GiftCertificate struct {
	Active        string `xml:"active,attr,omitempty"`
	DaysAvailable string `xml:"DaysAvailable,omitempty"`
	Value         string `xml:"Value,omitempty"`

GiftCertificate hold information about gift certificates

type Image

type Image struct {
	ImageSetThumb  string `xml:"Thumbnail,omitempty"`
	ImageSetLarge  string `xml:"Large,omitempty"`
	ImageSetPoprUp string `xml:"PopUp,omitempty"`

Image is the struct for marshalling and unmarshalling cv3's Images node

type Images

type Images struct {
	Image []Image `xml:"Image,omitempty"`

Images is the struct for marshalling and unmarshalling cv3's Images node

type InventoryControl

type InventoryControl struct {
	InventoryControlExempt   string `xml:"inventory_control_exempt,attr,omitempty"`
	InventoryStatus          string `xml:"Status,omitempty"`
	InventoryOnHand          string `xml:"Inventory,omitempty"`
	OnOrder                  string `xml:"OnOrder,omitempty"`
	InventoryBackorderedDate string `xml:"InventoryBackorderedDate,omitempty"`
	OutOfStock               string `xml:"OutOfStockPoint,omitempty"`

InventoryControl struct for marshalling and unmarshalling cv3's xml node of InventoryControl

type Meta

type Meta struct {
	MetaKeywords    string `xml:"Keyword,omitempty"`
	MetaTitle       string `xml:"Title,omitempty"`
	MetaDescription string `xml:"Description,omitempty"`

Meta is the struct for marshalling and unmarshalling the cv3's Meta node

type OrdStatus

type OrdStatus struct {
	OrderID                  string
	Status                   string
	Tracking                 string
	CustomerNumber           string
	SendTrackingNotification bool

OrdStatus holds our data to update orders with new tracking info. It is named badly because I can't figure out what the existing OrderStatus struct is doing.

type Order

type Order struct {
	SubTotal              string
	OrderID               string             `xml:"orderID"`
	PriceCategory         string             `xml:"priceCategory"`
	TotalPrice            string             `xml:"totalPrice"`
	TotalShipping         string             `xml:"totalShipping"`
	TotalTax              string             `xml:"totalTax"`
	DateOrdered           string             `xml:"dateOrdered"`
	TimeOrdered           string             `xml:"timeOrdered"`
	PayMethod             string             `xml:"payMethod"`
	SourceCode            string             `xml:"sourceCode"`
	PromoCode             string             `xml:"promoCode"`
	Comments              string             `xml:"comments"`
	IP                    string             `xml:"IP"`
	BillingCompany        string             `xml:"billing>company"`
	BillingFirstName      string             `xml:"billing>firstName"`
	BillingLastName       string             `xml:"billing>lastName"`
	BillingTitle          string             `xml:"billing>title"`
	BillingAddress        string             `xml:"billing>address1"`
	BillingAddress2       string             `xml:"billing>address2"`
	BillingCity           string             `xml:"billing>city"`
	BillingState          string             `xml:"billing>state"`
	BillingZip            string             `xml:"billing>zip"`
	BillingCountry        string             `xml:"billing>country"`
	BillingEmail          string             `xml:"billing>email"`
	BillingPhone          string             `xml:"billing>phone"`
	BillingOptOut         string             `xml:"billing>optOut"`
	BillingTransactionID  string             `xml:"billing>CCInfo>transactionID"`
	MemberID              string             `xml:"billing>memberID"`
	CCType                string             `xml:"billing>CCInfo>CCType"`
	CCName                string             `xml:"billing>CCInfo>CCName"`
	CCNum                 string             `xml:"billing>CCInfo>CCNum"`
	CCExpM                string             `xml:"billing>CCInfo>CCExpM"`
	CCExpY                string             `xml:"billing>CCInfo>CCExpY"`
	AuthCode              string             `xml:"billing>CCInfo>authCode"`
	AuthAmount            string             `xml:"billing>CCInfo>authAmount"`
	RequestToken          string             `xml:"billing>CCInfo>token"`
	PurchaseOrder         string             `xml:"purchaseOrder"`
	PayPalBuyer           string             `xml:"payPalInfo>Buyer"`
	PayPalAmount          string             `xml:"payPalInfo>Amount"`
	PayPalTransactionID   string             `xml:"payPalInfo>TransactionID"`
	ShipTos               []ShipTo           `xml:"shipTos>shipTo"`
	CustomFields          []CustomField      `xml:"customFields>customField"`
	TotalOrderDiscount    TotalOrderDiscount `xml:"totalOrderDiscount"`
	GiftCardPayments      []GiftCardPayment  `xml:"billing>GCInfo>giftCertificateUsed"`
	GiftCardPaymentsTotal string             `xml:"billing>GCInfo>totalAmountUsed"`

type OrderStatus

type OrderStatus struct {
	OrderStatus string `xml:",innerxml"`

OrderStatus struct

type Orders

type Orders struct {
	Orders []Order `xml:"orders>order"`

type Package

type Package struct {
	ShipsInOwnBox string `xml:"ships_in_own_box,attr,omitempty"`
	Length        string `xml:"Length,omitempty"`
	Width         string `xml:"Width,omitempty"`
	Height        string `xml:"Height,omitempty"`

Package hold the shipping package information

type Price

type Price struct {

type Pricing

type Pricing struct {
	PriceCategory string `xml:"price_category,attr,omitempty"`
	StandardPrice string `xml:"StandardPrice,omitempty"`
	SpecialPrice  string `xml:"SpecialPrice,omitempty"`

Pricing is the struct for marshalling and unmarshalling cv3's price node

type ProdCategories

type ProdCategories struct {
	IDs []string `xml:"ID,omitempty"`

ProdCategories is the struct for marshalling and unmarshalling cv3's Categories node

type ProdCustomField

type ProdCustomField struct {
	Id    string `xml:"id,attr"`
	Value string `xml:",cdata"`

CustomFields struct for marshalling and unmarshalling cv3's xml nodes of Custom Fields

type Product

type Product struct {
	XMLName          xml.Name          `xml:"product"`
	Inactive         string            `xml:"inactive,attr"`
	OutOfSeason      string            `xml:"out_of_season,attr,omitempty"`
	Sku              string            `xml:"SKU"`
	ProdId           string            `xml:"ProdID,omitempty"`
	Name             string            `xml:"Name,omitempty"`
	UrlName          string            `xml:"URLName,omitempty"`
	Brand            string            `xml:"Brand,omitempty"`
	Retail           *Retail           `xml:"Retail,omitempty"`
	WholeSale        *WholeSale        `xml:"Wholesale,omitempty"`
	Special          *Special          `xml:"Special,omitempty"`
	Weight           *Weight           `xml:"Weight,omitempty"`
	Shipping         *Shipping         `xml:"Shipping,omitempty"`
	InventoryControl *InventoryControl `xml:"InventoryControl,omitempty"`
	SubProducts      *SubProducts      `xml:"SubProducts,omitempty"`
	Description      string            `xml:"Description,omitempty"`
	Keywords         string            `xml:"Keywords,omitempty"`
	Meta             *Meta             `xml:"Meta,omitempty"`
	Images           *Images           `xml:"Images,omitempty"`
	Categories       *ProdCategories   `xml:"Categories,omitempty"`
	ProdCustomFields []ProdCustomField `xml:"Custom,omitempty"`
	ParentSKU        string            `xml:"ParentSKU,omitempty"`

Product is the struct used when unmarshaling inventory items

type ProductCall

type ProductCall struct {
	ProductCall string `xml:",innerxml"`

ProductCall struct

type ProductIDs

type ProductIDs struct {
	ID []string `xml:"productIDs>ID"`

ProductIDs struct to hold product IDs

type Products

type Products struct {
	XMLName  xml.Name  `xml:"products"`
	Products []Product `xml:"product,omitempty"`

Products data sructure for Products

type Request

type Request struct {
	Request string `xml:",innerxml"`

Request struct

type RequestBody

type RequestBody struct {
	XMLName  xml.Name `xml:"request"`
	Auth     Credentials
	Requests []Request `xml:"requests"`

RequestBody struct

type Retail

type Retail struct {
	Active string    `xml:"active,attr,omitempty"`
	Price  []Pricing `xml:"Price,omitempty"`

Retail is the struct for marshalling and unmarshalling cv3's retail node

type ShipTo

type ShipTo struct {
	Name           string          `xml:"name"`
	FirstName      string          `xml:"firstName"`
	LastName       string          `xml:"lastName"`
	Company        string          `xml:"company"`
	Title          string          `xml:"title"`
	Address        string          `xml:"address1"`
	Address2       string          `xml:"address2"`
	City           string          `xml:"city"`
	State          string          `xml:"state"`
	Zip            string          `xml:"zip"`
	Country        string          `xml:"country"`
	Phone          string          `xml:"phone"`
	Tax            string          `xml:"tax"`
	Shipping       string          `xml:"shipping"`
	Message        string          `xml:"message"`
	ShipMethod     string          `xml:"shipMethod"`
	ShipMethodCode string          `xml:"shipMethodCode"`
	ShipOn         string          `xml:"shipOn"`
	GiftWrap       string          `xml:"giftWrap"`
	ShipToProducts []ShipToProduct `xml:"shipToProducts>shipToProduct"`
	ShipEmail      string          `xml:"shipEmail"`

type ShipToProduct

type ShipToProduct struct {
	SKU      string `xml:"SKU"`
	Quantity string `xml:"quantity"`
	Price    string `xml:"price"`
	Product  Product

data structures for Orders

type Shipping

type Shipping struct {
	ShipPreference string  `xml:"ShipPreference,omitempty"`
	FixedRate      string  `xml:"FixedRate,omitempty"`
	Package        Package `xml:"Package,omitempty"`

Shipping hold the products shipping information

type Special

type Special struct {
	Ongoing   string `xml:"ongoing,attr,omitempty"`
	AllowFree string `xml:"allow_free,attr,omitempty"`
	Start     string `xml:"Start,omitempty"`
	End       string `xml:"End,omitempty"`

Special hold the pricing information for a special sale

type SubCategory

type SubCategory struct {
	Name      string `xml:"Name"`
	ID        string `xml:"ID"`
	Invisible string `xml:"invisible,attr"`

SubCategory is the struct to hold the Subcategories

type SubProduct

type SubProduct struct {
	XMLName              xml.Name           `xml:"SubProduct"`
	Active               string             `xml:"active,attr,omitempty"`
	Inactive             string             `xml:"inactive,attr,omitempty"`
	OutOfSeason          string             `xml:"out_of_season,attr,omitempty"`
	TaxExempt            string             `xml:"tax_exempt,attr,omitempty"`
	GoogleCheckoutExempt string             `xml:"google_checkout_exempt,attr,omitempty"`
	Sku                  string             `xml:"SKU,omitempty"`
	AltID                string             `xml:"AltID,omitempty"`
	ProdId               string             `xml:"ProdID,omitempty"`
	Name                 string             `xml:"Name,omitempty"`
	Image                string             `xml:"Image,omitempty"`
	Retail               Retail             `xml:"Retail,omitempty"`
	WholeSale            WholeSale          `xml:"WholeSale,omitempty"`
	Special              Special            `xml:"Special,omitempty"`
	Weight               Weight             `xml:"Weight,omitempty"`
	Shipping             Shipping           `xml:"Shipping,omitempty"`
	GiftCertificate      GiftCertificate    `xml:"GiftCertificate,omitempty"`
	Subscription         Subscription       `xml:"Subscription,omitempty"`
	ElectronicDelivery   ElectronicDelivery `xml:"ElectronicDelivery,omitempty"`
	Attribute            Attribute          `xml:"Attribute,omitempty"`
	InventoryControl     InventoryControl   `xml:"InventoryControl,omitempty"`

SubProduct TODO good description

type SubProducts

type SubProducts struct {
	SubProducts []SubProduct `xml:"SubProduct,omitempty"`
	Active      string       `xml:"active,attr"`

SubProducts is an array of type SubProduct

type Subscription

type Subscription struct {
	Active string `xml:"active,attr,omitempty"`
	Price  string `xml:"Price,omitempty"`

Subscription hold the product subscription information

type TotalOrderDiscount

type TotalOrderDiscount struct {
	Amount        string `xml:"amount"`
	TotalDiscount string `xml:"totalDiscount"`
	Type          string `xml:"type,attr"`

type Weight

type Weight struct {
	ShipWeight    string `xml:"ShipWeight,omitempty"`
	DisplayWeight string `xml:"DisplayWeight,omitempty"`
	DisplayUnit   string `xml:"DisplayUnit,omitempty"`

Weight hold the information about the weight

type WholeSale

type WholeSale struct {
	Active        string `xml:"active,attr,omitempty"`
	StandardPrice string `xml:"StandardPrice,omitempty"`
	Qty           string `xml:"Qty,omitempty"`

WholeSale hold pricing info for a wholesale item

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL