Add a setting for recurring invoice crm.invoice.recurring.add

Scope: crm

Who can execute the method: any user

Warning

The method is deprecated. It is recommended to use Universal methods for invoices

The method adds a new setting for a recurring invoice.

Method parameters

Required parameters are marked with *

Name
type

Description

fields
array

Field values for creating a recurring invoice setting.
The required field is INVOICE_ID [ID of the invoice that has the parameter IS_RECURRING=Y].

To find out the required format of the fields, execute the method crm.invoice.recurring.fields and check the format of the returned values for these fields

Code examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"INVOICE_ID":"10","IS_LIMIT":"N","START_DATE":"'$(date -Iseconds --utc --date='TZ="Europe/Berlin" +1 month')'","PARAMS":{"PERIOD":"day","IS_WORKING_ONLY":"N","INTERVAL":30,"DATE_PAY_BEFORE_OFFSET_TYPE":"month","DATE_PAY_BEFORE_OFFSET_VALUE":1}}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/crm.invoice.recurring.add    
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"fields":{"INVOICE_ID":"10","IS_LIMIT":"N","START_DATE":"'$(date -Iseconds --utc --date='TZ="Europe/Berlin" +1 month')'","PARAMS":{"PERIOD":"day","IS_WORKING_ONLY":"N","INTERVAL":30,"DATE_PAY_BEFORE_OFFSET_TYPE":"month","DATE_PAY_BEFORE_OFFSET_VALUE":1}},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/crm.invoice.recurring.add
        
try
        {
        	const current = new Date();
        	const nextMonth = new Date();
        	nextMonth.setMonth(current.getMonth() + 1);
        
        	const date2str = function(d)
        	{
        		return d.getFullYear() + '-' + paddatepart(1 + d.getMonth()) + '-' + paddatepart(d.getDate()) + 'T' + paddatepart(d.getHours()) + ':' + paddatepart(d.getMinutes()) + ':' + paddatepart(d.getSeconds()) + '+02:00';
        	};
        
        	const paddatepart = function(part)
        	{
        		return part >= 10 ? part.toString() : '0' + part.toString();
        	};
        
        	const response = await $b24.callMethod(
        		"crm.invoice.recurring.add",
        		{
        			fields:
        			{
        				"INVOICE_ID": "10",
        				"IS_LIMIT": "N",
        				"START_DATE": date2str(nextMonth),
        				"PARAMS": {
        					"PERIOD": "day",
        					"IS_WORKING_ONLY": "N",
        					"INTERVAL": 30,
        					"DATE_PAY_BEFORE_OFFSET_TYPE": "month",
        					"DATE_PAY_BEFORE_OFFSET_VALUE": 1,
        				}
        			}
        		}
        	);
        
        	const result = response.getData().result;
        	if(result.error())
        		console.error(result.error());
        	else
        		console.info("Recurring invoice settings added. Record ID - " + result);
        }
        catch(error)
        {
        	console.error('Error:', error);
        }
        
try {
            $current = new DateTime();
            $nextMonth = new DateTime();
            $nextMonth->setDate($current->format('Y'), $current->format('m') + 1, $current->format('d'));
        
            $date2str = function($d) {
                return $d->format('Y-m-d\TH:i:sP');
            };
        
            $paddatepart = function($part) {
                return $part >= 10 ? $part : '0' . $part;
            };
        
            $response = $b24Service
                ->core
                ->call(
                    'crm.invoice.recurring.add',
                    [
                        'fields' => [
                            'INVOICE_ID'                 => '10',
                            'IS_LIMIT'                   => 'N',
                            'START_DATE'                 => $date2str($nextMonth),
                            'PARAMS' => [
                                'PERIOD'                     => 'day',
                                'IS_WORKING_ONLY'            => 'N',
                                'INTERVAL'                   => 30,
                                'DATE_PAY_BEFORE_OFFSET_TYPE' => 'month',
                                'DATE_PAY_BEFORE_OFFSET_VALUE' => 1,
                            ],
                        ],
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            if ($result->error()) {
                error_log($result->error());
                echo 'Error: ' . $result->error();
            } else {
                echo 'Success: Recurring invoice settings added. Record ID - ' . $result->data();
            }
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error adding recurring invoice settings: ' . $e->getMessage();
        }
        
var current = new Date();
        var nextMonth = new Date();
        nextMonth.setMonth(current.getMonth() + 1);
        var date2str = function(d)
        {
            return d.getFullYear() + '-' + paddatepart(1 + d.getMonth()) + '-' + paddatepart(d.getDate()) + 'T' + paddatepart(d.getHours()) + ':' + paddatepart(d.getMinutes()) + ':' + paddatepart(d.getSeconds()) + '+02:00';
        };
        var paddatepart = function(part)
        {
            return part >= 10 ? part.toString() : '0' + part.toString();
        };
        BX24.callMethod(
            "crm.invoice.recurring.add",
            {
                fields:
                {
                    "INVOICE_ID": "10",
                    "IS_LIMIT": "N",
                    "START_DATE": date2str(nextMonth),
                    "PARAMS": {
                        "PERIOD": "day",
                        "IS_WORKING_ONLY": "N",
                        "INTERVAL": 30,
                        "DATE_PAY_BEFORE_OFFSET_TYPE": "month",
                        "DATE_PAY_BEFORE_OFFSET_VALUE": 1,
                    }
                }
            },
            function(result)
            {
                if(result.error())
                    console.error(result.error());
                else
                    console.info("Recurring invoice settings added. Record ID - " + result.data());
            }
        );
        
require_once('crest.php');
        
        $current = new DateTime();
        $nextMonth = (new DateTime())->modify('+1 month');
        
        function date2str($d) {
            return $d->format('Y-m-d\TH:i:s+02:00');
        }
        
        $result = CRest::call(
            'crm.invoice.recurring.add',
            [
                'fields' => [
                    'INVOICE_ID' => 10,
                    'IS_LIMIT' => 'N',
                    'START_DATE' => date2str($nextMonth),
                    'PARAMS' => [
                        'PERIOD' => 'day',
                        'IS_WORKING_ONLY' => 'N',
                        'INTERVAL' => 30,
                        'DATE_PAY_BEFORE_OFFSET_TYPE' => 'month',
                        'DATE_PAY_BEFORE_OFFSET_VALUE' => 1,
                    ]
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';