Creating a Client (Individual) and Application from a Lead Automatically
Goal: create a lead, run a check on the lead, automatically create a client and application.
This business scenario should be used when you need to:
- quickly create a working example in the system?
- speed up your familiarization with the system?
- create an application that can be processed, approved, and then issue a loan as the next step?
Then this scenario is exactly what you need to use.
Expected result: a created application.
Upon successful verification, the client and application are created automatically.
In the interface, the result may look as follows:

The intake channel must have the "SPR" scheme selected, which is configured for manual verification only. "Basic Tariff" is selected as the loan product.


Business scenario description in BPMN: for this scenario, see numbers 1 and 2

To achieve the goal, you need to call 2 API methods.
1. Method Signature
General description of working with the core web service method is described in the article "API Usage Nuances" in the "Method" section.
POST /main/leadsPath parameters:
none
Request parameters:
none
Request body
The request body contains an object with the following structure:
| Element | Required | Data type | Description |
| firstName | M | string[50] | First name. If you pass the full name, it will be saved. In this case, problems may arise later if last name and patronymic are added. |
| mobilePhone | M | string[50] | Mobile phone number. Only digits in international format are specified 797762007777. The value of this field is added to the lead as +7 (977) 620 07 77. |
| lastName | M | string[50] | Last name. This field can also accept any string value up to 50 characters in length. However, this is not recommended. |
| birthDate | M | date | Date of birth in YYYY-MM-DD format |
| sexId | M | int[20] | Gender ID. See possible values [here](https://docs.brainysoft.ru/documentation/page/794). |
| passport | M | object | Passport |
| passport.issueDate | M | date | Passport issue date in YYYY-MM-DD format |
| passport.no | M | string[25] | Passport number |
| addressData | M | object | Residential address |
| registrationAddressData | M | object | Registration address |
| amount | M | float | Loan amount |
| managerId | M | int[20] | Loan specialist. The value for this field is taken from the "[Loan Specialists](http://docs.brainysoft.ru/documentation/page/79)" directory. If this field is not passed, the value is taken from the loan specialist who has the "Use for automatic client creation" checkbox enabled. Also note that when passing the "subdivisionId" field, the managerId field will be set to the loan specialist of that subdivision. For example, if we pass "subdivisionId":101798, then clientId will take the value 101091, the loan specialist of that subdivision. |
| subdivisionId | O | int[20] | [Subdivision identifier](http://docs.brainysoft.ru/page/223). See also the description of the "managerId" parameter. |
| period | M | [int][11] | Loan period. This field is conditionally required for the successful completion of this business scenario. |
Note: for the successful execution of method 1, only 2 properties need to be passed in the request body (firstName and mobilePhone).
All other properties marked as required or conditionally required are necessary for the successful execution of method 2.
Errors:
- NO_CLIENT_FIRST_NAME_ERROR - client first name not specified
- NO_MOBILE_PHONE_ERROR - phone number not specified
Request example:
POST /main/leads{
"firstName": "Фридрих",
"mobilePhone": "797762007719",
"lastName": "Эберт",
"birthDate": "1982-12-20",
"sexId": 101251,
"passport": {
"issueDate": "2012-01-23",
"no": "782573"
},
"addressData": {},
"registrationAddressData": {},
"amount": 99,
"subdivisionId": 101798,
"period": 30
}Result of method 1 call
General description of the returned object structure is described in the article "API Usage Nuances" in the "Method" section.
| Element | Description |
| data | Identifier of the created lead. |
Response example:
{
"status": "ok",
"timestamp": 1551033140167,
"data": 1400
}Code examples (method 1):
$requestBody = '{
"firstName": "Фридрих",
"mobilePhone": "797762007719",
"lastName": "Эберт",
"birthDate": "1982-12-20",
"sexId": 101251,
"passport": {
"issueDate": "2012-01-23",
"no": "782573"
},
"addressData": { },
"registrationAddressData": { },
"amount": 99,
"subdivisionId": 101798,
"period":30
}';
curl_setopt_array($curl_newLead, array(
CURLOPT_PORT => "9025",
CURLOPT_URL => "https://{customer}-saas.brainysoft.ru/bs-core/main/leads/",
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $requestBody
));2. Method Signature
General description of working with the core web service method is described in the article "API Usage Nuances" in the "Method" section.
POST /main/leads/{leadId}/checkPath parameters:
| Parameter | Required | Data type | Description |
| leadId | M | int | Identifier of the lead created by calling the method above. |
Request parameters:
none
Request body
none
Errors:
- NO_CLIENT_NAME_ERROR - client last name not specified
- NO_BIRTH_DATE_ERROR - date of birth not specified
- NO_SEX_ERROR - gender not specified
- NO_PASSPORT_ERROR - passport number not specified
- NO_PASSPORT_ISSUE_DATE_ERROR - passport issue date not specified
- NO_ADDRESS_ERROR - address not specified
- NO_REGISTRATION_ADDRESS_ERROR - registration address not specified
- NO_LOAN_AMOUNT_ERROR - loan amount not specified
- LOAN_AMOUNT_LESS_THAN_MIN_LOAN_AMOUNT_ERROR - The loan amount requested in the application must be greater than the minimum amount according to the loan product
- PERIOD_LESS_THAN_MIN_PERIOD_ERROR - The period specified in the application must be greater than the minimum period in the loan product.

Request example:
POST /main/leads/1400/checkResult of method 2 call
General description of the returned object structure is described in the article "API Usage Nuances" in the "Method" section.
| Element | Description |
| data | Empty string in valid JSON format. |
Response example:
{
"status": "ok",
"timestamp": 1462953747271,
"data": ""
}Code examples:
$leadId = //identifier of the lead created by method 1
curl_setopt_array($curl, array(
CURLOPT_PORT => "9025",
CURLOPT_URL => "https://{customer}-saas.brainysoft.ru/bs-core/main/leads/$leadId/check",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array (
"bsauth: $bsauth",
"cache-control: no-cache"
)
));PHP code example can be viewed and copied here.