Add Currency crm.currency.add

Scope: crm

Who can execute the method: any user with access to modify CRM settings

This method adds a new currency.

For the languages used on the account, localization parameters must be specified. If not provided, default parameters will be used. Localization parameters for a specific language can be set using the crm.currency.localizations.set method.

Method Parameters

Required parameters are marked with *

Name
type

Description

fields*
object

Field values (detailed description provided below) for adding a new currency in the form of a structure:

fields: {
            CURRENCY: 'value',
            BASE: 'value',
            AMOUNT_CNT: 'value',
            AMOUNT: 'value'
            SORT: 'value'
            LANG: 'value'
        }
        

Parameter fields

Required parameters are marked with *

Name
type

Description

CURRENCY*
string

Currency identifier.

Corresponds to the ISO 4217 standard

BASE
string

Indicates whether the currency is base.

Possible values:

  • Y — yes
  • N — no

Default value is N.

Warning

It is not recommended to change the base currency via REST. Otherwise, it will be necessary to change the rates of all currencies.

AMOUNT_CNT*
int

Denomination. Typically, 1 or a multiple of 10 is used as the denomination.

AMOUNT*
double

Exchange rate relative to the base currency.

SORT
int

Position in the currency list.

Default value is 100.

LANG
object

Currency localization parameters.

An object in the format {"lang_1": "value_1", ... "lang_N": "value_N"}, where lang_N is the language identifier, and value is an object of type crm_currency_localization.

If not all languages are specified, default localization parameters will be used for the remaining ones.

Parameter LANG

Name
type

Description

DECIMALS*
int

Number of decimal places in the fractional part.

DEC_POINT
string

Decimal point for output.

FORMAT_STRING
string

Format template.

FULL_NAME
string

Name of the currency in the language for which localization is added.

HIDE_ZERO
string

Indicates whether to hide insignificant zeros.

THOUSANDS_SEP
string

Thousands separator.

THOUSANDS_VARIANT
string

Code for the thousands separator.

Allowed values are described in the reference.

