How to create a custom field using BoldSign API?

Custom Fields help organize documents by allowing you to create and reuse fields tailored to your needs. These fields are used to store frequently used information, ensuring consistency across documents and reducing repetitive tasks.

Once created, a Custom Field is linked to your brand, making it easy to drag and drop into any document, quickly filling in details without manual entry.

To set up a custom field via the API, provide key details like fieldName, description, order, and formfield settings. To prevent team members from editing the Id of the custom field, specify the idPrefix and set restrictIdPrefixChange to true.

Below are examples of how to create a custom form field for Phone Number using TextBox field:

Code snippet

curl -X POST \
  'https://api.boldsign.com/v1/customField/create' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: {your api key}' \
  -H 'Content-Type: application/json' \
  -d '{
    "fieldName": "PhoneNumber",
    "fieldDescription": "Signer Contact details",
    "fieldOrder": 1,
    "brandId": "{your brand Id}",
    "sharedField": true,
    "formField": {
      "fieldType": "TextBox",
      "width": 60,
      "height": 40,
      "isRequired": true,
      "validationType": "NumbersOnly"
    }
  }'

var client = new HttpClient();
var apiClient = new ApiClient("https://api.boldsign.com", "API-KEY");

var customFieldClient = new CustomFieldClient(apiClient);

var newCustomField = new CreateCustomField()
{
    FieldName = "PhoneNumber",
    FieldDescription = "Signer Contact details",
    FieldOrder = 1,
    BrandId = "{your brandId}",
    SharedField = true,
    FormField = new FormField()
    {
        FieldType = "TextBox",
        Width = 60,
        Height = 40,
        IsRequired = true,
        ValidationType = "NumbersOnly"
    }
};

var response = await customFieldClient.CreateAsync(newCustomField);
Console.WriteLine(response);

import requests

url = "https://api.boldsign.com/v1/customField/create"
headers = {
    "Accept": "application/json;odata.metadata=minimal;odata.streaming=true",
    "X-API-KEY": "{your api key}",
    "Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true"
}
data = {
    "fieldName": "PhoneNumber",
    "fieldDescription": "Signer Contact details",
    "fieldOrder": 1,
    "brandId": "{your brand id}",
    "sharedField": True,
    "formField": {
        "fieldType": "TextBox",
        "width": 60,
        "height": 40,
        "isRequired": True,
        "validationType": "NumbersOnly"
    }
}

response = requests.post(url, headers=headers, json=data)

print(response.status_code)
print(response.json())  # or response.text if the response is not in JSON format

const axios = require('axios');

const url = 'https://api.boldsign.com/v1/customField/create';
const headers = {
  'Accept': 'application/json;odata.metadata=minimal;odata.streaming=true',
  'X-API-KEY': '{your api key}',
  'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
};

const data = {
  "fieldName": "PhoneNumber",
  "fieldDescription": "Signer Contact details",
  "fieldOrder": 1,
  "brandId": "{your brand id}",
  "sharedField": true,
  "formField": {
    "fieldType": "TextBox",
    "width": 60,
    "height": 40,
    "isRequired": true,
    "validationType": "NumbersOnly"
  }
};

axios.post(url, data, { headers })
  .then(response => {
    console.log('Status Code:', response.status);
    console.log('Response Data:', response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.data : error.message);
  });
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

$client = new Client();

$url = 'https://api.boldsign.com/v1/customField/create';
$headers = [
    'Accept' => 'application/json;odata.metadata=minimal;odata.streaming=true',
    'X-API-KEY' => '{your api key}',
    'Content-Type' => 'application/json;odata.metadata=minimal;odata.streaming=true'
];

$data = [
    "fieldName" => "PhoneNumber",
    "fieldDescription" => "Signer Contact details",
    "fieldOrder" => 1,
    "brandId" => "{your brand Id}",
    "sharedField" => true,
    "formField" => [
        "fieldType" => "TextBox",
        "width" => 60,
        "height" => 40,
        "isRequired" => true,
        "validationType" => "NumbersOnly"
    ]
];

try {
    $response = $client->request('POST', $url, [
        'headers' => $headers,
        'json' => $data
    ]);

    echo 'Status Code: ' . $response->getStatusCode() . "\n";
    echo 'Response Body: ' . $response->getBody() . "\n";
} catch (RequestException $e) {
    echo 'Error: ' . $e->getMessage() . "\n";
    if ($e->hasResponse()) {
        echo 'Response Body: ' . $e->getResponse()->getBody() . "\n";
    }
}

In the provided code example, replace values for fieldName with the custom name of the field you want to create, fieldOrder with the order of the field, brandId with the id of the brand the custom field is associated with and the fieldType with the original field that the custom field is being created from. Once the above codes are excuted, a custom field is created and saved successfully in the brand.