Skip to content

Instantly share code, notes, and snippets.

@taf2
Created July 12, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taf2/84d157d679702ffdf5fb27e94c47878b to your computer and use it in GitHub Desktop.
Save taf2/84d157d679702ffdf5fb27e94c47878b to your computer and use it in GitHub Desktop.
#!/bin/bash
# using ctm forms api to manage creation, updates and destruction of forms
# as well as submitting data to the forms
# external to this script you should
# export CTM_API_KEY, CTM_API_SECRET and CTM_ENDPOINT you can get them from either /accounts/edit or /agencies/{id}/edit pages
# export CTM_ACCOUNT_ID=your account id
# form options include:
<< 'fields-avialable'
header_text
header2_text
header3_text
header4_text
header5_text
completion_text
error_text
custom_style
redirect_url
footer_text
name
description
fade_in
default_country_code
rate_limit
dynamic_sources
upsert_id
present_agent
lambda_inbound_email_parser_id
lambda_parser_id
label_placement
size
style
theme
name_required
email_required
use_select2
label_alignment
name_half_width
phone_half_width
phone_validation
email_half_width
required_placement
live_validate
custom_fields - array of fields
fields-avialable
# create a basic form
#curl -u$CTM_API_KEY:$CTM_API_SECRET \
#-H'Content-Type:application/json' \
#-XPOST $CTM_ENDPOINT/api/v1/accounts/${CTM_ACCOUNT_ID}/form_reactors \
#-d '{"name":"your form", "default_country_code": "1", "virtual_phone_number_id": "TPNC3C4B23C348AEC2EE54EFD301979CD2EFF048D7517B267A4452D1AB012CA5989"}'
<< 'response-body'
{
"form_reactor": {
"id": "FRT472ABB2C5B9B141AD0BD7258C47CE05F20144851A03D015F",
"name": "your form",
"description": null,
"account_id": 18614,
"custom_fields": [
],
"default_country_code": "1",
"include_email": true,
"include_name": true,
"include_country_code": true,
"log_form_entry_only": false,
"present_agent": false,
"call_lead_first": false,
"prompt_delay": 1,
"prompt_message": null,
"fade_in": false,
"rate_limit": 30,
"redirect_url": "",
"redirect_to_url": false,
"receiving_number": null,
"tracking_number": {
"number": "+1dddddddddd",
"id": "TPNC3C4B23C348AEC2EE54EFD301979CD2EFF048D7517B267A4452D1AB012CA5989"
},
"dynamic_sources": false,
"header_text": "",
"header2_text": "",
"header3_text": "",
"header4_text": "",
"header5_text": "",
"send_follow_up_text_message": false,
"delay_time": 10,
"delay_time_unit": "minutes",
"text_message": null,
"managed_mode": null,
"managed_id": null,
"chat_routing_rules": [
],
"footer_text": "",
"style": null,
"size": "normal",
"theme": null,
"label_placement": null,
"label_alignment": "left",
"required_placement": "right",
"custom_style": "",
"completion_text": "",
"error_text": "[&#128222; +1dddddddddd](tel:+1dddddddddd)",
"route_action_label": nulld
"route_action_type": null,
"prompt_key_press": "1",
"after_hours_action_type": "number_id",
"agent_status": null,
"after_hours_number_id": null,
"geo_router_field_name": "zipcode",
"upsert_id": null,
"route_action_id": 0,
"delay_calling_by": 0,
"connect_with_conference": false,
"name_required": true,
"name_half_width": false,
"phone_half_width": false,
"phone_validation": false,
"email_required": true,
"email_half_width": false,
"live_validate": false,
"use_select2": true,
"dial_with_caller_number": false
}
}
response-body
# you'll want to set this to the id returned from above
form_id=FRT472ABB2C5B9B141AD0BD7258C47CE05F20144851A03D015F
# now let's add some custom fields to our newly created form
curl -u$CTM_API_KEY:$CTM_API_SECRET \
-H'Content-Type:application/json' \
-XPATCH $CTM_ENDPOINT/api/v1/accounts/${CTM_ACCOUNT_ID}/form_reactors/${form_id} \
-d '{"custom_fields": [{"name":"zip_code","label":"zip code","type":"text","autoname":true,"half_width":false,"required":true,"save_to_custom":""}], "name":"your form", "default_country_code": "1", "virtual_phone_number_id": "TPNC3C4B23C348AEC2EE54EFD301979CD2EFF048D7517B267A4452D1AB012CA5989"}'
<< 'response-body'
..
"custom_fields": [
{
"name": "zip_code",
"label": "zip code",
"type": "text",
"autoname": true,
"half_width": false,
"required": true,
"save_to_custom": ""
}
],
...
response-body
# you can use DELETE to destroy the form and GET to get the form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment