Skip to content

Creating Resources

Andrew Waters edited this page Mar 29, 2019 · 1 revision

You will need to use a client instantiated with client credentials to create resources

client := gomo.NewClient(
	gomo.NewClientCredentials(
		os.Getenv("CLIENT_ID"),
		os.Getenv("CLIENT_SECRET"),
	),
)

if err := client.Authenticate(); err != nil {
	log.Fatal(err)
}

price := make([]entities.ProductPrice, 0)
price = append(price, entities.ProductPrice{
	Amount:      10000,
	Currency:    "USD",
	IncludesTax: true,
})

product := entities.Product{
	Name:          "A new product",
	Slug:          fmt.Sprintf("product-slug-%d", unique),
	SKU:           fmt.Sprintf("sku.product.%d", unique),
	Description:   "A product description",
	ManageStock:   false,
	Price:         price,
	Status:        "live",
	CommodityType: "physical",
}

r, _ := client.Post("products", &product)
r, _ = client.Get(fmt.Sprintf("products/%s", product.ID), &product)
Clone this wiki locally