Skip to content

Webhooks TypeScript

BL edited this page Jun 8, 2018 · 2 revisions

Usage

export TRELLO_API_KEY=KEY
export TRELLO_OAUTH_TOKEN=TOKEN

Configuration

Set your Trello Api Key and Trello Auth Token.

import * as TrelloNodeAPI from 'trello-node-api';
const Trello = new TrelloNodeAPI();
Trello.setApiKey(apiKey);
Trello.setOauthToken(oauthToken);

Webhooks

Create webhook

    let data = {
        description: 'Webhook description',
        callbackURL: 'https://mycallbackurl.com/', // REQUIRED
        idModel: 'MODEL_ID', // REQUIRED
        active: false
    };
    let response;
    try {
        response = await Trello.webhook.create(data);
    } catch (error) {
        if (error) {
            console.log('error ', error);
        }
    }
    console.log('response', response);

Search webhook

    let response;
    try {
        response = await Trello.webhook.search('WEBHOOK_ID');
    } catch (error) {
        if (error) {
            console.log('error ', error);
        }
    }
    console.log('response', response);

Search Field Webhook

    let response;
    try {
        response = await Trello.webhook.searchField('WEBHOOK_ID', 'FIELD_NAME');
    } catch (error) {
        if (error) {
            console.log('error ', error);
        }
    }
    console.log('response', response);

Update Webhook

    let id = 'WEBHOOK_ID'; // REQUIRED
    let data = {
        displayName: 'ORGANIZATION_DISPLAY_NAME',
        description: 'Webhook descriptions',
        callbackURL: 'https://mycallbackurl.com/',
        idModel: 'MODEL_ID',
        active: false
    };
    let response;
    try {
        response = await Trello.webhook.update(id, data);
    } catch (error) {
        if (error) {
            console.log('error ', error);
        }
    }
    console.log('response', response);

Delete Webhook

    let response;
    try {
        response = await Trello.webhook.del('WEBHOOK_ID');
    } catch (error) {
        if (error) {
            console.log('error ', error);
        }
    }
    console.log('response', response);