npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitrix24-promise

v0.0.5

Published

Authorize and make bitrix 24 requests with request-promise.

Downloads

5

Readme

Bitrix24-promise

A Node.js module that provides automatic authorization to a Bitrix24-based CRM system, allowing you to call BX24 REST API methods using promises with a similar syntax, without ever touching the weird window-based official Javascript library.

Usage

Initialize the library by providing the credentials, add a route to listen to the oauth token, then call Bitrix methods:

const express = require('express');
const app = express();
const BX24 = require('bitrix24-promise');
BX24.initialize({
    url:'https://your-bitrix-portal.bitrix24.ru',
    credentials:{
        client: {
            id: 'local.123456idstring.78901011',
            secret: 'bitrix secret string'
        },
        auth: {
            tokenHost: 'https://oauth.bitrix.info',
            tokenPath: '/oauth/token/',
            authorizePath: '/oauth/authorize'
        },
        user: {
            login: '[email protected]',
            password: 'hunter2'
        }
    },
    scope:'crm'
});
app.get('/bitrix/auth', BX24.authenticate(), function(req, res){
    res.send('Authorization successful');
    BX24.callMethod('crm.contact.list').then(function(result){
        for(let user of result)
            console.log(user.NAME);
    });
});

Installation

npm install bitrix24-promise

Developer Reference

For Bitrix24 API documentation, see https://dev.1c-bitrix.ru/rest_help/index.php

BX24.initialize({})

Set up the library and optionally try to authorize automatically. Return a promise that can contain the token if authorization was automatic, but the recommended way of getting data on initialization is to put the request in token callback.

url:'https://your-bitrix-portal.bitrix24.ru', //required - base url of your bitrix portal
credentials:{
    client: {
        id: 'local.123456idstring.78901011', //required - id of your app
        secret: 'bitrix secret string that is usually long'  //required - secret string of your app
    },
    auth: {
        tokenHost: 'https://oauth.bitrix.info', //required - base url of oauth server
        tokenPath: '/oauth/token/', //required - oauth grant token url
        authorizePath: '/oauth/authorize' //required - oauth url with user authorization
    },
    user: {
        login: '[email protected]', //optional - username for automatic authorization
        password: 'hunter2' //optional - password for automatic authorization
    },
    scope:'crm' //optional - default is 'crm'
}

For the possible scope field values, see https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=99&LESSON_ID=2280 . Multiple values in the string should be separated by commas.

BX24.tokenCallback(req, res, next)

Express middleware to grab auth data and request the access token. It is necessary to use this middleware with either manual or automatic authorization. All BX24 methods called after this middleware will have the access token.

BX24.manualAuthURL(req, res)

Express route that redirects the user to the OAuth site. You can do the redirect in your own routes and this one is provided just for convinience.

BX24.getToken()

Returns a token promise. Calling this method will refresh the token if it is expired.

{
    accessToken: 'String' //token that can be used to access Bitrix API outside of the callMethod() function
    refreshToken: 'String' //refresh token used internally to refresh the token when it expires
    expiresAt: Number // amount of milliseconds from 1 January 1970 to the moment this accessToken expires
}

BX24.callMethod(method, params)

Call a Bitrix method, refreshing the token if necessary. Returns a promise with the request result. Parameters object is optional. For method descriptions, see the official Bitrix REST API documentation https://dev.1c-bitrix.ru/rest_help/index.php