addFields

The addFields function allows you to add new fields and field data.

Overview

Warning: Do not use fields to store particularly sensitive or private information about your contacts or information requiring stronger controls than provided by the application. Information such as credit card numbers, social security numbers, unencrypted passwords, and other similar data should be stored outside of the application in a system specifically designed for handling this type of data. You are responsible for any consequences of processing any data placed in the application inappropriately.

Any field data you use in a message must be smaller than 1 MB.

Syntax

writeResult = bApi.addFields(fieldObject[] fields, 'isVisibleInContactList' = 'false');

Field Objects

Name Type Required Description
name string Yes The internal name of the field.
label string Yes The external (public facing) name of the field.
type string Yes The type of field:
  • text – Text box (max character limit: 65535)
  • textarea – A large multi-line text box (max character limit: 65535)
  • password – A text box that hides typed characters (max character limit: 65535)
  • checkbox – Check boxes (max character limit: 1)
  • radio – Radio buttons
  • select – Pull-down menu
  • integer – Accepts any 10 digit whole number less than or equal to 2147483647. If you need to store a static number (a number that is not incrementing or decrementing), we suggest using either a predefined field, or a custom field with a type of Text.
  • currency – Accepts any positive or negative number with two decimal points (max character limit: 15)
  • float – Accepts any positive or negative number with a decimal point (max character limit: 53)
  • date – A value that matches a specific date. See SOAP Data Formats for more information on the date format.
visibility string No; default is public The visibility selected for the field {public, private}. Public fields are visible to you and can be made visible to your contacts. Private fields are visible only to you.
options FieldOptionObject[] Not unless the type requires it The possible options that can be set for a field if the field is a pull-down, check box, or radio button.
isVisibleInContactList boolean No When isVisibleInContactList is true, the field will be displayed in the contact list grid as a separate column and will be available when creating a webform. If you send a null value, the field value will default to false.

PHP Code Example

<?php
/**
 * This script will add add fields to an account.
 *
 * @copyright  Copyright (c) 2018 Bronto Software (http://www.bronto.com)
 */
$client = new SoapClient('https://api.bronto.com/v4?wsdl', array(
    'trace' => 1,
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS
));
try {
    // Add your API token
    $token = "YOUR API KEY";
    print "logging in\n";
    $sessionId      = $client->login(array(
        'apiToken' => $token
    ))->return;
    $session_header = new SoapHeader("http://api.bronto.com/v4", 'sessionHeader', array(
        'sessionId' => $sessionId
    ));
    $client->__setSoapHeaders(array(
        $session_header
    ));
    // Adding a text field
    // Uncomment and comment out select $fieldObject to use
    // $fieldObject = array('name' => 'MY TEXT FIELD',
    //              "label" => 'MY FIELD TEXT LABEL',
    //              "type" => "text"
    //           );
    $optionGreen = array(
        'value' => 'green',
        "label" => "Green",
        'isDefault' => false
    );
    $optionBlue  = array(
        'value' => 'blue',
        "label" => "Blue",
        'isDefault' => false
    );
    $optionRed   = array(
        'value' => 'red',
        "label" => "Red",
        'isDefault' => true
    );
    //Adding a select option. The values are passed in the options array
    $fieldObject = array(
        'name' => 'MY SELECT FIELD',
        "label" => 'MY FIELD SELECT LABEL',
        "type" => "select",
        "options" => array(
            $optionGreen,
            $optionBlue,
            $optionRed
        )
    );
    print "Adding the field\n";
    $write_result = $client->addFields(array(
        'fields' => $fieldObject, 'isVisibleInContactList' => false
        ))->return;
    if (isset($write_result->errors)) {
        print "There was a problem adding the field:\n";
        print_r($write_result->results);
    } else {
        print "The field has been added.  Id: " . $write_result->results[0]->id . "\n";
    }
}
catch (Exception $e) {
    print "uncaught exception\n";
    print_r($e);
}
?>