search icon

Convoy App SDK

We extended the visibility we provide you on the Convoy dashboard to your users through app portal; your users can view, debug and inspect events sent to them. The App Portal is available through convoy-app.js SDK, through which you can render our pre-built UI on your platform out of the box or use it to power your custom built UI for your users. We automatically manage your customer's application context so you don't have to be concerned about a customer seeing events from another customer.

Usage

You can embed the convoy-app.js sdk into your client application through any of the following ways:

  • Using Jsdelivr
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bundle.js"></script>
  • Installing the convoy-app.js node module
terminal
$ npm i convoy-app.js
import * as Convoy from 'convoy-app.js';

// Or

<script src="node_modules/convoy-app.js/dist/bundle.js"></script>

Initializing

You need two details to setup convoy app:

  • url; this represents you Convoy instance url
  • api_key; authentication token generated from your backend system see API reference here

Javascript

const convoy = new Convoy({ uri: 'convoy instance url', api_key: 'app token from your backend'});

Typescript

declare const Convoy: any;

export class ConvoyExampleClass {
    convoy: any;

    constructor() {
        this.convoy = new Convoy({ uri: 'convoy instance url', api_key: 'app token from your backend'})
    }
}

SDK Methods

App Portal UI

You can use the SDK to load app portal within your client platform

example
convoy.initAppPortal();
// You can optionally pass a DOM selector string, convoy-app uses #convoy-app by default
convoy.initAppPortal('#convoy-app');

convoy app portal

Create Subscription Modal

You can use the SDK to load a modal that renders a form for your users to create subscription

example
convoy.createSubscription();
// You can optionally pass a DOM selector string, convoy-app uses #convoy-create-sub by default
convoy.createSubscription('#convoy-create-sub');

convoy app portal

App Event

You can use the SDK to get the app's events

example
try {
    const response = await convoy.events.all();
} catch (error) {
    console.log(error);
}


try {
    const response = await convoy.events.get(eventId);
} catch (error) {
    console.log(error);
}

Event Deliveries

You can use the SDK to get the app's event deliveries

example
try {
    const response = await convoy.eventDeliveries.all();
} catch (error) {
    console.log(error);
}

try {
    const response = await convoy.eventDeliveries.get(eventDeliveryId);
} catch (error) {
    console.log(error);
}


// get event delivery attempt

try {
    const response = await convoy.eventDeliveries.deliveryAttempts(eventDeliveryId);
} catch (error) {
    console.log(error);
}

try {
    const response = await convoy.eventDeliveries.deliveryAttempt(eventDeliveryId, eventDeliveryAttemptId);
} catch (error) {
    console.log(error);
}



// resend event

try {
    const response = await convoy.eventDeliveries.resend(eventDeliveryId);
} catch (error) {
    console.log(error);
}



// batch resend events

try {
    const response = await convoy.eventDeliveries.batchResend({ids: [...eventDeliveryIds]});
} catch (error) {
    console.log(error);
}

Subscription

You can use the SDK to get the app's subscription

example
try {
    const response = await convoy.subscriptions.all();
} catch (error) {
    console.log(error);
}


try {
    const response = await convoy.subscriptions.get(eventId);
} catch (error) {
    console.log(error);
}
Contribute to this doc in Github
Updated at May 26, 2023

Don't miss anything.

Subscribe to the Convoy Newsletter find tutorials and tools that will help you grow as a developer and scale your project or business, and see interesting topics.