20 KiB
Webhooks
(Webhooks)
Available Operations
- ActivateConfig - Activate one config
- ChangeConfigSecret - Change the signing secret of a config
- DeactivateConfig - Deactivate one config
- DeleteConfig - Delete one config
- GetManyConfigs - Get many configs
- InsertConfig - Insert a new config
- TestConfig - Test one config
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/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.ActivateConfig(ctx, operations.ActivateConfigRequest{
ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
})
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.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/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.ChangeConfigSecret(ctx, operations.ChangeConfigSecretRequest{
ConfigChangeSecret: &shared.ConfigChangeSecret{
Secret: "V0bivxRWveaoz08afqjU6Ko/jwO0Cb+3",
},
ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
})
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 | 400 | 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/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.DeactivateConfig(ctx, operations.DeactivateConfigRequest{
ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
})
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 | 404 | application/json |
| sdkerrors.SDKError | 4xx-5xx | / |
DeleteConfig
Delete a webhooks config by ID.
Example Usage
package main
import(
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
"net/http"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.DeleteConfig(ctx, operations.DeleteConfigRequest{
ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
})
if err != nil {
log.Fatal(err)
}
if res.StatusCode == http.StatusOK {
// 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 | 400,404 | application/json |
| sdkerrors.SDKError | 4xx-5xx | / |
GetManyConfigs
Sorted by updated date descending
Example Usage
package main
import(
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.GetManyConfigs(ctx, operations.GetManyConfigsRequest{
Endpoint: formancesdkgo.String("https://example.com"),
ID: formancesdkgo.String("4997257d-dfb6-445b-929c-cbe2ab182818"),
})
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.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/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.InsertConfig(ctx, shared.ConfigUser{
Endpoint: "https://example.com",
EventTypes: []string{
"TYPE1",
"TYPE2",
},
Secret: formancesdkgo.String("V0bivxRWveaoz08afqjU6Ko/jwO0Cb+3"),
})
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 | 400 | 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/pkg/models/shared"
formancesdkgo "github.com/formancehq/formance-sdk-go"
"context"
"github.com/formancehq/formance-sdk-go/pkg/models/operations"
"log"
)
func main() {
s := formancesdkgo.New(
formancesdkgo.WithSecurity(shared.Security{
Authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
}),
)
ctx := context.Background()
res, err := s.Webhooks.TestConfig(ctx, operations.TestConfigRequest{
ID: "4997257d-dfb6-445b-929c-cbe2ab182818",
})
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 | 400,404 | application/json |
| sdkerrors.SDKError | 4xx-5xx | / |