Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk

Build Status codecov Go Report Card GoDoc

The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefore be nearly feature complete.

The SDK was initially created for enabling the creation of the Terraform Provider for Commercetools That provider enables you to use infrastructure-as-code principles with Commercetools.

Using the SDK

", Endpoints: commercetools.NewClientEndpoints("europe-west1", "gcp"), Credentials: &commercetools.ClientCredentials{ ClientID: " ", ClientSecret: " ", Scopes: []string{" "}, }, }) ctx := context.Background() // Get or Createa product type productTypeDraft := commercetools.ProductTypeDraft{ Name: "a-product-type", Key: "a-product-type", } productType, err := client.ProductTypeGetWithKey(ctx, productTypeDraft.Key) if productType == nil { productType, err = client.ProductTypeCreate(ctx, &productTypeDraft) if err != nil { log.Println(err) } } r := rand.New(rand.NewSource(time.Now().UnixNano())) randomID := r.Int() productDraft := &commercetools.ProductDraft{ Key: fmt.Sprintf("test-product-%d", randomID), Name: &commercetools.LocalizedString{ "nl": "Een test product", "en": "A test product", }, ProductType: &commercetools.ProductTypeResourceIdentifier{ ID: productType.ID, }, Slug: &commercetools.LocalizedString{ "nl": fmt.Sprintf("een-test-product-%d", randomID), "en": fmt.Sprintf("a-test-product-%d", randomID), }, } // The last argument is optional for reference expansion product, err := client.ProductCreate( ctx, productDraft, commercetools.WithReferenceExpansion("taxCategory")) if err != nil { log.Fatal(err) } log.Print(product) }">
package main

import (
    "context"
    "fmt"
    "log"
    "math/rand"
    "time"
    
    "github.com/labd/commercetools-go-sdk/commercetools"
)

func main() {

    // Create the new client. When an empty value is passed it will use the CTP_*
    // environment variables to get the value. The HTTPClient arg is optional,
    // and when empty will automatically be created using the env values.
    client, err := commercetools.NewClient(&commercetools.ClientConfig{
        ProjectKey: "
      
       "
      ,
        Endpoints:  commercetools.NewClientEndpoints("europe-west1", "gcp"),
        Credentials: &commercetools.ClientCredentials{
            ClientID:     "
      
       "
      ,
            ClientSecret: "
      
       "
      ,
            Scopes:       []string{"
      
       "
      },
        },
    })
    
    ctx := context.Background()

    // Get or Createa product type
    productTypeDraft := commercetools.ProductTypeDraft{
        Name: "a-product-type",
        Key:  "a-product-type",
    }

    productType, err := client.ProductTypeGetWithKey(ctx, productTypeDraft.Key)
    if productType == nil {
        productType, err = client.ProductTypeCreate(ctx, &productTypeDraft)
        if err != nil {
            log.Println(err)
        }
    }

    r := rand.New(rand.NewSource(time.Now().UnixNano()))
    randomID := r.Int()
    productDraft := &commercetools.ProductDraft{
        Key: fmt.Sprintf("test-product-%d", randomID),
        Name: &commercetools.LocalizedString{
            "nl": "Een test product",
            "en": "A test product",
        },
        ProductType: &commercetools.ProductTypeResourceIdentifier{
            ID: productType.ID,
        },
        Slug: &commercetools.LocalizedString{
            "nl": fmt.Sprintf("een-test-product-%d", randomID),
            "en": fmt.Sprintf("a-test-product-%d", randomID),
        },
    }

    // The last argument is optional for reference expansion
    product, err := client.ProductCreate(
        ctx, productDraft, commercetools.WithReferenceExpansion("taxCategory"))
    if err != nil {
        log.Fatal(err)
    }
    
    log.Print(product)
}

Generating code

To generate code do the following steps:

  • pip install pyyaml
  • install yq (f.e. brew install yq on macOS)
  • git clone https://github.com/commercetools/commercetools-api-reference.git in the folder on the same level as the commercetools-go-sdk folder
  • make generate

TODO for code generating the services:

  • CustomObject service implementation
  • Implement all traits (f.e. priceSelecting)
Similar Resources

Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Jul 2, 2021

Wechat Pay SDK(V3) Write by Go.

WechatPay GO(v3) Introduction Wechat Pay SDK(V3) Write by Go. API V3 of Office document is here. Features Signature/Verify messages Encrypt/Decrypt ce

May 23, 2022

Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go

Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go

go-wechaty Connecting Chatbots Wechaty is a RPA SDK for Wechat Individual Account that can help you create a chatbot in 6 lines of Go. Voice of the De

Dec 30, 2022

An easy-to-use unofficial SDK for Feishu and Lark Open Platform

go-lark go-lark is an easy-to-use unofficial SDK for Feishu and Lark Open Platform. go-lark implements messaging APIs, with full-fledged supports on b

Jan 2, 2023

A go SDK for the data available via data.gov.gr

go-data-gov-gr-sdk A Go based SDK to access the public data provided by the Greek Government and are available at https://www.data.gov.gr/ Quick Start

Jan 24, 2022

weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk

weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk

wechat SDK for golang https://github.com/chanxuehong/wechat 招人啦 golang 后端的坑, 趣头条集团下面的创新团队, 现在步入正常轨道了, 前景很好. 要求: golang中高级 自驱、有责任心 沟通没有问题 待遇: open, 看能力

Dec 30, 2022

SDK for Yigim Payment Gateway

Yigim gateway SDK The package provides ability to access the Yigim payment's api via the Go language. Usage To install run: go get github.com/paladium

Oct 5, 2021

DipDup Golang SDK

General instruments for DipDup in golang

Dec 14, 2022

Unofficial SDK of official notion API in Go

notion-go A go client for the Notion API Description This aims to be an unofficial Go version of the official SDK which is written in JavaScript. Inst

May 12, 2022
anatha-sdk fork from anatha tech.
anatha-sdk fork from anatha tech.

anatha just anatha-sdk fork from anathatech. Cosmos SDK The Cosmos-SDK is a framework for building blockchain applications in Golang. It is being used

Nov 25, 2021
A go sdk for baidu netdisk open platform 百度网盘开放平台 Go SDK

Pan Go Sdk 该代码库为百度网盘开放平台Go语言的SDK

Nov 22, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

Dec 7, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

Jan 7, 2022
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

Dec 13, 2022
AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Dec 31, 2022
A Facebook Graph API SDK For Go.

A Facebook Graph API SDK In Golang This is a Go package that fully supports the Facebook Graph API with file upload, batch request and marketing API.

Dec 12, 2022
A Golang SDK for Medium's OAuth2 API

Medium SDK for Go This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app. Install go get github.com/Medium/

Nov 28, 2022
MinIO Client SDK for Go

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object stor

Dec 29, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022