SuiteRest-Go
NetSuite wrapper to connect with REST Web Services
Requirements:
- golang 1.16+
- oapi-codegen
go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen
- Set NetSuite REST Web Services must be enabled (see docs)
- Make a copy of cmd/.env and fill with required values
- account number
- consumer key
- consumer secret
- token id
- token secret
- dotenv rules apply for .env files
cmd/generator.go
Uses your NetSuite account information to generate OpenAPI record definitions and client files
go run generator.go customer --package=record
Output files will be stored in the current path
Application
Example getting customer information:
package main
import (
"context"
"encoding/json"
"github.com/felipechang/sample/customer"
"github.com/felipechang/suiterest-go/file"
"github.com/felipechang/suiterest-go/request"
"github.com/joho/godotenv"
"log"
)
func main() {
// load .env file
err := godotenv.Load()
var c *customer.Customer
// build params
params := request.NewParams(&request.Params{
Config: file.GetAuthConfig(),
})
// load the request client with auth headers
newClient, err := customer.NewClientWithResponses(
params.GetBasePath(),
customer.WithRequestEditorFn(params.GetWithRequestEditorFn),
)
if err != nil {
log.Fatalln(err)
}
// get email from customer
fields := "email"
response, err := newClient.GetCustomerIdWithResponse(
context.Background(),
11111111,
&customer.GetCustomerIdParams{
Fields: &fields,
})
if err != nil {
log.Fatalln(err)
}
// unmarshall into generated Customer struct
err = json.Unmarshal(response.Body, &c)
if err != nil {
log.Fatalln(err)
}
log.Println("Email", *c.Email)
}