planetscale-go icon indicating copy to clipboard operation
planetscale-go copied to clipboard

service-token to create branch

Open cemo opened this issue 3 years ago • 3 comments

I have created a service token to create a new branch but I am getting "not found" when I use it. Same code is working with access token.

cemo avatar Feb 09 '22 07:02 cemo

Hi @cemo

Could you provide step-by-step instructions on what exactly you did (such as which commands you used to create the token) and the command you use, where you get the not found error?

fatih avatar Feb 09 '22 12:02 fatih

Hi @fatih,

package main

import (
	"context"
	"fmt"
	"github.com/planetscale/planetscale-go/planetscale"
)

func main() {

	ctx := context.Background()

	// create a new PlanetScale API client with the given access token
	client, _ := planetscale.NewClient(
		planetscale.WithServiceToken("tok", "***"),
	)

	//client, _ := planetscale.NewClient(
	//	planetscale.WithAccessToken("***"),
	//)

	// list all databases for the given organization
	databases, _ := client.Databases.List(ctx, &planetscale.ListDatabasesRequest{
		Organization: "startupheroes",
	})

	fmt.Printf("Found %d databases\n", len(databases))
	for _, db := range databases {
		fmt.Printf("Name: %q\n", db.Name)
		fmt.Printf("Notes: %q\n", db.Notes)
	}
}

Here is a sample. service-token based client can not return databases.

cemo avatar Feb 09 '22 14:02 cemo

I created my service token via UI but auth token by CLI. I added all permissions to my token at UI by the way.

I am not sure but It seems service-token approach is totally broken.

cemo avatar Feb 09 '22 14:02 cemo