Skip to main content

Create a new project

Create a new project:
mkdir formance-go-demo
cd formance-go-demo
go mod init example/formance-go-demo

Install the Formance SDK

Install the Formance SDK:
go get github.com/formancehq/formance-sdk-go/v3
The Formance API relies on OAuth 2.0 for authentication.For more information, see OAuth 2.0.
The client_credentials grant type requires a client ID and client secret. These are sensitive credentials that should not be exposed to the public. If you’re integrating Formance into a web application, use an OAuth flow that does not require a client secret, such as the authorization code grant.

Hello World from the Formance Ledger

Replace the values with your API endpoint and credentials from the Authentication & Credentials Setup guide.
Create a new file called main.go with the following content:
package main

import(
	"context"
	"fmt"
	"log"
	
	"github.com/formancehq/formance-sdk-go/v3/pkg/models/operations"
	"github.com/formancehq/formance-sdk-go/v3/pkg/models/shared"
	formancesdkgo "github.com/formancehq/formance-sdk-go/v3"
)

func main() {
    s := formancesdkgo.New(
    	formancesdkgo.WithServerURL("https://<YOUR_SERVER_URL_HERE>"),
        formancesdkgo.WithSecurity(shared.Security{
            ClientID: formancesdkgo.String("<YOUR_CLIENT_ID_HERE>"),
            ClientSecret: formancesdkgo.String("<YOUR_CLIENT_SECRET_HERE>"),
        }),
    )

    ctx := context.Background()
    res, err := s.Ledger.V2.ListLedgers(ctx, operations.V2ListLedgersRequest{
        PageSize: formancesdkgo.Int64(100),
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("response:", res.StatusCode)
}

Run the project

Run the project:
go run main.go
Output:
2.1.0