Skip to content

Latest commit

 

History

History
335 lines (259 loc) · 20.1 KB

README.md

File metadata and controls

335 lines (259 loc) · 20.1 KB

Webhooks

(Webhook.Webhooks)

Overview

Available Operations

  • List - List webhook subscriptions
  • Create - Create webhook subscription
  • Get - Get webhook subscription
  • Update - Update webhook subscription
  • Delete - Delete webhook subscription

List

List all webhook subscriptions

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Webhook.Webhooks.List(ctx, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.GetWebhooksResponse != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
cursor *string Cursor to start from. You can find cursors for next/previous pages in the meta.cursors property of the response.
limit *int64 Number of results to return. Minimum 1, Maximum 200, Default 20
opts []operations.Option The options for this request.

Response

*operations.WebhookWebhooksAllResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Create a webhook subscription to receive events

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"github.com/apideck-libraries/sdk-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Webhook.Webhooks.Create(ctx, components.CreateWebhookRequest{
        Description: sdkgo.String("A description"),
        UnifiedAPI: components.UnifiedAPIIDCrm,
        Status: components.StatusEnabled,
        DeliveryURL: "https://example.com/my/webhook/endpoint",
        Events: []components.WebhookEventType{
            components.WebhookEventTypeVaultConnectionCreated,
            components.WebhookEventTypeVaultConnectionUpdated,
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CreateWebhookResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.CreateWebhookRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.WebhookWebhooksAddResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get the webhook subscription details

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Webhook.Webhooks.Get(ctx, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res.GetWebhookResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ JWT Webhook token that represents the unifiedApi and applicationId associated to the event source.
opts []operations.Option The options for this request.

Response

*operations.WebhookWebhooksOneResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update a webhook subscription

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"github.com/apideck-libraries/sdk-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Webhook.Webhooks.Update(ctx, "<id>", components.UpdateWebhookRequest{
        Description: sdkgo.String("A description"),
        Status: components.StatusEnabled.ToPointer(),
        DeliveryURL: sdkgo.String("https://example.com/my/webhook/endpoint"),
        Events: []components.WebhookEventType{
            components.WebhookEventTypeVaultConnectionCreated,
            components.WebhookEventTypeVaultConnectionUpdated,
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.UpdateWebhookResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ JWT Webhook token that represents the unifiedApi and applicationId associated to the event source.
updateWebhookRequest components.UpdateWebhookRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.WebhookWebhooksUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a webhook subscription

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Webhook.Webhooks.Delete(ctx, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res.DeleteWebhookResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ JWT Webhook token that represents the unifiedApi and applicationId associated to the event source.
opts []operations.Option The options for this request.

Response

*operations.WebhookWebhooksDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*