create_template
7 min
creates an email template in a project and stores its subject and html body a template goes under a category, so create template requires a cat id create the category first with create category , or reuse an existing one you can let the system generate the template id, or supply your own with template id (see section below on choosing a template id) the caller may only create templates in a project their account owns basic structure each call to the api requires action and a group id name type required description action string true for this call, create template group id integer true designates which project the template belongs to the api id in the header must be part of the organization that owns the group doc array true see doc parameters below doc parameters name type required description cat id string true the category id the template goes under (from create category ) name string true template name, shown in the app subject string true email subject line html string true the email body html template id string false a template id you choose if omitted, the system generates one example call curl x post "https //www regpack com/reg/api2/emails/" \\ h "content type application/json" \\ h "accept application/json" \\ h "api id 15263" \\ h "api user api admin\@regpacks com" \\ h "api token cd2e514f 7gab 3cde 62fg 51abcd4e7362" \\ d '{ "action" "create template", "group id" 100909072, "doc" { "cat id" "112481", "name" "welcome email", "subject" "welcome to the program", "html" "\<h1>welcome\</h1>\<p>we are glad you are here \</p>", "template id" "100909072 welcome" } }'import requests import json emails endpoint = "https //www regpack com/reg/api2/emails/" headers = { "content type" "application/json", "accept" "application/json", "api id" "15263", "api user" "api admin\@regpacks com", "api token" "cd2e514f 7gab 3cde 62fg 51abcd4e7362", } payload = { "action" "create template", "group id" 100909072, "doc" { "cat id" "112481", "name" "welcome email", "subject" "welcome to the program", "html" "\<h1>welcome\</h1>\<p>we are glad you are here \</p>", "template id" "100909072 welcome", }, } create template json = json dumps(payload) create template response = requests post(url=emails endpoint, data=create template json, headers=headers, timeout=10) example response the response returns the template's template id always reference this value going forward, even if it differs from the one you requested and existed, which is true only when no template id was supplied and a template with the same name already existed in the project (that existing template is returned unchanged) { "success" true, "template id" "100909072 welcome", "existed" false } choosing template id a template id is globally unique across all projects to make sure one project can never overwrite another project's template, a supplied template id is handled as follows your template id … result already exists in this same project the template is edited —its name, category, subject, and html are updated is not used by any project the template is created with exactly that id already exists in a different project your id is rejected to protect the other project the template is still created, but under a system generated id , and the response tells you (see below) omitted the system generates the id the call is idempotent by name sending the same name again returns the existing template response when the requested id was rejected { "success" true, "template id" "100909072 200145", "existed" false, "id rejected" true, "requested template id" "100909072 welcome", "warning" "requested template id '100909072 welcome' is already in use in another project; created with auto generated id '100909072 200145' instead " } field type meaning id rejected bool present and true when the requested id could not be used requested template id string the id you asked for warning string human readable explanation