Skip to content

Latest commit

 

History

History
435 lines (329 loc) · 22.7 KB

README.md

File metadata and controls

435 lines (329 loc) · 22.7 KB

Subscribers

(Subscribers)

Overview

Available Operations

List

Returns a list of subscribers, could paginated using the page and limit query parameter

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

    res, err := s.Subscribers.List(ctx, nil, novugo.Float64(10))
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != 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.
page *float64 N/A
limit *float64 N/A
opts []operations.Option The options for this request.

Response

*operations.SubscribersControllerListSubscribersResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

    res, err := s.Subscribers.Create(ctx, components.CreateSubscriberRequestDto{
        SubscriberID: "<id>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.SubscriberResponseDto != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.SubscribersControllerCreateSubscriberResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get subscriber by your internal id used to identify the subscriber

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

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

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
subscriberID string ✔️ N/A
includeTopics *bool Includes the topics associated with the subscriber
opts []operations.Option The options for this request.

Response

*operations.SubscribersControllerGetSubscriberResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Used to update the subscriber entity with new information

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

    res, err := s.Subscribers.Update(ctx, "<id>", components.UpdateSubscriberRequestDto{
        Email: novugo.String("[email protected]"),
        FirstName: novugo.String("John"),
        LastName: novugo.String("Doe"),
        Phone: novugo.String("+1234567890"),
        Avatar: novugo.String("https://example.com/avatar.jpg"),
        Locale: novugo.String("en-US"),
        Data: map[string]any{
            "preferences": map[string]any{
                "notifications": true,
                "theme": "dark",
            },
            "tags": []any{
                "premium",
                "newsletter",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.SubscriberResponseDto != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
subscriberID string ✔️ N/A
updateSubscriberRequestDto components.UpdateSubscriberRequestDto ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.SubscribersControllerUpdateSubscriberResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Deletes a subscriber entity from the Novu platform

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

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

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
subscriberID string ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.SubscribersControllerRemoveSubscriberResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

CreateBulk

  Using this endpoint you can create multiple subscribers at once, to avoid multiple calls to the API.
  The bulk API is limited to 500 subscribers per request.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

    res, err := s.Subscribers.CreateBulk(ctx, components.BulkSubscriberCreateDto{
        Subscribers: []components.CreateSubscriberRequestDto{
            components.CreateSubscriberRequestDto{
                SubscriberID: "<id>",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.BulkCreateSubscriberResponseDto != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.SubscribersControllerBulkCreateSubscribersResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*

UpdateOnlineStatus

Used to update the subscriber isOnline flag.

Example Usage

package main

import(
	"context"
	"os"
	novugo "github.com/novuhq/novu-go"
	"github.com/novuhq/novu-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := novugo.New(
        novugo.WithSecurity(os.Getenv("NOVU_API_KEY")),
    )

    res, err := s.Subscribers.UpdateOnlineStatus(ctx, "<id>", components.UpdateSubscriberOnlineFlagRequestDto{
        IsOnline: true,
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.SubscriberResponseDto != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
subscriberID string ✔️ N/A
updateSubscriberOnlineFlagRequestDto components.UpdateSubscriberOnlineFlagRequestDto ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.SubscribersControllerUpdateSubscriberOnlineFlagResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorDto 400, 404, 409 application/json
apierrors.ValidationErrorDto 422 application/json
apierrors.APIError 4XX, 5XX */*