netsuite

package module
v0.0.0-...-16b08f5 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 20 Imported by: 0

README

go-netsuite

Go/Golang library for connecting to netsuite rest API

This requires a config/config.yml file in the following format:

netsuite:
    apiURL: https://1234567-sb1.suitetalk.api.netsuite.com/services/rest/record/v1
    account: 1234567_SB1
    token: 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff
    tokenSecret: 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff
    consumerKey: 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff
    consumerSecret: 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff
package main

import (
    "fmt"
    "github.com/mk-j/go-netsuite-rest"
)

func main() {
	conn := netsuite.NetSuiteConnector{}
	conn.ReadConfig("./config/config.yml")

	jsonResponse:= conn.GET("/customer/1234567")
	restCustomer:= restdata.UnmarshalJSONToCustomer(jsonResponse)
	fmt.Println(JsonEncode(restCustomer))
}

Documention on the NetSuite REST API can be found at:

On Date Formats;

On Filtering Data

Field Type Allowed Operators
None EMPTY, EMPTY_NOT
Boolean IS, IS_NOT
Double, Integer, Float, Number, Duration ANY_OF, ANY_OF_NOT, BETWEEN, BETWEEN_NOT, EQUAL, EQUAL_NOT, GREATER, GREATER_NOT, GREATER_OR_EQUAL, GREATER_OR_EQUAL_NOT, LESS, LESS_NOT, LESS_OR_EQUAL, LESS_OR_EQUAL_NOT, WITHIN, WITHIN_NOT
String CONTAIN, CONTAIN_NOT, IS, IS_NOT, START_WITH, START_WITH_NOT, END_WITH, END_WITH_NOT
Date / Time AFTER, AFTER_NOT, BEFORE, BEFORE_NOT, ON, ON_NOT, ON_OR_AFTER, ON_OR_AFTER_NOT, ON_OR_BEFORE, ON_OR_BEFORE_NOT
Operators with varying numbers of values Example
Unary operators: The EMPTY and EMPTY_NOT operators do not accept any values. ?q=companyName EMPTY
Ternary operators: The BETWEEN, BETWEEN_NOT, WITHIN, and WITHIN_NOT operators accept two values. ?q=id BETWEEN_NOT [1, 42]
N-ary operators: The ANY_OF and ANY_OF_NOT operators do accept one or any higher number of values. ?q=id ANY_OF [1, 2, 3, 4, 5]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func HashHmacSha1

func HashHmacSha1(message string, secret string) string

func HashHmacSha256

func HashHmacSha256(message string, secret string) string

func JsonDecode

func JsonDecode(input string) map[string]interface{}

func JsonEncode

func JsonEncode(input interface{}) string

func JsonPrettyPrint

func JsonPrettyPrint(in string) string

func PercentEncode

func PercentEncode(input string) string

func RandInt

func RandInt(min int64, max int64) int64

func RandString

func RandString(s int) string

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string.

Types

type NSAddress

type NSAddress struct {
	Attention string `json:"attention,omitempty"`
	Addressee string `json:"addressee,omitempty"`
	AddrPhone string `json:"addrPhone,omitempty"`
	Addr1     string `json:"addr1,omitempty"`
	Addr2     string `json:"addr2,omitempty"`
	Addr3     string `json:"addr3,omitempty"`
	City      string `json:"city,omitempty"`
	State     string `json:"state,omitempty"`
	Zip       string `json:"zip,omitempty"`
	Country   string `json:"country,omitempty"`
}

not a complete list of struct fields... just the ones we feel like using in this app for more fields, see: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.1/index.html

type NSCreditMemo

type NSCreditMemo struct {
	ExternalId  string                         `json:"externalId,omitempty"`
	Currency    map[string]interface{}         `json:"currency,omitempty"`
	TranDate    string                         `json:"tranDate,omitempty"`
	Entity      map[string]interface{}         `json:"entity,omitempty"`
	Item        map[string][]NSCreditMemoItem  `json:"item,omitempty"`
	CreatedFrom map[string]interface{}         `json:"createdFrom,omitempty"`
	ApplyList   map[string][]NSCreditMemoApply `json:"applyList,omitempty"`
}

not a complete list of creditmemo fields... just the ones we feel like using in this app for more fields, see: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.1/index.html

type NSCreditMemoApply

type NSCreditMemoApply struct {
	Amount float64 `json:"amount,omitempty"`
	Doc    string  `json:"line,omitempty"`
	Apply  bool    `json:"apply,omitempty"`
}

type NSCreditMemoItem

