Bitrix24 Community

Support » Forum » CRM » POST using REST API - Address Field
Pages: 1
POST using REST API - Address Field
Hi, I need assistance in correctly posting the address. I'm in the process of developing a lead distribution software to connect my call center dialer software to Bitrix24 to facilitate a hot voice and data transfer simultaneously but need help with the posting of the address field.

When I post to ADDRESS I can get the street name to post but ADDRESS_CITY doesn't post to the city.. what is the correct way to post to the sub-fields within the default ADDRESS field?

sample test code:
// CRM server conection data
define('CRM_HOST', ''); // your CRM domain name
define('CRM_PORT', '443'); // CRM server port
define('CRM_PATH', '/crm/configs/import/lead.php'); // CRM server REST service path

// CRM server authorization data
define('CRM_LOGIN', ''); // login of a CRM user able to manage leads
define('CRM_PASSWORD', 'password'); // password of a CRM user
// OR you can send special authorization hash which is sent by server after first successful connection with login and password
//define('CRM_AUTH', 'e54ec19f0c5f092ea11145b80f465e1a'); // authorization hash


// POST processing
   $leadData = $_POST['DATA'];

   // get lead data from the form
   $postData = array(
      'TITLE' => $leadData['TITLE'],
      'COMPANY_TITLE' => $leadData['COMPANY_TITLE'],
      'NAME' => $leadData['NAME'],
      'LAST_NAME' => $leadData['LAST_NAME'],
      'COMMENTS' => $leadData['COMMENTS'],
      'ASSIGNED_BY_ID' => $leadData['ASSIGNED_BY_ID'],
      'UF_CRM_1432884947' => $leadData['LOAN_AMOUNT'],
      'ADDRESS' => $leadData['ADDRESS'],
      'ADDRESS_CITY' => $leadData['ADDRESS_CITY'],

   // append authorization data
   if (defined('CRM_AUTH'))
      $postData['AUTH'] = CRM_AUTH;
      $postData['LOGIN'] = CRM_LOGIN;
      $postData['PASSWORD'] = CRM_PASSWORD;

   // open socket to CRM
   $fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30);
   if ($fp)
      // prepare POST data
      $strPostData = '';
      foreach ($postData as $key => $value)
         $strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value);

      // prepare POST headers
      $str = "POST ".CRM_PATH." HTTP/1.0\r\n";
      $str .= "Host: ".CRM_HOST."\r\n";
      $str .= "Content-Type: application/x-www-form-urlencoded\r\n";
      $str .= "Content-Length: ".strlen($strPostData)."\r\n";
      $str .= "Connection: close\r\n\r\n";

      $str .= $strPostData;

      // send POST to CRM
      fwrite($fp, $str);

      // get CRM headers
      $result = '';
      while (!feof($fp))
         $result .= fgets($fp, 128);

      // cut response headers
      $response = explode("\r\n\r\n", $result);

      $output = '<pre>'.print_r($response[1], 1).'</pre>';
      echo 'Connection Failed! '.$errstr.' ('.$errno.')';
   $output = '';

// HTML form
<ht ml>
<met a http-equiv="Content-Type" content="text/html; charset=utf-8">
<fo rm action="bitrixPostRest.php" method="POST">
   Title*: <input type="text" name="DATA[TITLE]" value="" /><br />
   Company Name: <input type="text" name="DATA[COMPANY_TITLE]" value="" /><br />
   First Name: <input type="text" name="DATA[NAME]" value="" /><br />
   Last Name: <input type="text" name="DATA[LAST_NAME]" value="" /><br />
   Comments: <textarea name="DATA[COMMENTS]"></textarea><br />
   Responsible: <input type="text" name="DATA[ASSIGNED_BY_ID]" value="" /><br />
   Loan Amount: <input type="text" name="DATA[LOAN_AMOUNT]" value="" /><br />
   Address: <input type="text" name="DATA[ADDRESS]" value="" /><br />
   City: <input type="text" name="DATA[ADDRESS_CITY]" value="" /><br />
   State: <input type="text" name="DATA[ADDRESS_PROVINCE]" value="" /><br />
   <input type="submit" value="Send" />
Hello Nathaniel,

This api doesn't support the latests updates related to division of the address field into several ones. I've passed this to the devs. We will fix the ussue, but I cannot say any time frame.
Sorry for the inconvenience.
Hey Ann Slyshkina,

Has there been any development in the API so it will accommodate for other Address fields?

John Tran
Hey there,
Please contact our helpdesk about this issue.
Kind regards,
Pages: 1
are already using Bitrix24