### SDK Installation Source: https://github.com/formancehq/ledger/blob/main/pkg/client/README.md Install the Formance Ledger Go SDK using the go get command. ```APIDOC ## SDK Installation To add the SDK as a dependency to your project: ```bash go get github.com/formancehq/ledger/pkg/client ``` ``` -------------------------------- ### Install Go SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/README.md Add the Formance Ledger Go SDK as a dependency to your project using the go get command. ```bash go get github.com/formancehq/ledger/pkg/client ``` -------------------------------- ### SDK Example Usage Source: https://github.com/formancehq/ledger/blob/main/pkg/client/README.md Example of how to initialize the SDK and make a call to the GetInfo endpoint. ```APIDOC ## SDK Example Usage ### Example ```go package main import ( "context" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/components" "log" "os" ) func main() { ctx := context.Background() ss := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := ss.Ledger.GetInfo(ctx) if err != nil { log.Fatal(err) } if res.V2ConfigInfoResponse != nil { // handle response } } ``` ``` -------------------------------- ### Create Ledger on Specific Bucket (v2 API) Source: https://github.com/formancehq/ledger/blob/main/CONTRIBUTING.md Example of creating a ledger and specifying the bucket it should be installed on using the v2 API. ```shell $ curl -X POST http://localhost:3068/v2/testing -d '{"bucket": "bucket0"}' ``` -------------------------------- ### Get Ledger Information (Go) Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v1/README.md This example shows how to fetch specific information about a ledger by its name. It requires authentication via environment variables and specifies the target ledger name in the request. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V1.GetLedgerInfo(ctx, operations.GetLedgerInfoRequest{ Ledger: "ledger001", }) if err != nil { log.Fatal(err) } if res.LedgerInfoResponse != nil { // handle response } } ``` -------------------------------- ### V2MigrationInfo Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example structure for V2 Migration Info, showing migration version, name, date, and state. ```json { "version": 11, "name": "migrations:001", "date": "2019-08-24T14:15:22Z", "state": "TO DO" } ``` -------------------------------- ### Example Response for Server Information Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful 200 OK response when retrieving server information. ```json { "server": "string", "version": "string", "experimentalFeatures": [ "string" ] } ``` -------------------------------- ### V2LedgerInfo Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example structure for V2 Ledger Info, detailing the ledger's name and storage configuration, including migration history. ```json { "name": "ledger001", "storage": { "migrations": [ { "version": 11, "name": "migrations:001", "date": "2019-08-24T14:15:22Z", "state": "TO DO" } ] } } ``` -------------------------------- ### V2QueryTemplates Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md An example demonstrating the structure of V2QueryTemplates, which can contain multiple query template definitions. ```json { "property1": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} }, "property2": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} } } ``` -------------------------------- ### V2QueryTemplate Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md An example of a V2QueryTemplate showing how to define a query with parameters, variables, and a body. ```json { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} } ``` -------------------------------- ### StartPipeline Source: https://github.com/formancehq/ledger/blob/main/pkg/client/README.md Starts a pipeline. ```APIDOC ## StartPipeline ### Description Start pipeline. ### Method POST ### Endpoint /api/v2/pipelines/{pipeline_id}/start ``` -------------------------------- ### 200 OK Response Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example of a successful response when retrieving schemas. It includes pagination details and schema definitions. ```json { "cursor": { "data": [ { "version": "v1.0.0", "createdAt": "2023-01-01T00:00:00Z", "chart": { "users": { "$userID": { ".pattern": "^[0-9]{16}$" } } }, "transactions": { "property1": { "description": "string", "script": "string", "runtime": "experimental-interpreter" }, "property2": { "description": "string", "script": "string", "runtime": "experimental-interpreter" } }, "queries": { "property1": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} }, "property2": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} } } } ], "hasMore": true, "previous": "YXVsdCBhbmQgYSBtYXhpbXVtIG1heF9yZXN1bHRzLol=", "next": "aW0gdmVuaWFtLCBxdWlzIG5vc3RydWQ=", "pageSize": 0 } } ``` -------------------------------- ### Start Local Formance Ledger Source: https://github.com/formancehq/ledger/blob/main/README.md Use this command to start a local, all-in-one docker image of the Formance Ledger, including a Postgres DB, Gateway Server, Ledger server, Ledger worker, and Console UI. ```bash docker compose -f examples/standalone/docker-compose.yml up ``` -------------------------------- ### List Accounts Response Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example of a successful response when listing accounts, including pagination details and account data. ```json { "resource": "accounts", "cursor": { "pageSize": 15, "hasMore": false, "previous": "YXVsdCBhbmQgYSBtYXhpbXVtIG1heF9yZXN1bHRzLol=", "next": "aW0gdmVuaWFtLCBxdWlzIG5vc3RydWQ=", "data": [ { "address": "users:001", "metadata": { "admin": "true" }, "insertionDate": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:00:00Z", "firstUsage": "2023-01-01T00:00:00Z", "volumes": { "USD": { "input": 100, "output": 10, "balance": 90 }, "EUR": { "input": 100, "output": 10, "balance": 90 } }, "effectiveVolumes": { "USD": { "input": 100, "output": 10, "balance": 90 }, "EUR": { "input": 100, "output": 10, "balance": 90 } } } ] } } ``` -------------------------------- ### Example Response for In-Memory Metrics Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful 200 OK response when retrieving in-memory metrics. ```json { "property1": null, "property2": null } ``` -------------------------------- ### V2Bulk Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example of a V2 Bulk request, demonstrating a single bulk element with action, identifier, and data including postings, script, and metadata. ```json [ { "action": "string", "ik": "string", "data": { "timestamp": "2019-08-24T14:15:22Z", "postings": [ { "amount": 100, "asset": "COIN", "destination": "users:002", "source": "users:001" } ], "script": { "template": "CUSTOMER_DEPOSIT", "plain": "vars { account $user } send [COIN 10] ( source = @world destination = $user ) ", "vars": { "user": "users:042" } }, "runtime": "experimental-interpreter", "reference": "ref:001", "metadata": { "admin": "true" }, "accountMetadata": { "property1": { "admin": "true" }, "property2": { "admin": "true" } }, "force": true } } ] ``` -------------------------------- ### V2BaseBulkElement Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example structure for a V2 Base Bulk Element, defining the essential action and identifier fields for a bulk operation. ```json { "action": "string", "ik": "string" } ``` -------------------------------- ### Account TargetType Example Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/targettype.md Demonstrates how to use the TargetTypeAccount constant to specify an account as the target type. ```go import ( "github.com/formancehq/ledger/pkg/client/models/components" ) value := components.TargetTypeAccount ``` -------------------------------- ### Example 200 OK Response for List Logs Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful response when listing logs. It includes cursor information for pagination and a list of log entries, each with its ID, type, data, hash, date, and schema version. ```json { "resource": "logs", "cursor": { "pageSize": 15, "hasMore": false, "previous": "YXVsdCBhbmQgYSBtYXhpbXVtIG1heF9yZXN1bHRzLol=", "next": "aW0gdmVuaWFtLCBxdWlzIG5vc3RydWQ=", "data": [ { "id": 1234, "type": "NEW_TRANSACTION", "data": { "transaction": { "id": 1234, "postings": [ { "source": "world", "destination": "users:001", "amount": 100, "asset": "USD/2" } ], "metadata": {}, "timestamp": "2024-01-15T10:30:00Z", "insertedAt": "2024-01-15T10:30:00Z", "reverted": false }, "accountMetadata": { "users:001": { "created_by": "system" } } }, "hash": "9ee060170400f556b7e1575cb13f9db004f150a08355c7431c62bc639166431e", "date": "2019-08-24T14:15:22Z", "schemaVersion": "v1.0.0" } ] } } ``` -------------------------------- ### Start Ledger with Docker Compose Source: https://github.com/formancehq/ledger/blob/main/CONTRIBUTING.md Use this command to bring up the ledger service and its dependencies using Docker Compose. ```shell $ docker compose up -d ``` -------------------------------- ### StartPipeline Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v2/README.md Starts a paused pipeline. ```APIDOC ## StartPipeline ### Description Starts a paused pipeline. ### Method POST ### Endpoint /api/v2/ledgers/{ledgerId}/pipelines/{pipelineId}/start ``` -------------------------------- ### List Ledgers 200 Response Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful response (200 OK) when listing ledgers. It includes pagination details and a list of ledger objects. ```json { "cursor": { "pageSize": 15, "hasMore": false, "previous": "YXVsdCBhbmQgYSBtYXhpbXVtIG1heF9yZXN1bHRzLol=", "next": "aW0gdmVuaWFtLCBxdWlzIG5vc3RydWQ=", "data": [ { "name": "string", "addedAt": "2019-08-24T14:15:22Z", "bucket": "string", "deletedAt": "2019-08-24T14:15:22Z", "metadata": { "admin": "true" }, "features": { "property1": "string", "property2": "string" }, "id": 0 } ] } } ``` -------------------------------- ### List Transactions 200 Response Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful response (200 OK) when listing transactions. It includes cursor information and a list of transactions. ```json { "resource": "transactions", "cursor": { "pageSize": 15, "hasMore": false, "previous": "YXVsdCBhbmQgYSBtYXhpbXVtIG1heF9yZXN1bHRzLol=", "next": "aW0gdmVuaWFtLCBxdWlzIG5vc3RydWQ=", "data": [ { "insertedAt": "2019-08-24T14:15:22Z", "updatedAt": "2019-08-24T14:15:22Z", "timestamp": "2019-08-24T14:15:22Z", "postings": [ { "amount": 100, "asset": "COIN", "destination": "users:002", "source": "users:001" } ], "reference": "ref:001", "metadata": { "admin": "true" }, "id": 0, "reverted": true, "revertedAt": "2019-08-24T14:15:22Z", "preCommitVolumes": { "orders:1": { "USD": { "input": 100, "output": 10, "balance": 90 } }, "orders:2": { "USD": { "input": 100, "output": 10, "balance": 90 } } }, "postCommitVolumes": { "orders:1": { "USD": { "input": 100, "output": 10, "balance": 90 } }, "orders:2": { "USD": { "input": 100, "output": 10, "balance": 90 } } }, "preCommitEffectiveVolumes": { "orders:1": { "USD": { "input": 100, "output": 10, "balance": 90 } }, "orders:2": { "USD": { "input": 100, "output": 10, "balance": 90 } } }, "postCommitEffectiveVolumes": { "orders:1": { "USD": { "input": 100, "output": 10, "balance": 90 } }, "orders:2": { "USD": { "input": 100, "output": 10, "balance": 90 } } }, "template": "string" } ] } } ``` -------------------------------- ### Create V2BulkElementResultAddMetadata Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/v2bulkelementresult.md Example of creating a V2BulkElementResult for adding metadata. ```APIDOC ## CreateV2BulkElementResultAddMetadata ### Description Creates a V2BulkElementResult object representing a successful metadata addition. ### Method Signature `components.CreateV2BulkElementResultAddMetadata(components.V2BulkElementResultAddMetadata{/* values here */})` ### Request Example ```go v2BulkElementResult := components.CreateV2BulkElementResultAddMetadata(components.V2BulkElementResultAddMetadata{ // Populate with metadata details }) ``` ``` -------------------------------- ### Example 200 Response for Get Statistics Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example JSON response for a successful retrieval of ledger statistics, showing account and transaction counts. ```json { "data": { "accounts": 0, "transactions": 0 } } ``` -------------------------------- ### Go Example: Using V2RunQueryQueryParamOrderEffective Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/operations/v2runqueryqueryparamorder.md Demonstrates how to import and use the V2RunQueryQueryParamOrderEffective value in Go. This parameter is deprecated. ```go import ( "github.com/formancehq/ledger/pkg/client/models/operations" ) value := operations.V2RunQueryQueryParamOrderEffective ``` -------------------------------- ### List Logs with Options (Go) Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v1/README.md Demonstrates how to list logs from a ledger using the Go SDK. Includes setting authentication, pagination, and cursor options. Ensure your `FORMANCE_CLIENT_ID` and `FORMANCE_CLIENT_SECRET` environment variables are set. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V1.ListLogs(ctx, operations.ListLogsRequest{ Ledger: "ledger001", PageSize: client.Pointer[int64](100), After: client.Pointer("1234"), Cursor: client.Pointer("aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ=="), }) if err != nil { log.Fatal(err) } if res.LogsCursorResponse != nil { // handle response } } ``` -------------------------------- ### Initialize SDK with Security Details Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/operations/option.md Use WithSecurity to configure the SDK with provided security details during initialization. This option applies to all subsequent operations. ```go client.WithSecurity(/* ... */) ``` -------------------------------- ### Get a Ledger Response (200 OK) Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example of a successful response when retrieving a ledger. The response contains detailed information about the ledger. ```json { "data": { "name": "string", "addedAt": "2019-08-24T14:15:22Z", "bucket": "string", "deletedAt": "2019-08-24T14:15:22Z", "metadata": { "admin": "true" }, "features": { "property1": "string", "property2": "string" }, "id": 0 } } ``` -------------------------------- ### Initialize and Use Ledger Client Source: https://github.com/formancehq/ledger/blob/main/pkg/client/README.md Demonstrates how to initialize the Go SDK client with authentication and make a call to retrieve server information. Ensure the FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables are set. ```go package main import ( "context" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/components" "log" "os" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.GetInfo(ctx) if err != nil { log.Fatal(err) } if res.V2ConfigInfoResponse != nil { // handle response } } ``` -------------------------------- ### List Ledgers Request Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This snippet shows an example HTTP GET request to list ledgers. It includes common headers and the base endpoint. ```http GET http://localhost:8080/v2 HTTP/1.1 Host: localhost:8080 Content-Type: application/json Accept: application/json ``` -------------------------------- ### Example Usage of V2QueryParams4ResourceVolumes Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/v2queryparams4resource.md Demonstrates how to use the V2QueryParams4ResourceVolumes constant in Go. This is typically used when constructing API requests to filter resources by their volumes. ```go import ( "github.com/formancehq/ledger/pkg/client/models/components" ) value := components.V2QueryParams4ResourceVolumes ``` -------------------------------- ### Initialize SDK with Server URL Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/operations/option.md Use WithServerURL to provide an alternative server URL when initializing the SDK client. This option applies to all subsequent operations. ```go client.WithServerURL("https://api.example.com") ``` -------------------------------- ### Get Schema by Version Response (200 OK) Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example of a successful response when retrieving a ledger schema. It includes schema details like version, creation date, chart, transactions, and queries. ```json { "data": { "version": "v1.0.0", "createdAt": "2023-01-01T00:00:00Z", "chart": { "users": { "$userID": { ".pattern": "^[0-9]{16}$" } } }, "transactions": { "property1": { "description": "string", "script": "string", "runtime": "experimental-interpreter" }, "property2": { "description": "string", "script": "string", "runtime": "experimental-interpreter" } }, "queries": { "property1": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} }, "property2": { "description": "string", "resource": "transactions", "params": { "pageSize": 100, "cursor": "aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ==", "expand": "string", "pit": "2019-08-24T14:15:22Z", "sort": "id:desc", "resource": "accounts" }, "vars": { "property1": { "type": "string", "default": null }, "property2": { "type": "string", "default": null } }, "body": {} } } } } ``` -------------------------------- ### Create First Transaction (v1 API) Source: https://github.com/formancehq/ledger/blob/main/CONTRIBUTING.md Example of creating a transaction using the v1 API. Note that this automatically creates a ledger if it doesn't exist. ```shell $ curl -X POST http://localhost:3068/quickstart/transactions -d '{"postings": [{"source": "world", "destination": "bank", "amount": 100, "asset": "USD"}]}' | jq ``` -------------------------------- ### Get Pipeline State Success Response Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md This is an example of a successful response (200 OK) when retrieving pipeline information. It includes the pipeline's ID, creation timestamp, last log ID, and enabled status. ```json { "data": { "id": "string", "createdAt": "2019-08-24T14:15:22Z", "lastLogID": 0, "enabled": true } } ``` -------------------------------- ### List Accounts with Options Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v1/README.md Demonstrates how to list accounts from a ledger using the v1 SDK. Includes optional parameters for pagination, filtering by address, metadata, balance, and cursor. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V1.ListAccounts(ctx, operations.ListAccountsRequest{ Ledger: "ledger001", PageSize: client.Pointer[int64](100), After: client.Pointer("users:003"), Address: client.Pointer("users:.+"), Metadata: map[string]any{ "0": "m", "1": "e", "2": "t", "3": "a", "4": "d", "5": "a", "6": "t", "7": "a", "8": "[", "9": "k", "10": "e", "11": "y", "12": "]", "13": "=", "14": "v", "15": "a", "16": "l", "17": "u", "18": "e", "19": "1", "20": "&", "21": "m", "22": "e", "23": "t", "24": "a", "25": "d", "26": "a", "27": "t", "28": "a", "29": "[", "30": "a", "31": ".", "32": "n", "33": "e", "34": "s", "35": "t", "36": "e", "37": "d", "38": ".", "39": "k", "40": "e", "41": "y", "42": "]", "43": "=", "44": "v", "45": "a", "46": "l", "47": "u", "48": "e", "49": "2", }, Balance: client.Pointer[int64](2400), Cursor: client.Pointer("aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ=="), }) if err != nil { log.Fatal(err) } if res.AccountsCursorResponse != nil { // handle response } } ``` -------------------------------- ### Ledger Configuration JSON Response Source: https://github.com/formancehq/ledger/blob/main/CONTRIBUTING.md Example JSON output when retrieving ledger configuration. It shows the enabled features and other ledger metadata. ```json { "data": { "bucket": "_default", "metadata": {}, "features": { "ACCOUNT_METADATA_HISTORY": "SYNC", "HASH_LOGS": "DISABLED", "MOVES_HISTORY": "ON", "MOVES_HISTORY_POST_COMMIT_EFFECTIVE_VOLUMES": "SYNC", "TRANSACTION_METADATA_HISTORY": "SYNC" }, "id": 3, "name": "testing2", "addedAt": "2024-10-03T08:40:40.545229Z" } } ``` -------------------------------- ### Get Ledger Info with Go Client Source: https://github.com/formancehq/ledger/blob/main/pkg/client/USAGE.md Demonstrates how to initialize the client and retrieve ledger information. Ensure your FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables are set. ```go package main import ( "context" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/components" "log" "os" ) func main() { ctx := context.Background() ss := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := ss.Ledger.GetInfo(ctx) if err != nil { log.Fatal(err) } if res.V2ConfigInfoResponse != nil { // handle response } } ``` -------------------------------- ### Start Pipeline Request Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Use this endpoint to initiate the execution of a specified pipeline. Ensure the ledger and pipelineID are correctly provided in the path. ```http POST http://localhost:8080/v2/{ledger}/pipelines/{pipelineID}/start HTTP/1.1 Host: localhost:8080 Accept: application/json ``` -------------------------------- ### Get Server Information with Go SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/ledger/README.md Demonstrates how to fetch server information using the Ledger SDK. Ensure you have set the FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables for authentication. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.GetInfo(ctx) if err != nil { log.Fatal(err) } if res.V2ConfigInfoResponse != nil { // handle response } } ``` -------------------------------- ### Make Source: https://github.com/formancehq/ledger/blob/main/internal/controller/ledger/README.md Creates a new machine instance from a script. ```APIDOC ## Make ### Description Creates a new machine instance from a script. ### Method POST (assumed, based on naming convention) ### Endpoint /machine-factory/make (assumed) ### Parameters #### Request Body - **script** (string) - Required - The script to compile into a machine. ### Response #### Success Response (200) - **machine** (Machine) - The created machine instance. #### Error Response - **error** (string) - Description of the error. ``` -------------------------------- ### V2Stats Schema Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example JSON object for V2Stats, showing the total number of accounts and transactions. ```json { "accounts": 0, "transactions": 0 } ``` -------------------------------- ### Start Pipeline with v2 SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v2/README.md Initiates a pipeline using the Formance Ledger v2 SDK. Ensure you have set the FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables for authentication. Replace "" with the actual pipeline ID. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V2.StartPipeline(ctx, operations.V2StartPipelineRequest{ Ledger: "ledger001", PipelineID: "", }) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` -------------------------------- ### Create a New Transaction Instance Source: https://github.com/formancehq/ledger/blob/main/internal/README.md Initializes and returns a new, empty Transaction struct. Use this as a starting point before populating transaction details. ```go func NewTransaction() Transaction ``` -------------------------------- ### StateRegistry SetUpToDate Method Source: https://github.com/formancehq/ledger/blob/main/internal/controller/ledger/README.md Marks a ledger's state as up-to-date. Use after successfully updating the ledger state. ```go func (r *StateRegistry) SetUpToDate(name string) ``` -------------------------------- ### Initialize SDK with Templated Server URL Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/operations/option.md Use WithTemplatedServerURL to provide an alternative server URL with templated parameters during SDK client initialization. This option applies to all subsequent operations. ```go client.WithTemplatedServerURL("https://{host}:{port}", map[string]string{ "host": "api.example.com", "port": "8080", }) ``` -------------------------------- ### Transaction Script Variables Example Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/posttransactionscript.md Provides an example of using variables within a transaction script. This is useful for parameterizing scripts. ```json { "user": "users:042" } ``` -------------------------------- ### Run Script with Go SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v1/README.md Use this snippet to execute a script on a ledger. Ensure you have set up the client with your authentication credentials. The script can include variables and a reference for idempotency. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V1.RunScript(ctx, operations.RunScriptRequest{ Ledger: "ledger001", Preview: client.Pointer(true), Script: components.Script{ Plain: "vars {\naccount $user\n}\nsend [COIN 10] (\n\tsource = @world\n\tdestination = $user\n)\n", Vars: map[string]any{ "user": "users:042", }, Reference: client.Pointer("order_1234"), }, }) if err != nil { log.Fatal(err) } if res.ScriptResponse != nil { // handle response } } ``` -------------------------------- ### Get Exporter State (Go) Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v2/README.md Use this snippet to get the state of a specific exporter. Ensure you have set the FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V2.GetExporterState(ctx, operations.V2GetExporterStateRequest{ ExporterID: "", }) if err != nil { log.Fatal(err) } if res.V2GetExporterStateResponse != nil { // handle response } } ``` -------------------------------- ### Create Transactions with Go SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v1/README.md Demonstrates how to create a batch of transactions using the Go SDK. Ensure your environment variables `FORMANCE_CLIENT_ID` and `FORMANCE_CLIENT_SECRET` are set for authentication. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "math/big" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V1.CreateTransactions(ctx, operations.CreateTransactionsRequest{ Ledger: "ledger001", Transactions: components.Transactions{ Transactions: []components.TransactionData{ components.TransactionData{ Postings: []components.Posting{ components.Posting{ Amount: big.NewInt(100), Asset: "COIN", Destination: "users:002", Source: "users:001", }, }, Reference: client.Pointer("ref:001"), }, }, }, }) if err != nil { log.Fatal(err) } if res.TransactionsResponse != nil { // handle response } } ``` -------------------------------- ### V2Log Schema Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example JSON object representing a log entry in the ledger. It includes transaction details, metadata, hash, and schema version. ```json { "id": 1234, "type": "NEW_TRANSACTION", "data": { "transaction": { "id": 1234, "postings": [ { "source": "world", "destination": "users:001", "amount": 100, "asset": "USD/2" } ], "metadata": {}, "timestamp": "2024-01-15T10:30:00Z", "insertedAt": "2024-01-15T10:30:00Z", "reverted": false }, "accountMetadata": { "users:001": { "created_by": "system" } } }, "hash": "9ee060170400f556b7e1575cb13f9db004f150a08355c7431c62bc639166431e", "date": "2019-08-24T14:15:22Z", "schemaVersion": "v1.0.0" } ``` -------------------------------- ### V2PostTransaction Schema Example Source: https://github.com/formancehq/ledger/blob/main/docs/api/README.md Example JSON object representing a transaction to be posted to the ledger. Includes details like timestamp, postings, script, and metadata. ```json { "timestamp": "2019-08-24T14:15:22Z", "postings": [ { "amount": 100, "asset": "COIN", "destination": "users:002", "source": "users:001" } ], "script": { "template": "CUSTOMER_DEPOSIT", "plain": "vars {\naccount $user\n}\nsend [COIN 10] (\n\tsource = @world\n\tdestination = $user\n)\n", "vars": { "user": "users:042" } }, "runtime": "experimental-interpreter", "reference": "ref:001", "metadata": { "admin": "true" }, "accountMetadata": { "property1": { "admin": "true" }, "property2": { "admin": "true" } }, "force": true } ``` -------------------------------- ### List Schemas using Go SDK Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v2/README.md Demonstrates how to list all schemas for a given ledger using the Formance Go SDK. Ensure you have set the FORMANCE_CLIENT_ID and FORMANCE_CLIENT_SECRET environment variables. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V2.ListSchemas(ctx, operations.V2ListSchemasRequest{ Ledger: "ledger001", }) if err != nil { log.Fatal(err) } if res.V2SchemasCursorResponse != nil { // handle response } } ``` -------------------------------- ### Using V2MigrationInfoState in Go Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/v2migrationinfostate.md Demonstrates how to use the V2MigrationInfoState constants in Go. Import the necessary package and assign a state value. ```go import ( "github.com/formancehq/ledger/pkg/client/models/components" ) value := components.V2MigrationInfoStateToDo ``` -------------------------------- ### List Accounts with Go SDK v2 Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/sdks/v2/README.md This snippet shows how to list accounts from a ledger using the Formance Go SDK v2. It includes client initialization with authentication and a sample request with parameters like ledger name, page size, cursor, and sort order. ```go package main import( "context" "os" "github.com/formancehq/ledger/pkg/client/models/components" "github.com/formancehq/ledger/pkg/client" "github.com/formancehq/ledger/pkg/client/models/operations" "log" ) func main() { ctx := context.Background() s := client.New( client.WithSecurity(components.Security{ ClientID: client.Pointer(os.Getenv("FORMANCE_CLIENT_ID")), ClientSecret: client.Pointer(os.Getenv("FORMANCE_CLIENT_SECRET")), }), ) res, err := s.Ledger.V2.ListAccounts(ctx, operations.V2ListAccountsRequest{ Ledger: "ledger001", PageSize: client.Pointer[int64](100), Cursor: client.Pointer("aHR0cHM6Ly9nLnBhZ2UvTmVrby1SYW1lbj9zaGFyZQ=="), Sort: client.Pointer("id:desc"), RequestBody: map[string]any{ }, }) if err != nil { log.Fatal(err) } if res.V2AccountsCursorResponse != nil { // handle response } } ``` -------------------------------- ### Plain Transaction Script Example Source: https://github.com/formancehq/ledger/blob/main/pkg/client/docs/models/components/v2posttransactionscript.md Defines a simple transaction script using plain text. This example shows how to declare variables and perform a coin transfer. ```plaintext vars { account $user } send [COIN 10] ( source = @world destination = $user ) ```