type NSCreditMemoItem struct {
	Quantity    float64           `json:"quantity,omitempty"`
	Amount      float64           `json:"amount,omitempty"`
	Description string            `json:"description,omitempty"` //ProductCache::productName($item_line['product_id']);
	Item        map[string]string `json:"item,omitempty"`        //for externalId of ProductId
	Line        int64             `json:"line,omitempty"`
	OrderLine   int64             `json:"orderLine,omitempty"`
}

type NSCustomer

type NSCustomer struct {
	InternalId        string                 `json:"id,omitempty"`
	ExternalId        string                 `json:"externalId,omitempty"`
	CompanyName       string                 `json:"companyName,omitempty"`
	Email             string                 `json:"email,omitempty"`
	EntityId          string                 `json:"entityId,omitempty"`
	EntityStatus      map[string]interface{} `json:"entityStatus,omitempty"`
	CustomForm        map[string]interface{} `json:"customForm,omitempty"`
	Terms             map[string]interface{} `json:"terms,omitempty"`
	Subsidiary        map[string]interface{} `json:"subsidiary,omitempty"`
	AccountCreateDate string                 `json:"custentity_account_create_date,omitempty"`
}

not a complete list of struct fields... just the ones we feel like using in this app for more fields, see: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.1/index.html

func UnmarshalJSONToCustomer

func UnmarshalJSONToCustomer(json_input string) *NSCustomer

func (*NSCustomer) SetCustomFormId

func (this *NSCustomer) SetCustomFormId(CustomFormId string)

func (*NSCustomer) SetSubsidiary

func (this *NSCustomer) SetSubsidiary(SubsidiaryExternalId string)

func (*NSCustomer) SetTerms

func (this *NSCustomer) SetTerms(TermsExternalId string)

func (*NSCustomer) SetTermsId

func (this *NSCustomer) SetTermsId(TermsInternalId string)

type NSInvoice

type NSInvoice struct {
	BillingAddress  NSAddress                  `json:"billingAddress,omitempty"`
	ShippingAddress NSAddress                  `json:"shippingAddress,omitempty"`
	ExternalId      string                     `json:"externalId,omitempty"`
	InternalId      string                     `json:"internalId,omitempty"`
	TranDate        string                     `json:"tranDate,omitempty"`
	Email           string                     `json:"email,omitempty"`
	OtherRefNum     string                     `json:"otherRefNum,omitempty"`
	Account         map[string]interface{}     `json:"account,omitempty"`
	CreatedFrom     map[string]interface{}     `json:"createdFrom,omitempty"`
	CustomForm      map[string]interface{}     `json:"customForm,omitempty"`
	Terms           map[string]interface{}     `json:"terms,omitempty,omitempty"`
	Currency        map[string]interface{}     `json:"currency,omitempty"`
	Entity          map[string]interface{}     `json:"entity,omitempty"`
	SalesRep        map[string]interface{}     `json:"salesRep,omitempty"`
	Subsidiary      map[string]interface{}     `json:"subsidiary,omitempty"`
	Item            map[string][]NSInvoiceItem `json:"item,omitempty"`
	InvoiceMethod   string                     `json:"custbody_invoice_method,omitempty"` //example custom field
}

not a complete list of struct fields... just the ones we feel like using in this app for more fields, see: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.1/index.html

func (*NSInvoice) AddItem

func (this *NSInvoice) AddItem(itemToAdd NSInvoiceItem)

type NSInvoiceItem

type NSInvoiceItem struct {
	Quantity    float64           `json:"quantity,omitempty"`
	Amount      float64           `json:"amount,omitempty"`
	Description string            `json:"description,omitempty"`
	Item        map[string]string `json:"item,omitempty"`
	Line        int64             `json:"line,omitempty"`
	OrderLine   int64             `json:"orderLine,omitempty"`
}

type NSSalesOrder

type NSSalesOrder struct {
	InternalId      string                        `json:"internalId,omitempty"`
	ExternalId      string                        `json:"externalId,omitempty"`
	CustomForm      map[string]interface{}        `json:"customForm,omitempty"`
	Currency        map[string]interface{}        `json:"currency,omitempty"`
	Memo            string                        `json:"memo,omitempty"`
	OtherRefNum     string                        `json:"otherRefNum,omitempty"`
	TranDate        string                        `json:"tranDate,omitempty"`
	Entity          map[string]interface{}        `json:"entity,omitempty"`
	Item            map[string][]NSSalesOrderItem `json:"item,omitempty"`
	Subsidiary      map[string]interface{}        `json:"subsidiary,omitempty"`
	Terms           map[string]interface{}        `json:"terms,omitempty"`
	SalesRep        map[string]interface{}        `json:"salesRep,omitempty"`
	Message         string                        `json:"message,omitempty"`
	LineOfBusiness  string                        `json:"class,omitempty"`
	Email           string                        `json:"email,omitempty"`
	BillingAddress  NSAddress                     `json:"billingAddress,omitempty"`
	ShippingAddress NSAddress                     `json:"shippingAddress,omitempty"`
	AltLocalName    string                        `json:"custbody_local_name,omitempty"` //example custom field
}

