Skip to content

feat: added support for branches #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

robertolosanno-e2x
Copy link
Contributor

Fixes #

NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS

@robertolosanno-e2x robertolosanno-e2x requested a review from a team as a code owner March 13, 2025 18:07
@robertolosanno-e2x
Copy link
Contributor Author

Hi @demeyerthom,
I tested the change with the following code, just need to update the variable branch := "main" with a different branch

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/labd/contentstack-go-sdk/management"
)

func main() {
	apiKey := os.Getenv("CONTENTSTACK_API_KEY")
	if apiKey == "" {
		log.Fatal("CONTENTSTACK_API_KEY environment variable is required")
	}

	managementToken := os.Getenv("CONTENTSTACK_MANAGEMENT_TOKEN")
	if managementToken == "" {
		log.Fatal("CONTENTSTACK_MANAGEMENT_TOKEN environment variable is required")
	}

	cfg := management.ClientConfig{
		BaseURL: "https://api.contentstack.io", // or your region specific URL
	}

	client, err := management.NewClient(cfg)
	if err != nil {
		log.Fatalf("Error creating client: %v", err)
	}

	branch := "main"
	stackAuth := management.StackAuth{
		ApiKey:          apiKey,
		ManagementToken: managementToken,
		Branch:          branch, // specify your branch here
	}

	instance, err := client.Stack(&stackAuth)
	if err != nil {
		log.Fatalf("Error creating stack instance: %v", err)
	}

	contentTypes, err := instance.ContentTypeFetchAll(context.Background())
	if err != nil {
		log.Fatalf("Error fetching content types: %v", err)
	}

	fmt.Printf("Found %d content types in branch '%s':\n", len(contentTypes), branch)
	for _, ct := range contentTypes {
		fmt.Printf("- %s (UID: %s)\n", ct.Title, ct.UID)
	}
}

@demeyerthom demeyerthom merged commit fe44329 into labd:main Mar 14, 2025
1 of 2 checks passed
@robertolosanno-e2x robertolosanno-e2x deleted the feat/branches_support branch March 14, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants