Articles in this section
Category / Section

How to add line breaks to the textbox form field when using templates via API?

Published:
5 mins read

When working with a textbox form field that contains a large amount of text, you can add line breaks to separate paragraphs using the newline (\n) character. This ensures better formatting and readability in the final document.

How to Insert Line Breaks

To add line breaks:

  1. Use your created template in BoldSign to pre-fill form field values via the API. Refer to this guide to Send document from template by filling existing fields.
  2. Add the newline (\n) character within the field value. You can adjust the number of (\n) characters depending on the spacing you need between paragraphs.

Here’s an example code snippet demonstrating how to insert line breaks into a textbox form field using the BoldSign API:

Example Code Snippet

cURL

curl -X 'POST' \
'https://api.boldsign.com/v1/template/send?templateId=4357f511-xxxx-xxxx-6535-9a43be83cffc' \
-H 'accept: application/json' \
-H 'X-API-KEY: {Your API Key}' \
-H 'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true' \
-d '{
   "title": "Sample document",
   "message": "Kindly review and sign this.",
   "roles": [
      {
         "roleIndex": 1,
         "signerName": "Richard",
         "signerEmail": "richards@cubeflakes.com",
         "signerType": "Signer",
         "signerRole": "Employee",
         "locale": "EN",
         "existingFormFields": [
            {
               "id": "TextBox1",
               "value": "This is the first paragraph. \nThis is the second paragraph. \nThis is the third paragraph."
            }
         ]
      }
   ]
}'

C#

var apiClient =
                new ApiClient("https://api.boldsign.com",
                    "Your API Key"); 
            var templateClient = new TemplateClient(apiClient);

            var existingFormFieldCollectionsSigner1 = new List<ExistingFormField>
            {
                new ExistingFormField
                {
                    Id = "TextBox1",
                    Value = "This is the first paragraph.\nThis is the second paragraph.\nThis is the third paragraph."
                }
            };

            var templateRoleSigner1 = new Roles(
                roleSignerName: "Richard",
                roleSignerEmailAddress: "richard@cubeflakes.com",
                roleSignerIndex: 1,
                signerType: SignerType.Signer,
                signerRole: "Employee",
                existingFormFields: existingFormFieldCollectionsSigner1,
                locale: Locales.EN
            );

            var roles = new List<Roles> { templateRoleSigner1 };

            var sendForSignFromTemplate = new SendForSignFromTemplate()
            {
                TemplateId = "2f29bb2b-b9d8-8420-8a94-5d1372106fab",
                Roles = roles
            };

            try
            {
                var documentCreated = templateClient.SendUsingTemplate(sendForSignFromTemplate);
                Console.WriteLine($"Document Created Successfully: {documentCreated.DocumentId}");
            }
            catch (BoldSign.Api.ApiException ex)
            {
                Console.WriteLine($"API Error: {ex.Message}");
                Console.WriteLine(
                    $"Response Content: {ex.Message}"); 
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unexpected Error: {ex.Message}");
            }
        }
    }
}

Python


import boldsign
configuration = boldsign.Configuration(api_key="Your API Key")

with boldsign.ApiClient(configuration) as api_client:
    template_api = boldsign.TemplateApi(api_client)

    existing_form_fields = [
        boldsign.ExistingFormField(
            id="TextBox1",  
            value="This is the first paragraph.\n\nThis is the second paragraph.\n\nThis is the third paragraph."
        )
    ]
    roles = [
        boldsign.Role(
            role_index=1,
            signer_name="David",
            signer_email="david@cubeflakes.com",
            signer_order=1,
            signer_type="Signer",
            role="Admin",
            existing_form_fields=existing_form_fields   
        )
    ]
    send_for_sign_from_template = boldsign.SendForSignFromTemplateForm(
        roles=roles,
        enable_signing_order=True
    )

    send_using_template_response = template_api.send_using_template(
        template_id="2f29bb2b-b9d8-4420-9a94-5d1372106fab",
        send_for_sign_from_template_form=send_for_sign_from_template
    )

    print(send_using_template_response) 


Node.js

const axios = require('axios');

async function sendDocumentForSigning() {
    try {
        const response = await axios.post(
            'https://api.boldsign.com/v1/template/send?templateId=3357f511-xxxx-xxxx-5735-9a43be83cffc',
            {
                title: "Simple document",
                message: "Kindly review and sign this.",
                roles: [
                    {
                        roleIndex: 1,
                        signerName: "Richard",
                        signerEmail: "richard@cubeflakes.com",
                        signerType: "Signer",
                        signerRole: "Manager",
                        locale: "EN",
                        existingFormFields: [
                            {
                                id: "TextBox1",
                                value: "This is the first paragraph.\n\nThis is the second paragraph.\n\nThis is the third paragraph." 
                            }
                        ]
                    }
                ]
            },
            {
                headers: {
                    'accept': 'application/json',
                    'X-API-KEY': '{Your API Key}', 
                    'Content-Type': 'application/json;odata.metadata=minimal;odata.streaming=true'
                }
            }
        );

        console.log("Response:", JSON.stringify(response.data, null, 2));
        return response.data;
    } catch (error) {
        console.error('Error:', error.response ? error.response.data : error.message);
        throw error;
    }
}

sendDocumentForSigning();

After executing the above code, when signers open the document, the textbox field displays the text with properly separated paragraphs and spacing based on the specified line breaks.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied