{"id":18930044,"url":"https://github.com/labd/commercetools-go-sdk","last_synced_at":"2025-05-16T13:02:04.305Z","repository":{"id":45334299,"uuid":"137788197","full_name":"labd/commercetools-go-sdk","owner":"labd","description":"Go SDK for commercetools","archived":false,"fork":false,"pushed_at":"2025-03-07T14:56:32.000Z","size":3042,"stargazers_count":27,"open_issues_count":3,"forks_count":21,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-12T08:30:42.671Z","etag":null,"topics":["commercetools","go-sdk"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/labd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["labd"]}},"created_at":"2018-06-18T18:03:30.000Z","updated_at":"2025-03-07T15:29:38.000Z","dependencies_parsed_at":"2023-11-14T16:43:02.215Z","dependency_job_id":"b4b497af-8e13-4c99-96e9-c743328969f1","html_url":"https://github.com/labd/commercetools-go-sdk","commit_stats":{"total_commits":276,"total_committers":20,"mean_commits":13.8,"dds":0.7101449275362319,"last_synced_commit":"cea49612c3b7fc74e47c8310f35c1e9db28d56e4"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labd%2Fcommercetools-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labd","download_url":"https://codeload.github.com/labd/commercetools-go-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535787,"owners_count":22087394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commercetools","go-sdk"],"created_at":"2024-11-08T11:36:20.807Z","updated_at":"2025-05-16T13:02:04.279Z","avatar_url":"https://github.com/labd.png","language":"Go","funding_links":["https://github.com/sponsors/labd"],"categories":[],"sub_categories":[],"readme":"# commercetools-go-sdk\n\n[![Build Status](https://github.com/labd/commercetools-go-sdk/workflows/Go%20Tests/badge.svg)](https://github.com/labd/commercetools-go-sdk/workflows/)\n[![codecov](https://codecov.io/gh/LabD/commercetools-go-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/LabD/commercetools-go-sdk)\n[![Go Report Card](https://goreportcard.com/badge/github.com/labd/commercetools-go-sdk)](https://goreportcard.com/report/github.com/labd/commercetools-go-sdk)\n[![GoDoc](https://godoc.org/github.com/labd/commercetools-go-sdk?status.svg)](https://godoc.org/github.com/labd/commercetools-go-sdk)\n\nThe Commercetools Go SDK is automatically generated based on the official [API specifications](https://github.com/commercetools/commercetools-api-reference)\nof Commercetools. It should therefore be nearly feature complete.\n\nThe SDK was initially created for enabling the creation of the\n[Terraform Provider for Commercetools](https://github.com/labd/terraform-provider-commercetools)\nThat provider enables you to use infrastructure-as-code principles with Commercetools.\n\nNote that since this SDK is automatically generated we cannot guarantee backwards\ncompatibility between releases. Please pin the dependency correctly and be aware\nof potential changes when updating\n\n## Using the SDK\n\n\n```go\npackage main\n\nimport (\n   \"context\"\n   \"errors\"\n   \"fmt\"\n   \"github.com/labd/commercetools-go-sdk/ctutils\"\n   \"log\"\n   \"math/rand\"\n   \"time\"\n\n   \"github.com/davecgh/go-spew/spew\"\n   \"github.com/labd/commercetools-go-sdk/platform\"\n   \"golang.org/x/oauth2/clientcredentials\"\n)\n\nfunc main() {\n\n   // Create the new client. When an empty value is passed it will use the CTP_*\n   // environment variables to get the value. The HTTPClient arg is optional,\n   // and when empty will automatically be created using the env values.\n   client, err := platform.NewClient(\u0026platform.ClientConfig{\n      URL: \"https://api.europe-west1.gcp.commercetools.com\",\n      Credentials: \u0026clientcredentials.Config{\n         TokenURL:     \"https://auth.europe-west1.gcp.commercetools.com/oauth/token\",\n         ClientID:     \"\u003cclient-id\u003e\",\n         ClientSecret: \"\u003cclient-secret\u003e\",\n         Scopes:       []string{\"manage_project:\u003cproject-key\u003e\"},\n      },\n   })\n\n   projectClient := client.WithProjectKey(\"\u003cproject-key\u003e\")\n\n   ctx := context.Background()\n\n   // Get or Createa product type\n   productTypeDraft := platform.ProductTypeDraft{\n      Name: \"a-product-type\",\n      Key:  ctutils.StringRef(\"a-product-type\"),\n   }\n\n   productType, err := projectClient.\n      ProductTypes().\n      WithKey(*productTypeDraft.Key).\n      Get().\n      Execute(ctx)\n\n   if err != nil {\n      if errors.As(err, \u0026platform.ErrNotFound) {\n         productType, err = projectClient.\n            ProductTypes().\n            Post(productTypeDraft).\n            Execute(ctx)\n      }\n\n      if err != nil {\n         log.Fatal(err)\n      }\n   }\n\n   r := rand.New(rand.NewSource(time.Now().UnixNano()))\n   randomID := r.Int()\n   productDraft := platform.ProductDraft{\n      Key: ctutils.StringRef(fmt.Sprintf(\"test-product-%d\", randomID)),\n      Name: platform.LocalizedString{\n         \"nl\": \"Een test product\",\n         \"en\": \"A test product\",\n      },\n      ProductType: platform.ProductTypeResourceIdentifier{\n         ID: ctutils.StringRef(productType.ID),\n      },\n      Slug: platform.LocalizedString{\n         \"nl\": fmt.Sprintf(\"een-test-product-%d\", randomID),\n         \"en\": fmt.Sprintf(\"a-test-product-%d\", randomID),\n      },\n   }\n\n   // The last argument is optional for reference expansion\n   product, err := projectClient.\n      Products().\n      Post(productDraft).\n           WithQueryParams(\n              platform.ByProjectKeyProductsRequestMethodPostInput{\n                 Expand: []string{\"foobar\"},\n              },\n           ).\n      Execute(ctx)\n\n   // Alternatively you can pass query params via methods\n   //product, err := projectClient.\n   //\tProducts().\n   //\tPost(productDraft).\n   //\tExpand([]string{\"foobar\"}).\n   //\tExecute(ctx)\n\n   if err != nil {\n      log.Fatal(err)\n   }\n\n   spew.Dump(product)\n}\n\n```\n\n## Generating code\n\nTo re-generate the API based on new RAML files take the following steps:\n - Install rmf-codegen (see https://github.com/commercetools/rmf-codegen)\n - Clone the API specifications https://github.com/commercetools/commercetools-api-reference\n   in the parent directory\n - Run `make generate`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabd%2Fcommercetools-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabd%2Fcommercetools-go-sdk/lists"}