All Projects → 2BAD → bitrix

2BAD / bitrix

Licence: MIT license
Bitrix24 REST API client that doesn't suck. Suffer no more.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to bitrix

Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (-59.32%)
Mutual labels:  api-client, rest-client
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+17923.73%)
Mutual labels:  api-client, rest-client
Datafire
A framework for building integrations and APIs
Stars: ✭ 487 (+725.42%)
Mutual labels:  api-client, rest-client
Apipie
Transform api declaration to js object for frontend. Inspired by VueRouter, koa-middleware and axios.
Stars: ✭ 29 (-50.85%)
Mutual labels:  api-client, rest-client
NClient
💫 NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Stars: ✭ 25 (-57.63%)
Mutual labels:  api-client, rest-client
radiobrowser4j
RadioBrowser Java API library
Stars: ✭ 30 (-49.15%)
Mutual labels:  api-client, rest-client
Apiclientcodegen
A collection of Visual Studio custom tool code generators for Swagger / OpenAPI specification files
Stars: ✭ 50 (-15.25%)
Mutual labels:  api-client, rest-client
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-79.66%)
Mutual labels:  api-client, rest-client
YuiAPI
一个浏览器API测试客户端,API文档生成器,支持chrome/firefox/新版edge
Stars: ✭ 25 (-57.63%)
Mutual labels:  api-client, rest-client
drowsy
😪 Lazy integrations tool for RESTful interfaces to aid POC development and streamline integrations
Stars: ✭ 19 (-67.8%)
Mutual labels:  api-client, rest-client
Parse Dashboard For Ios
A beautiful mobile client for managing your Parse apps while you are on the go! Now you can easily view and modify your data in the same way you would on the offical desktop client.
Stars: ✭ 81 (+37.29%)
Mutual labels:  api-client, rest-client
sevenbridges-python
SevenBridges Python Api bindings
Stars: ✭ 41 (-30.51%)
Mutual labels:  api-client, rest-client
restofus
Restofus - a cross-platform (REST) API client.
Stars: ✭ 18 (-69.49%)
Mutual labels:  api-client, rest-client
apiron
🍳 apiron is a Python package that helps you cook a tasty client for RESTful APIs. Just don't wash it with SOAP.
Stars: ✭ 106 (+79.66%)
Mutual labels:  api-client, rest-client
midtrans-python-client
Official Midtrans Payment API Client for Python | https://midtrans.com
Stars: ✭ 24 (-59.32%)
Mutual labels:  api-client
sleeper-api-wrapper
A Python wrapper for the Sleeper Fantasy Football API.
Stars: ✭ 41 (-30.51%)
Mutual labels:  api-client
homeberry
HomeBerry is an Android remote control app for your Raspberry PI
Stars: ✭ 31 (-47.46%)
Mutual labels:  rest-client
synadm
Command line admin tool for Synapse (Matrix reference homeserver)
Stars: ✭ 93 (+57.63%)
Mutual labels:  api-client
WeConnect-python
Python API for the Volkswagen WeConnect Services
Stars: ✭ 27 (-54.24%)
Mutual labels:  api-client
laravel-transporter
Transporter is a futuristic way to send API requests in PHP. This is an OOP approach to handling API requests.
Stars: ✭ 282 (+377.97%)
Mutual labels:  api-client
description
that doesn't suck

Bitrix24 REST API client

NPM version License Code coverage Travis Build Status GitHub Build Status Dependency Status Written in TypeScript

  • 🔥 No bullshit
  • Expressive API
  • 💪 Strongly typed methods and requests results with TypeScript
  • 🚀 Handles records batching and rate limiting for you
  • ❤️ Promise-based

@2bad/bitrix usage example

Install

npm install @2bad/bitrix

Usage

Init client with Bitrix API endpoint and access token and use the client to ease your Bitrix pain:

import Bitrix from '@2bad/bitrix'

const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN')

// Get deal
bitrix.deals.get('77')
  .then(({ result }) => {
    // Get typed payload
    const { TITLE } = result // string
    console.log(TITLE)
  })
  .catch(console.error)

// Get all deals
bitrix.deals.list({ select: ["*", "UF_*"] })
  .then(({ result }) => {
    const titles = result.map((e) => e.TITLE)
    console.log(titles)
  })
  .catch(console.error)

Authentication

Before you'll be able to use Bitrix REST API, you need to authenticate.

There are two ways to do that:

  1. A harder, but proper way — create a Bitrix application and then authenticate with an OAuth.

    Authentication with an OAuth requires some additional steps and that's up to you to deal with it using a lambda function, some server or a Postman.

    That will yield an access token. Use it to init the client:

    const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN')

    Note, that access token lives only 30 minutes and should be refreshed periodically with provided by OAuth refresh token, which in turn lives 1 month.

  2. An easier way — create a Bitrix inbound webhook with required permissions.

    It will instantly give you an endpoint with a token inside of it. No additional authentication or access tokens required to use it:

    const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest/1/WEBHOOK_TOKEN')

    That endpoint lives indefinitely. Rejoice and hope that it won't backfire on you.

API

How it works

The client tries hard to provide a consistent, strongly typed and at the same time effortless experience.

It takes care of the any necessary batching to run "large" commands, like retrieving all deals or leads with least possible network request. That allows achieving a reading of the 250 000 and updating of 5000 entries per minute with a single line of code.

All client methods are automatically rate-limited and queued if needed to cope with Bitrix REST API limitation of 2 requests per second, so you should never see Bitrix errors about exceeding rate limits.

Methods required params and returned payload types are automatically resolved based on Methods interface, which effectively describes all currently supported methods.

To facilitate better architecture, the client divided into layers:

  1. Methods — a mostly generic methods like call to work with Bitrix API methods. They take care of the routine and provide a foundation for more complex operations.
  2. Client — a generic client, which takes care of some additional routine tasks like setting access token on every request, setting up a queue for the rate limiting, and providing generic methods.
  3. Services — each service provides an expressive interface to work with a specific group of Bitrix REST API operations. In essence, they do orchestrate generic client methods and parameters to get proper results.
  4. Bitrix client — a top-level provider of generic method and services. An effortless way to deal with Bitrix REST API by using an intuitive API, which takes care of all underlying complexity.

FAQ

Is it finished?

The core is ready and stable. It can be used to arbitrary invoke any Bitrix REST API methods.

However, not all Bitrix REST API methods are exposed as convenient client services yet (the ones like bitrix.deals.list()).

If you need specific service, add one by making a Pull Request, following the structure of already existing services and "Adding new methods" instructions.

I'm not a Typed Language Master Race user. Can I use it with a regular JavaScript?

Sure. Just install and import it as any other NPM module. But The Type Police is already on the way for you.

Note that this library wasn't designed with regular JavaScript in mind, so it doesn't make unnecessary dynamic checks. Don't be too persistent in passing on wrong parameters — it might yield unexpected results. After all, TypeScript is a recommended way to use it.

Should I check payloads error properties for errors?

You shouldn't. Catch rejections instead, as the library will reject if there are any errors in a payload.

List method does not return user fields!

Bitrix API doesn't do that by default. Use wildcards in select param to force inclusion of user fields:

bitrix.deals.list({ select: ['*', 'UF_*'] })

User fields are not typed properly

Client can't know about non-default properties in payloads. Because of that, it assumes that any payload can have any additional fields of type [key: string]: string:

bitrix.leads.get({ ID: '77' })
  .then(({ result }) => {
    // known property of type `string`
    const title = result.TITLE

    // unknown property of type `string`
    const someData = result.UF_23232323

    console.log(title, someData)
  })

I need to call a Bitrix method which isn't supported yet

Use appropriate low-level client methods with a casting, like so:

bitrix.call('some.new.get' as any, { ID: '77' } as any)
  .then((payload) => payload as GetPayload<NewPayload>)

bitrix.list('some.new.list' as any, { select: ["TITLE"] })
  .then((payload) => payload as ListPayload<NewPayload>)

I need to call a specific set of commands. How to do that effectively?

Use the batch method. It will handle all routine:

bitrix.batch({
  lead: { method: Method.GET_LEAD, params: { ID: '77' } },
  deals: { method: Method.LIST_DEALS, params: {} }
})

Development

  • npm test — run all tests and collect full coverage report
  • npm run test:unit — run unit tests and collect coverage report
  • npm run test:integration — run integration tests and collect coverage report
  • npm run test:watch — watch for changes and run all tests
  • npm run test:unit:watch — watch for changes and run unit tests
  • npm run test:integration:watch — watch for changes and run integration tests
  • npm run build — build the library for the release

Adding new methods

Proper method parameters and payload types handling requires some routine when adding any new method. Hopefully, we can do it better in future, but for now follow those steps:

  1. Add new method into the Method enum.
  2. Add it into the LISTABLE_METHODS array if it is listable (paginated). Not everything that lists is listable, so check it.
  3. Add or update related service:
    1. Put exposed by the service public methods into the index.ts file. Ensure that you're properly mapping service method arguments to call or list params.
    2. Add related entities into the entities.ts.
    3. Add interface describing service methods into the methods.ts. Test and check method payload type to be sure you've described it correctly!
    4. Extend Methods interface with the added service-specific interface. That way the client will know how to resolve parameters and payload types for the added method.
    5. Add tests into the index.unit.test.ts.
  4. Re-export service public types like Entities in the bitrix.ts to make them available to the end-users.
  5. Document addition in the docs.
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].