View Source BitrixEx (bitrix_ex v0.1.0)

HTTP client make using Tesla for integrating with the Bitrix24 API

Summary

Functions

authenticate application add get access token

Generate authorization url

Call method using a webhook url

Call method using a webhook url

Similar to the previous ones, but it has the additional parameter opts for using Tesla resources.

use refresh token to get a new access token

Functions

@spec application_url() :: binary()
Link to this function

authenticate(client_code, opts \\ [])

View Source
@spec authenticate(
  client_code :: String.t(),
  opts :: keyword()
) :: {:ok, map()} | {:error, any()}

authenticate application add get access token

Link to this function

authorization_url(redirect_uri \\ "")

View Source
@spec authorization_url(redirect_uri :: String.t()) :: String.t()

Generate authorization url

Examples

iex> BitrixEx.authorization_url()
"https://mydomain.bitrix24.com/oauth/authorize/?client_id=app.xxxxxxxxxxxxxx.xxxxxxxx&response_type=code"

additionally you can add a redirect uri

iex> redirect_uri = "https://mydomain.com/callback"
iex> BitrixEx.authorization_url(redirect_uri)
"https://mydomain.bitrix24.com/oauth/authorize/?client_id=app.xxxxxxxxxxxxxx.xxxxxxxx&redirect_uri=https%3A%2F%2Fmydomain.com%2Fcallback&response_type=code"
@spec call_method(method :: String.t()) :: {:ok, map()} | {:error, any()}

Call method using a webhook url

config :bitrix_ex,
  webhook_url: "https://mydomain.bitrix24.com/rest/1/xxxx"

Examples

iex> BitrixEx.call_method("tasks.task.list")
{:ok, %{"result" => %{"tasks" => []}}}
Link to this function

call_method(method, params)

View Source
@spec call_method(
  method :: String.t(),
  params :: map()
) :: {:ok, map()} | {:error, any()}

Call method using a webhook url

Examples

config :bitrix_ex,
  webhook_url: "https://mydomain.bitrix24.com/rest/1/xxxx"

iex> method = "tasks.task.list"
iex> params = %{select: ["ID", "TITLE"], filter: %{"GROUP_ID" => 1}}
iex> BitrixEx.call_method(method, params)
{:ok,
  %{
    "result" => %{
      "tasks" => [
        %{"id" => 1, "title" => "test"},
        %{"id" => 2, "title" => "test2"}
      ]
    }
  }
}

Call method using a local or standard application

Examples

config :bitrix_ex,
  application_url: "https://mydomain.bitrix24.com/rest/",
  # or just "https://mydomain.bitrix24.com"

for this call the access token must be passed in the params

iex> access_token = "your_access_token"
iex> BitrixEx.call_method("tasks.task.list", %{auth: access_token})
{:ok, %{"result" => %{"tasks" => []}}}
Link to this function

call_method(method, params, opts)

View Source
@spec call_method(
  method :: String.t(),
  params :: map(),
  opts :: keyword()
) :: {:ok, map()} | {:error, any()}

Similar to the previous ones, but it has the additional parameter opts for using Tesla resources.

@spec client_id() :: binary()
@spec client_secret() :: binary()
@spec oauth_url() :: binary()
Link to this function

refresh_token(refresh_token, opts \\ [])

View Source
@spec refresh_token(
  refresh_token :: String.t(),
  opts :: keyword()
) :: {:ok, map()} | {:error, any()}

use refresh token to get a new access token

@spec webhook_url() :: binary()