Code Examples

  1. Creating the yuan with localization parameters (Russian and English languages)

    The base currency is the ruble. The exchange rate for the yuan is 12.2251 rubles for 1 yuan.

    How to Use Examples in Documentation

    curl -X POST \
            -H "Content-Type: application/json" \
            -H "Accept: application/json" \
            -d '{"fields":{"CURRENCY":"CNY","BASE":"N","AMOUNT":12.2251,"AMOUNT_CNT":1,"SORT":9000,"LANG":{"ru":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"# CNY","FULL_NAME":"yuan","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"S"},"en":{"DECIMALS":2,"DEC_POINT":",","FORMAT_STRING":"# CNY","FULL_NAME":"yuan","HIDE_ZERO":"Y","THOUSANDS_SEP":"."}}}}' \
            https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.currency.add
            
    curl -X POST \
            -H "Content-Type: application/json" \
            -H "Accept: application/json" \
            -d '{"fields":{"CURRENCY":"CNY","BASE":"N","AMOUNT":12.2251,"AMOUNT_CNT":1,"SORT":9000,"LANG":{"ru":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"# CNY","FULL_NAME":"yuan","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"S"},"en":{"DECIMALS":2,"DEC_POINT":",","FORMAT_STRING":"# CNY","FULL_NAME":"yuan","HIDE_ZERO":"Y","THOUSANDS_SEP":"."}}},"auth":"**put_access_token_here**"}' \
            https://**put_your_bitrix24_address**/rest/crm.currency.add
            
    BX24.callMethod(
                "crm.currency.add",
                {
                    fields: {
                        CURRENCY: 'CNY',
                        BASE: 'N',
                        AMOUNT: 12.2251,
                        AMOUNT_CNT: 1,
                        SORT: 9000,
                        LANG: {
                            ru: {
                                DECIMALS: 2,
                                DEC_POINT: '.',
                                FORMAT_STRING: '# CNY',
                                FULL_NAME: 'yuan',
                                HIDE_ZERO: 'Y',
                                THOUSANDS_VARIANT: 'S',
                            },
                            en: {
                                DECIMALS: 2,
                                DEC_POINT: ',',
                                FORMAT_STRING: '# CNY',
                                FULL_NAME: 'yuan',
                                HIDE_ZERO: 'Y',
                                THOUSANDS_SEP: '.',
                            },
                        },
                    }
                },
            )
            .then(
                function(result)
                {
                    if (result.error())
                    {
                        console.error(result.error());
                    }
                    else
                    {
                        console.log(result);
                    }
                },
                function(error)
                {
                    console.info(error);
                }
            ); 
            
    require_once('crest.php');
            
            $result = CRest::call(
                'crm.currency.add',
                [
                    'fields' => [
                        'CURRENCY' => 'CNY',
                        'BASE' => 'N',
                        'AMOUNT' => 12.2251,
                        'AMOUNT_CNT' => 1,
                        'SORT' => 9000,
                        'LANG' => [
                            'ru' => [
                                'DECIMALS' => 2,
                                'DEC_POINT' => '.',
                                'FORMAT_STRING' => '# CNY',
                                'FULL_NAME' => 'yuan',
                                'HIDE_ZERO' => 'Y',
                                'THOUSANDS_VARIANT' => 'S',
                            ],
                            'en' => [
                                'DECIMALS' => 2,
                                'DEC_POINT' => ',',
                                'FORMAT_STRING' => '# CNY',
                                'FULL_NAME' => 'yuan',
                                'HIDE_ZERO' => 'Y',
                                'THOUSANDS_SEP' => '.',
                            ],
                        ],
                    ]
                ]
            );
            
            echo '<PRE>';
            print_r($result);
            echo '</PRE>';
            
  2. Creating the Indonesian rupiah

    Assuming the base currency is the ruble. The currency has a very low exchange rate — 1 rupiah is equivalent to 0.00548 rubles. In this case, we increase the denomination (AMOUNT_CNT) to set the rate with the required precision.

    How to Use Examples in Documentation

    curl -X POST \
            -H "Content-Type: application/json" \
            -H "Accept: application/json" \
            -d '{"fields":{"CURRENCY":"IDR","AMOUNT":54.8738,"AMOUNT_CNT":10000,"SORT":8000,"LANG":{"ru":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"Rp#","FULL_NAME":"rupiah","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"C"},"en":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"# CNY","FULL_NAME":"rupee","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"C"}}}}' \
            https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.currency.add
            
    curl -X POST \
            -H "Content-Type: application/json" \
            -H "Accept: application/json" \
            -d '{"fields":{"CURRENCY":"IDR","AMOUNT":54.8738,"AMOUNT_CNT":10000,"SORT":8000,"LANG":{"ru":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"Rp#","FULL_NAME":"rupiah","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"C"},"en":{"DECIMALS":2,"DEC_POINT":".","FORMAT_STRING":"# CNY","FULL_NAME":"rupee","HIDE_ZERO":"Y","THOUSANDS_VARIANT":"C"}}},"auth":"**put_access_token_here**"}' \
            https://**put_your_bitrix24_address**/rest/crm.currency.add
            
    BX24.callMethod(
                "crm.currency.add",
                {
                    fields: {
                        CURRENCY: 'IDR',
                        AMOUNT: 54.8738,
                        AMOUNT_CNT: 10000,
                        SORT: 8000,
                        LANG: {
                            ru: {
                                DECIMALS: 2,
                                DEC_POINT: '.',
                                FORMAT_STRING: 'Rp#',
                                FULL_NAME: 'rupiah',
                                HIDE_ZERO: 'Y',
                                THOUSANDS_VARIANT: 'C'
                            },
                            en: {
                                DECIMALS: 2,
                                DEC_POINT: '.',
                                FORMAT_STRING: '# CNY',
                                FULL_NAME: 'rupee',
                                HIDE_ZERO: 'Y',
                                THOUSANDS_VARIANT: 'C'
                            }
                        }
                    }
                },
            )
            .then(
                function(result)
                {
                    if (result.error())
                    {
                        console.error(result.error());
                    }
                    else
                    {
                        console.log(result);
                    }
                },
                function(error)
                {
                    console.info(error);
                }
            );
            
    require_once('crest.php');
            
            $result = CRest::call(
                'crm.currency.add',
                [
                    'fields' => [
                        'CURRENCY' => 'IDR',
                        'AMOUNT' => 54.8738,
                        'AMOUNT_CNT' => 10000,
                        'SORT' => 8000,
                        'LANG' => [
                            'ru' => [
                                'DECIMALS' => 2,
                                'DEC_POINT' => '.',
                                'FORMAT_STRING' => 'Rp#',
                                'FULL_NAME' => 'rupiah',
                                'HIDE_ZERO' => 'Y',
                                'THOUSANDS_VARIANT' => 'C',
                            ],
                            'en' => [
                                'DECIMALS' => 2,
                                'DEC_POINT' => '.',
                                'FORMAT_STRING' => '# CNY',
                                'FULL_NAME' => 'rupee',
                                'HIDE_ZERO' => 'Y',
                                'THOUSANDS_VARIANT' => 'C',
                            ]
                        ]
                    ]
                ]
            );
            
            echo '<PRE>';
            print_r($result);
            echo '</PRE>';
            

Response Handling

HTTP status: 200

{
            "result": "CNY",
            "time": {
                "start": 1717684463.467685,
                "finish": 1717684465.282238,
                "duration": 1.8145530223846436,
                "processing": 0.12580394744873047,
                "date_start": "2024-06-06T16:34:23+02:00",
                "date_finish": "2024-06-06T16:34:25+02:00",
                "operating": 0
            }
        }
        

Returned Data

Name
type

Description

result
crm_currency.CURRENCY

Identifier of the created currency.

time
time

Information about the request execution time.

Error Handling

HTTP status: 400

{
        	"error": "",
        	"error_description": "Access denied."
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
error_description

Textual description of the error. The description is not intended to be shown to the end user in its raw form

Possible Error Codes

Code

Description

Value

Empty string

Access denied.

Insufficient access rights.

Empty string

The "Currency" module is not found! Please install the "Currency" module.

ERROR_CORE

Undefined array key "#FIELD#"

Required field #FIELD# is not specified (the missing field code will be substituted instead of #FIELD#)

ERROR_CORE

Other errors in the data for creating the currency.

Statuses and System Error Codes

HTTP Status: 20x, 40x, 50x

The errors described below may occur when calling any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users

500

PORTAL_DELETED
Portal was deleted

The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site

Continue Learning