not a complete list of salesorder fields... just the ones we feel like using in this app for more fields, see: https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.1/index.html

func (*NSSalesOrder) AddItem

func (this *NSSalesOrder) AddItem(itemToAdd NSSalesOrderItem)

----------------------------------------------------------------------

func (*NSSalesOrder) SetCurrency

func (this *NSSalesOrder) SetCurrency(CurrencyExternalId string)

func (*NSSalesOrder) SetCustomFormId

func (this *NSSalesOrder) SetCustomFormId(CustomFormId string)

func (*NSSalesOrder) SetEntity

func (this *NSSalesOrder) SetEntity(EntityExternalId string)

func (*NSSalesOrder) SetSalesRepId

func (this *NSSalesOrder) SetSalesRepId(SalesRepInternalId string)

func (*NSSalesOrder) SetSubsidiary

func (this *NSSalesOrder) SetSubsidiary(SubsidiaryExternalId string)

func (*NSSalesOrder) SetTerms

func (this *NSSalesOrder) SetTerms(TermsExternalId string)

func (*NSSalesOrder) SetTermsId

func (this *NSSalesOrder) SetTermsId(TermsInternalId string)

type NSSalesOrderItem

type NSSalesOrderItem struct {
	Quantity    float64           `json:"quantity,omitempty"`
	Amount      float64           `json:"amount,omitempty"`
	Description string            `json:"description,omitempty"`
	Item        map[string]string `json:"item,omitempty"`
	Line        int64             `json:"line,omitempty"`
}

type NetSuiteConnector

type NetSuiteConnector struct {
	Auth struct {
		Account        string `yaml:"account"`
		ConsumerKey    string `yaml:"consumerKey"`
		ConsumerSecret string `yaml:"consumerSecret"`
		Token          string `yaml:"token"`
		TokenSecret    string `yaml:"tokenSecret"`
		APIURL         string `yaml:"apiURL"`
	} `yaml:"netsuite"`
	ConfigFile     string
	LastInsertId   int
	LastStatusCode int
	LastStatus     string
}

func (*NetSuiteConnector) At

func (r *NetSuiteConnector) At(patharg string, args ...interface{}) NetSuiteRequest

----------------------------------------------------------------------

func (*NetSuiteConnector) DELETE

func (r *NetSuiteConnector) DELETE(patharg string, args ...interface{}) string

----------------------------------------------------------------------

func (*NetSuiteConnector) GET

func (r *NetSuiteConnector) GET(patharg string, args ...interface{}) string

----------------------------------------------------------------------

func (*NetSuiteConnector) POST

func (r *NetSuiteConnector) POST(patharg string, args ...interface{}) string

----------------------------------------------------------------------

func (*NetSuiteConnector) ReadConfig

func (r *NetSuiteConnector) ReadConfig(path string)

----------------------------------------------------------------------

type NetSuiteRequest

type NetSuiteRequest struct {
	Connection  *NetSuiteConnector
	RequestURL  string
	QueryParams map[string]string
	RequestBody interface{} //can pass in json encoded string, or a struct or map here
}

func (NetSuiteRequest) DELETE

func (r NetSuiteRequest) DELETE() string

----------------------------------------------------------------------

func (NetSuiteRequest) GET

func (r NetSuiteRequest) GET() string

func (NetSuiteRequest) INSERT

func (r NetSuiteRequest) INSERT(post_json interface{}) string

func (NetSuiteRequest) PATCH

func (r NetSuiteRequest) PATCH(post_json interface{}) string

----------------------------------------------------------------------

func (NetSuiteRequest) POST

func (r NetSuiteRequest) POST(post_json interface{}) string

----------------------------------------------------------------------

func (NetSuiteRequest) PUT

func (r NetSuiteRequest) PUT(post_json interface{}) string

----------------------------------------------------------------------

func (NetSuiteRequest) Query

func (r NetSuiteRequest) Query(QueryParams map[string]string) NetSuiteRequest

---------------------------------------------------------------------- ----------------------------------------------------------------------

func (NetSuiteRequest) UPDATE

func (r NetSuiteRequest) UPDATE(post_json interface{}) string

func (NetSuiteRequest) UPSERT

func (r NetSuiteRequest) UPSERT(post_json interface{}) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL