This is the Convoy JS SDK. This SDK contains methods for easily interacting with Convoy's API. Below are examples to get you started. You can view the full API Reference here
Install convoy.js
npm install convoy.jsNext, require the convoy module and set it up with your instance URL, API key, and project ID. Both the API key and project ID are available from your Project Settings page.
Your instance URL depends on where your project lives:
- Convoy Cloud (US):
https://us.getconvoy.cloud/api/v1 - Convoy Cloud (EU):
https://eu.getconvoy.cloud/api/v1 - Self-hosted:
https://your-instance/api/v1
// HTTP Client
const { Convoy } = require('convoy.js');
const convoy = new Convoy({ uri: 'https://us.getconvoy.cloud/api/v1', api_key: 'your_api_key', project_id: 'your_project_id' })
// Amazon SQS Client
const { Convoy } = require('convoy.js');
const convoy = new Convoy({ uri: 'https://us.getconvoy.cloud/api/v1', api_key: 'your_api_key', project_id: 'your_project_id', sqs_options: {} })
// Apache Kafka Client
const { Convoy } = require('convoy.js');
const convoy = new Convoy({ uri: 'https://us.getconvoy.cloud/api/v1', api_key: 'your_api_key', project_id: 'your_project_id', kafka_options: {} })An endpoint represents a target URL to receive events.
const endpointData = {
name: 'Default Endpoint',
url: "https://webhook.site/63baf442-bbf7-4d51-97e8-428ade404459",
description: "Default Endpoint",
secret: "endpoint-secret",
events: ["*"]
};
const response = await convoy.endpoints.create(endpointData);Store the Endpoint ID, so you can use it in subsequent requests for creating subscriptions or sending events.
const subscription = await convoy.subscriptions.create({
endpoint_id: '01HD6PJBQ0WE842PZ3J8SHDC46',
name: 'Test Subscription',
type: 'api'
});You can send events to Convoy via HTTP or via any supported message broker. See here to see the list of supported brokers.
// Send an event to a single endpoint.
const eventData = {
endpoint_id: endpointId,
event_type: "payment.success",
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
};
const response = await convoy.events.create(eventData);
// Fanout an event to multiple endpoints.
const fanoutData = {
owner_id: "some_unique_key",
event_type: "payment.success",
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
};
const fanoutResponse = await convoy.events.createFanOutEvent(fanoutData);
// Broadcast an event to every endpoint in the project.
const broadcastData = {
event_type: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
}
};
const broadcastResponse = await convoy.events.createBroadcastEvent(broadcastData);Note: The body struct used above is the same used for the message brokers below.
This library depends on aws-sdk-js-v3 to configure the SQS client.
// Send event to a single endpoint.
const data = await convoy.sqs.writeEvent({
endpoint_id: '01HCF8X23MWXCEWR3K3HB7KAY8',
event_type: '*',
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
});
// Fanout an event to multiple endpoints.
const data = await convoy.sqs.writeEvent({
owner_id: 'some_unique_key',
event_type: '*',
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
});This library depends on kafkajs to configure the Kafka client.
// Send event to a single endpoint.
const data = await convoy.kafka.writeEvent({
endpoint_id: '01HCF8X23MWXCEWR3K3HB7KAY8',
event_type: '*',
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
});
// Fanout an event to multiple endpoints.
const data = await convoy.kafka.writeEvent({
owner_id: 'some_unique_key',
event_type: '*',
data: {
event: "payment.success",
data: {
status: "Completed",
description: "Transaction Successful",
userID: "test_user_id808",
}
}
});This client supports verifying simple and advanced webhook signatures.
// verfiy a simple signature
const webhook = new Webhook({
header: '666060cbe1348bbc7ec98f4e93dda8eaaf11bbf283d6a2dd56e841b2ef12fcd465c846903f709942473e1442604798186746f04848702c44a773f80672de7b21',
payload: { email: 'test@gmail.com', first_name: 'test', last_name: 'test' },
secret: '8IX9njirDG',
hash: 'sha512',
encoding: 'hex',
});
webhook.verify()
// verfiy an advanced signature
const webhook = new Webhook({
header: 't=2048976161,v1=afdb90313acfa15a3fc425755ae651a204947710315bb2a90bccaa87fce88998,v1=fLBDCBUiX5iIs0L5zfNq45h23EkX1HAMpFF+2lHrnes=',
payload: { email: 'test@gmail.com' },
secret: '8IX9njirDG',
hash: 'sha256',
encoding: 'base64',
});
expect(webhook.verify()).toBeTruthy();npm run testPlease see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
The HTTP API client is generated from Convoy OpenAPI via Speakeasy. Webhook signature verification remains hand-written (src/webhook.ts) and is covered by shared tests/signature-vectors.json. See MIGRATION.md.
Convoy API Reference: Convoy is a fast and secure webhooks proxy. This document contains datastore's API specification.
Tip
To finish publishing your SDK to npm and others you must run your first generation action.
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
npm add https://github.com/frain-dev/convoy.jspnpm add https://github.com/frain-dev/convoy.jsbun add https://github.com/frain-dev/convoy.jsyarn add https://github.com/frain-dev/convoy.jsNote
This package is published with CommonJS and ES Modules (ESM) support.
For supported JavaScript runtimes, please consult RUNTIMES.md.
import { Convoy } from "convoy.js";
const convoy = new Convoy({
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
}
run();This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
apiKeyAuth |
http | HTTP Bearer |
To authenticate with the API the apiKeyAuth parameter must be set when initializing the SDK client instance. For example:
import { Convoy } from "convoy.js";
const convoy = new Convoy({
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
}
run();Available methods
- getDeliveryAttempts - List delivery attempts
- getDeliveryAttempt - Retrieve a delivery attempt
- getEndpoints - List all endpoints
- createEndpoint - Create an endpoint
- testOAuth2Connection - Test OAuth2 connection
- deleteEndpoint - Delete endpoint
- getEndpoint - Retrieve endpoint
- updateEndpoint - Update an endpoint
- activateEndpoint - Activate endpoint
- expireSecret - Roll endpoint secret
- pauseEndpoint - Pause endpoint
- getEventDeliveriesPaged - List all event deliveries
- batchRetryEventDelivery - Batch retry event delivery
- forceResendEventDeliveries - Force retry event delivery
- getEventDelivery - Retrieve an event delivery
- resendEventDelivery - Retry event delivery
- getEventsPaged - List all events
- createEndpointEvent - Create an event
- batchReplayEvents - Batch replay events
- createBroadcastEvent - Create a broadcast event
- countAffectedEvents - Count events matching batch replay filters
- createDynamicEvent - Dynamic Events
- createEndpointFanoutEvent - Fan out an event
- getEndpointEvent - Retrieve an event
- replayEndpointEvent - Replay event
- getEventTypes - Retrieves a project's event types
- createEventType - Create an event type
- importOpenApiSpec - Import event types from OpenAPI spec
- updateEventType - Updates an event type
- deprecateEventType - Deprecates an event type
- getFilters - List all filters
- createFilter - Create a new filter
- bulkCreateFilters - Create multiple subscription filters
- bulkUpdateFilters - Update multiple subscription filters
- testFilter - Test a filter
- deleteFilter - Delete a filter
- getFilter - Get a filter
- updateFilter - Update a filter
- getMetaEventsPaged - List all meta events
- getMetaEvent - Retrieve a meta event
- resendMetaEvent - Retry meta event
- bulkOnboard - Bulk onboard endpoints with subscriptions
- loadPortalLinksPaged - List all portal links
- createPortalLink - Create a portal link
- getPortalLink - Retrieve a portal link
- updatePortalLink - Update a portal link
- refreshPortalLinkAuthToken - Get a portal link auth token
- revokePortalLink - Revoke a portal link
- getProjects - List all projects
- createProject - Create a project
- deleteProject - Delete a project
- getProject - Retrieve a project
- updateProject - Update a project
- loadSourcesPaged - List all sources
- createSource - Create a source
- deleteSource - Delete a source
- getSource - Retrieve a source
- updateSource - Update a source
- postV1ProjectsProjectIDSourcesTestFunction - Validate source function
- getSubscriptions - List all subscriptions
- createSubscription - Create a subscription
- testSubscriptionFilter - Validate subscription filter
- testSubscriptionFunction - Test a subscription function
- deleteSubscription - Delete subscription
- getSubscription - Retrieve a subscription
- updateSubscription - Update a subscription
- toggleSubscriptionStatus - Toggle subscription status
All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
Available standalone functions
deliveryAttemptsGetDeliveryAttempt- Retrieve a delivery attemptdeliveryAttemptsGetDeliveryAttempts- List delivery attemptsendpointsActivateEndpoint- Activate endpointendpointsCreateEndpoint- Create an endpointendpointsDeleteEndpoint- Delete endpointendpointsExpireSecret- Roll endpoint secretendpointsGetEndpoint- Retrieve endpointendpointsGetEndpoints- List all endpointsendpointsPauseEndpoint- Pause endpointendpointsTestOAuth2Connection- Test OAuth2 connectionendpointsUpdateEndpoint- Update an endpointeventDeliveriesBatchRetryEventDelivery- Batch retry event deliveryeventDeliveriesForceResendEventDeliveries- Force retry event deliveryeventDeliveriesGetEventDeliveriesPaged- List all event deliverieseventDeliveriesGetEventDelivery- Retrieve an event deliveryeventDeliveriesResendEventDelivery- Retry event deliveryeventsBatchReplayEvents- Batch replay eventseventsCountAffectedEvents- Count events matching batch replay filterseventsCreateBroadcastEvent- Create a broadcast eventeventsCreateDynamicEvent- Dynamic EventseventsCreateEndpointEvent- Create an eventeventsCreateEndpointFanoutEvent- Fan out an eventeventsGetEndpointEvent- Retrieve an eventeventsGetEventsPaged- List all eventseventsReplayEndpointEvent- Replay eventeventTypesCreateEventType- Create an event typeeventTypesDeprecateEventType- Deprecates an event typeeventTypesGetEventTypes- Retrieves a project's event typeseventTypesImportOpenApiSpec- Import event types from OpenAPI speceventTypesUpdateEventType- Updates an event typefiltersBulkCreateFilters- Create multiple subscription filtersfiltersBulkUpdateFilters- Update multiple subscription filtersfiltersCreateFilter- Create a new filterfiltersDeleteFilter- Delete a filterfiltersGetFilter- Get a filterfiltersGetFilters- List all filtersfiltersTestFilter- Test a filterfiltersUpdateFilter- Update a filtermetaEventsGetMetaEvent- Retrieve a meta eventmetaEventsGetMetaEventsPaged- List all meta eventsmetaEventsResendMetaEvent- Retry meta eventonboardBulkOnboard- Bulk onboard endpoints with subscriptionsportalLinksCreatePortalLink- Create a portal linkportalLinksGetPortalLink- Retrieve a portal linkportalLinksLoadPortalLinksPaged- List all portal linksportalLinksRefreshPortalLinkAuthToken- Get a portal link auth tokenportalLinksRevokePortalLink- Revoke a portal linkportalLinksUpdatePortalLink- Update a portal linkprojectsCreateProject- Create a projectprojectsDeleteProject- Delete a projectprojectsGetProject- Retrieve a projectprojectsGetProjects- List all projectsprojectsUpdateProject- Update a projectsourcesCreateSource- Create a sourcesourcesDeleteSource- Delete a sourcesourcesGetSource- Retrieve a sourcesourcesLoadSourcesPaged- List all sourcessourcesUpdateSource- Update a sourcesubscriptionsCreateSubscription- Create a subscriptionsubscriptionsDeleteSubscription- Delete subscriptionsubscriptionsGetSubscription- Retrieve a subscriptionsubscriptionsGetSubscriptions- List all subscriptionssubscriptionsPostV1ProjectsProjectIDSourcesTestFunction- Validate source functionsubscriptionsTestSubscriptionFilter- Validate subscription filtersubscriptionsTestSubscriptionFunction- Test a subscription functionsubscriptionsToggleSubscriptionStatus- Toggle subscription statussubscriptionsUpdateSubscription- Update a subscription
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
import { Convoy } from "convoy.js";
const convoy = new Convoy({
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>", {
retries: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
console.log(result);
}
run();If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { Convoy } from "convoy.js";
const convoy = new Convoy({
retryConfig: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
}
run();ConvoyError is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
|---|---|---|
error.message |
string |
Error message |
error.statusCode |
number |
HTTP response status code eg 404 |
error.headers |
Headers |
HTTP response headers |
error.body |
string |
HTTP body. Can be empty string if no body is returned. |
error.rawResponse |
Response |
Raw HTTP response |
error.data$ |
Optional. Some errors may contain structured data. See Error Classes. |
import { Convoy } from "convoy.js";
import * as errors from "convoy.js/models/errors";
const convoy = new Convoy({
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
try {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
} catch (error) {
// The base class for HTTP error responses
if (error instanceof errors.ConvoyError) {
console.log(error.message);
console.log(error.statusCode);
console.log(error.body);
console.log(error.headers);
// Depending on the method different errors may be thrown
if (error instanceof errors.GetProjectsBadRequestError) {
console.log(error.data$.message); // string
console.log(error.data$.status); // boolean
console.log(error.data$.data); // { [k: string]: any }
}
}
}
}
run();Primary error:
ConvoyError: The base class for HTTP error responses.
Less common errors (211)
Network errors:
ConnectionError: HTTP client was unable to make a request to a server.RequestTimeoutError: HTTP request timed out due to an AbortSignal signal.RequestAbortedError: HTTP request was aborted by the client.InvalidRequestError: Any input used to create a request is invalid.UnexpectedClientError: Unrecognised or unexpected error.
Inherit from ConvoyError:
GetProjectsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateProjectBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeleteProjectBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetProjectBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateProjectBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEndpointsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*TestOAuth2ConnectionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeleteEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ActivateEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ExpireSecretBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*PauseEndpointBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEventTypesBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateEventTypeBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ImportOpenApiSpecBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateEventTypeBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeprecateEventTypeBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEventDeliveriesPagedBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*BatchRetryEventDeliveryBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ForceResendEventDeliveriesBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEventDeliveryBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ResendEventDeliveryBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetDeliveryAttemptsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetDeliveryAttemptBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEventsPagedBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateEndpointEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*BatchReplayEventsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateBroadcastEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CountAffectedEventsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateDynamicEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateEndpointFanoutEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetEndpointEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ReplayEndpointEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetMetaEventsPagedBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetMetaEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ResendMetaEventBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*BulkOnboardBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*LoadPortalLinksPagedBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreatePortalLinkBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetPortalLinkBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdatePortalLinkBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*RefreshPortalLinkAuthTokenBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*RevokePortalLinkBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*LoadSourcesPagedBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateSourceBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeleteSourceBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetSourceBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateSourceBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*PostV1ProjectsProjectIDSourcesTestFunctionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetSubscriptionsBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateSubscriptionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*TestSubscriptionFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*TestSubscriptionFunctionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeleteSubscriptionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetSubscriptionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateSubscriptionBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*ToggleSubscriptionStatusBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetFiltersBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*CreateFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*BulkCreateFiltersBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*BulkUpdateFiltersBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*TestFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*DeleteFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*UpdateFilterBadRequestError: Bad Request. Status code400. Applicable to 1 of 67 methods.*GetProjectsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateProjectUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeleteProjectUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetProjectUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateProjectUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEndpointsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*TestOAuth2ConnectionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeleteEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ActivateEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ExpireSecretUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*PauseEndpointUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEventTypesUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateEventTypeUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ImportOpenApiSpecUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateEventTypeUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeprecateEventTypeUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEventDeliveriesPagedUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*BatchRetryEventDeliveryUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ForceResendEventDeliveriesUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEventDeliveryUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ResendEventDeliveryUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetDeliveryAttemptsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetDeliveryAttemptUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEventsPagedUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateEndpointEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*BatchReplayEventsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateBroadcastEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CountAffectedEventsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateDynamicEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateEndpointFanoutEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetEndpointEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ReplayEndpointEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetMetaEventsPagedUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetMetaEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ResendMetaEventUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*BulkOnboardUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*LoadPortalLinksPagedUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreatePortalLinkUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetPortalLinkUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdatePortalLinkUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*RefreshPortalLinkAuthTokenUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*RevokePortalLinkUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*LoadSourcesPagedUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateSourceUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeleteSourceUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetSourceUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateSourceUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*PostV1ProjectsProjectIDSourcesTestFunctionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetSubscriptionsUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateSubscriptionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*TestSubscriptionFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*TestSubscriptionFunctionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeleteSubscriptionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetSubscriptionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateSubscriptionUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*ToggleSubscriptionStatusUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetFiltersUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*CreateFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*BulkCreateFiltersUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*BulkUpdateFiltersUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*TestFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*DeleteFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*GetFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*UpdateFilterUnauthorizedError: Unauthorized. Status code401. Applicable to 1 of 67 methods.*PaymentRequiredError: Payment Required. Status code402. Applicable to 1 of 67 methods.*CreateProjectForbiddenError: Forbidden. Status code403. Applicable to 1 of 67 methods.*DeleteProjectForbiddenError: Forbidden. Status code403. Applicable to 1 of 67 methods.*UpdateProjectForbiddenError: Forbidden. Status code403. Applicable to 1 of 67 methods.*GetProjectsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateProjectNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeleteProjectNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetProjectNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateProjectNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEndpointsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*TestOAuth2ConnectionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeleteEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ActivateEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ExpireSecretNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*PauseEndpointNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEventTypesNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateEventTypeNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ImportOpenApiSpecNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateEventTypeNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeprecateEventTypeNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEventDeliveriesPagedNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*BatchRetryEventDeliveryNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ForceResendEventDeliveriesNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEventDeliveryNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ResendEventDeliveryNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetDeliveryAttemptsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetDeliveryAttemptNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEventsPagedNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateEndpointEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*BatchReplayEventsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateBroadcastEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CountAffectedEventsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateDynamicEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateEndpointFanoutEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetEndpointEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ReplayEndpointEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetMetaEventsPagedNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetMetaEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ResendMetaEventNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*BulkOnboardNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*LoadPortalLinksPagedNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreatePortalLinkNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetPortalLinkNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdatePortalLinkNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*RefreshPortalLinkAuthTokenNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*RevokePortalLinkNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*LoadSourcesPagedNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateSourceNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeleteSourceNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetSourceNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateSourceNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*PostV1ProjectsProjectIDSourcesTestFunctionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetSubscriptionsNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateSubscriptionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*TestSubscriptionFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*TestSubscriptionFunctionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeleteSubscriptionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetSubscriptionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateSubscriptionNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ToggleSubscriptionStatusNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetFiltersNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*CreateFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*BulkCreateFiltersNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*BulkUpdateFiltersNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*TestFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*DeleteFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*GetFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*UpdateFilterNotFoundError: Not Found. Status code404. Applicable to 1 of 67 methods.*ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. Seeerror.rawValuefor the raw value anderror.pretty()for a nicely formatted multi-line string.
* Check the method documentation to see if the error is applicable.
You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
| # | Server | Description |
|---|---|---|
| 0 | https://us.getconvoy.cloud/api |
US Region |
| 1 | https://eu.getconvoy.cloud/api |
EU Region |
import { Convoy } from "convoy.js";
const convoy = new Convoy({
serverIdx: 0,
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
}
run();The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:
import { Convoy } from "convoy.js";
const convoy = new Convoy({
serverURL: "https://eu.getconvoy.cloud/api",
apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await convoy.projects.getProjects("<id>");
console.log(result);
}
run();The TypeScript SDK makes API calls using an HTTPClient that wraps the native
Fetch API. This
client is a thin wrapper around fetch and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.
The HTTPClient constructor takes an optional fetcher argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.
The following example shows how to:
- route requests through a proxy server using undici's ProxyAgent
- use the
"beforeRequest"hook to add a custom header and a timeout to requests - use the
"requestError"hook to log errors
import { Convoy } from "convoy.js";
import { ProxyAgent } from "undici";
import { HTTPClient } from "convoy.js/lib/http";
const dispatcher = new ProxyAgent("http://proxy.example.com:8080");
const httpClient = new HTTPClient({
// 'fetcher' takes a function that has the same signature as native 'fetch'.
fetcher: (input, init) =>
// 'dispatcher' is specific to undici and not part of the standard Fetch API.
fetch(input, { ...init, dispatcher } as RequestInit),
});
httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request, {
signal: request.signal || AbortSignal.timeout(5000)
});
nextRequest.headers.set("x-custom-header", "custom value");
return nextRequest;
});
httpClient.addHook("requestError", (error, request) => {
console.group("Request Error");
console.log("Reason:", `${error}`);
console.log("Endpoint:", `${request.method} ${request.url}`);
console.groupEnd();
});
const sdk = new Convoy({ httpClient: httpClient });You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console's interface as an SDK option.
Warning
Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
import { Convoy } from "convoy.js";
const sdk = new Convoy({ debugLogger: console });