Files

20 KiB

Webhooks

(Webhooks)

Available Operations

ActivateConfig

Activate a webhooks config by ID, to start receiving webhooks to its endpoint.

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.ActivateConfigRequest{
        ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.ActivateConfig(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.ConfigResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ActivateConfigRequest ✔️ The request object to use for the request.

Response

*operations.ActivateConfigResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

ChangeConfigSecret

Change the signing secret of the endpoint of a webhooks config.

If not passed or empty, a secret is automatically generated. The format is a random string of bytes of size 24, base64 encoded. (larger size after encoding)

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.ChangeConfigSecretRequest{
        ConfigChangeSecret: &shared.ConfigChangeSecret{
            Secret: "V0bivxRWveaoz08afqjU6Ko/jwO0Cb+3",
        },
        ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.ChangeConfigSecret(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.ConfigResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ChangeConfigSecretRequest ✔️ The request object to use for the request.

Response

*operations.ChangeConfigSecretResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

DeactivateConfig

Deactivate a webhooks config by ID, to stop receiving webhooks to its endpoint.

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.DeactivateConfigRequest{
        ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.DeactivateConfig(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.ConfigResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.DeactivateConfigRequest ✔️ The request object to use for the request.

Response

*operations.DeactivateConfigResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

DeleteConfig

Delete a webhooks config by ID.

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.DeleteConfigRequest{
        ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.DeleteConfig(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.DeleteConfigRequest ✔️ The request object to use for the request.

Response

*operations.DeleteConfigResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

GetManyConfigs

Sorted by updated date descending

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.GetManyConfigsRequest{
        Endpoint: v2.String("https://example.com"),
        ID: v2.String("4997257d-dfb6-445b-929c-cbe2ab182818"),
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.GetManyConfigs(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.ConfigsResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.GetManyConfigsRequest ✔️ The request object to use for the request.

Response

*operations.GetManyConfigsResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

InsertConfig

Insert a new webhooks config.

The endpoint should be a valid https URL and be unique.

The secret is the endpoint's verification secret. If not passed or empty, a secret is automatically generated. The format is a random string of bytes of size 24, base64 encoded. (larger size after encoding)

All eventTypes are converted to lower-case when inserted.

Example Usage

package main

import(
	"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
	"github.com/formancehq/formance-sdk-go/v2"
	"context"
	"log"
)

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := shared.ConfigUser{
        Endpoint: "https://example.com",
        EventTypes: []string{
            "TYPE1",
            "TYPE2",
        },
        Name: v2.String("customer_payment"),
        Secret: v2.String("V0bivxRWveaoz08afqjU6Ko/jwO0Cb+3"),
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.InsertConfig(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.ConfigResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request shared.ConfigUser ✔️ The request object to use for the request.

Response

*operations.InsertConfigResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /

TestConfig

Test a config by sending a webhook to its endpoint.

Example Usage

package main

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

func main() {
    s := v2.New(
        v2.WithSecurity(shared.Security{
            Authorization: "<YOUR_AUTHORIZATION_HERE>",
        }),
    )

    request := operations.TestConfigRequest{
        ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
    }
    
    ctx := context.Background()
    res, err := s.Webhooks.TestConfig(ctx, request)
    if err != nil {
        log.Fatal(err)
    }
    if res.AttemptResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.TestConfigRequest ✔️ The request object to use for the request.

Response

*operations.TestConfigResponse, error

Error Object Status Code Content Type
sdkerrors.WebhooksErrorResponse default application/json
sdkerrors.SDKError 4xx-5xx /