All Projects → setyongr → B24

setyongr / B24

Licence: mit
Bitrix24 Client Library

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to B24

Cup
CUP, common useful python-lib. (Currently, Most popular python lib in baidu)
Stars: ✭ 826 (+4488.89%)
Mutual labels:  library
Realm Core
Core database component for the Realm Mobile Database SDKs
Stars: ✭ 836 (+4544.44%)
Mutual labels:  library
Minifuture
A monadic Future design pattern implementation in Swift
Stars: ✭ 16 (-11.11%)
Mutual labels:  library
Tfidf
Simple TF IDF Library
Stars: ✭ 6 (-66.67%)
Mutual labels:  library
Arma3launcherlib
Simple .NET library containing everything needed for a custom Arma 3 launcher.
Stars: ✭ 7 (-61.11%)
Mutual labels:  library
Matter
Material Design Components in Pure CSS. Materializing HTML at just one class per component 🍰
Stars: ✭ 888 (+4833.33%)
Mutual labels:  library
Zlib Ng
zlib replacement with optimizations for "next generation" systems.
Stars: ✭ 807 (+4383.33%)
Mutual labels:  library
Styledecorator
Easy string decoration with styles
Stars: ✭ 17 (-5.56%)
Mutual labels:  library
Greedo Layout For Ios
Full aspect ratio grid layout for iOS
Stars: ✭ 837 (+4550%)
Mutual labels:  library
Galgo Ios
When you want your logs to be displayed on screen
Stars: ✭ 16 (-11.11%)
Mutual labels:  library
Experiment
🔬 Elixir Library for carefully refactoring critical paths by performing experiments.
Stars: ✭ 6 (-66.67%)
Mutual labels:  library
Sumologic Python
Sumologic's python api library
Stars: ✭ 6 (-66.67%)
Mutual labels:  library
Elongation Preview
ElongationPreview is an elegant UI push-pop style view controller. iOS library made by @Ramotion
Stars: ✭ 888 (+4833.33%)
Mutual labels:  library
Rulerz
Powerful implementation of the Specification pattern in PHP
Stars: ✭ 827 (+4494.44%)
Mutual labels:  library
Scalable Image Matching
This is a image matching system for scalable and efficient matching of images from a large database. The basic idea is to compute perceptural hash value for each image and compare the similarity based on the pHash computed. Searching are scalable with the elasticsearch as the backend database.
Stars: ✭ 17 (-5.56%)
Mutual labels:  library
Devtools
The Hoa\Devtools library.
Stars: ✭ 5 (-72.22%)
Mutual labels:  library
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (-11.11%)
Mutual labels:  library
Coord Rs
[deprecated] A simple, ergonomic vector mathematics crate for Rust
Stars: ✭ 18 (+0%)
Mutual labels:  library
Multicolortextview
Stars: ✭ 17 (-5.56%)
Mutual labels:  library
Shpref Library
💾 Android Kotlin library. Shared preferences wrapper. (2020)
Stars: ✭ 16 (-11.11%)
Mutual labels:  library

Bitrix24 Client Library

Installation

npm install b24 --save

Modes

There are 2 modes to use this library. API mode and Webhook mode.

You can specify the mode when initializing Bitrix24.

API Mode

When you use API mode, you must authenticate the user using OAuth. See Authentication for example. You also must provide client_id, client_secret, and redirect_uri in config block.

Method Hook

There are 2 method that will called when using API mode. saveToken(data) and retriveToken. You can use this to save and get token from database.

Example

const b24 = require('b24');

const bitrix24 = new b24.Bitrix24({
    config: {
        mode: "api",
        host: "your bitrix host",
        client_id : "your client id",
        client_secret : "your client secret",
        redirect_uri : "http://localhost:3000/callback"
    },
    methods: {
        async saveToken(data){
            //Save token to database
        },
        async retriveToken(){
            //Retrive token from database
            return {
                access_token: "youraccesstoken",
                refresh_token: "yourrefreshtoken"
            }
        }
    }
})

Webhook Mode

It use webhook feature from Bitrix24 To use this you must provide user_id and code in config block.

user_id can be obtained throught my profile page. See the URL, e.g https://k2d2.bitrix24.com/company/personal/user/4/. The value would be 4

code can be obtained throught Application -> Web hooks -> ADD WEB HOOK -> Inbound web hook

Example

const b24 = require('b24');

const bitrix24 = new b24.Bitrix24({
    config: {
        mode: "webhook",
        host: "your bitrix host",
        user_id: "1",
        code: "your_webhook_code"
    }
})

Authentication

You must do authentication when use API mode. It just OAuth2

Step:

  1. Visit url provided by bitrix24.auth.authorization_uri
  2. It will give you the code in callback url, use this to get token
  3. Get token with bitrix24.auth.getToken(code)
  4. Profit!!!

Example:

const express = require('express');
const b24 = require('b24');

const app = express()

const bitrix24 = new b24.Bitrix24({
    config: {
        mode: "api",
        host: "your bitrix host",
        client_id : "your client id",
        client_secret : "your client secret",
        redirect_uri : "http://localhost:3000/callback"
    },
    methods: {
        async saveToken(data){
            //Save token to database
        },
        async retriveToken(){
            //Retrive token from database
            return {
                access_token: "youraccesstoken",
                refresh_token: "yourrefreshtoken"
            }
        }
    }
})

// Bitrix auth
app.get('/auth', (req, res) => {
    res.redirect(bitrix24.auth.authorization_uri);
});

// Callback service parsing the authorization token and asking for the access token
app.get('/callback', async (req, res) => {
    try{
        const code = req.query.code;
        const result = await bitrix24.auth.getToken(code);
        return res.json(result);
    }catch(err){
        console.log(err)
        return res.status(500).json({message:"Authentication Failed"});
    }
});

app.listen(3000, () => {
    console.log('Server started on port 3000');
});

Run Bitrix24 API

For complete API refrence visit https://training.bitrix24.com/rest_help/index.php

To Run Bitrix24 API we need to use callMethod(method, param) method.

pass the method you want to run in method parameter, param parameter is optional, it used to add parameter to method that you call, visit the official API reference to see all possible parameter.

Example:

const express = require('express');
const b24 = require('b24');

const app = express()

const bitrix24 = new b24.Bitrix24({
    config: {
        mode: "webhook",
        host: "your bitrix host",
        user_id: "1",
        code: "your_webhook_code"
    }
})

// Get all Bitrix24 User
app.get('/allUser', async (req, res) => {
    try{
        const result = await bitrix24.callMethod('user.get');
        return res.json(result);        
    }catch(err){
        console.log(err)
        return res.status(500).json({message:"Internal Server Error"});
    }
})

app.listen(3000, () => {
    console.log('Server started on port 3000');
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].