Template API

You may use the template API to get, create, update and test templates. You'll need to use the Users API Key to authenticate your API requests. Account admins can can get this key from the Account Overview page.

You can try out the code examples below by replacing <USERS_API_KEY> with your own Users API Key and <TEMPLATE_UUID>with the uuid of the template.

The template uuids can be found by querying the Index, or from the URL bar when viewing a template in the blueshift dashboard.

https://app.getblueshift.com/dashboard#/email_template_studio/<TEMPLATE_UUID>/edit/info

*The Template API is currently available only for email templates and push templates and can modify the namesubject and content of an email template.

 

Email Templates

Index

Returns a JSON representation of your templates.

  • cURL
curl -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/email_templates.json

Sample response:

  • JSON
 {
"templates": [{
"name": "my template",
"created_at": "2016-06-07T22:27:56.000Z",
"updated_at": "2016-06-14T00:53:04.000Z",
"uuid": "1da9e1e8-feae-4ec3-be0a-7dba528590bb",
"author": "Bertram Gilfoyle",
"resource": {
"updated_at": "2016-06-14T00:53:04.000Z"
}
}, {
"name": "my other template",
"created_at": "2016-06-08T22:14:56.000Z",
"updated_at": "2016-06-11T00:23:08.000Z",
"uuid": "8ab4a1c0-435b-4137-912e-c5cx445fa5cf",
"author": "Dinesh Chugtai",
"resource": {
"updated_at": "2016-06-14T00:53:04.000Z"
}
}]
}
 

Get

Returns a JSON representation of your template along with a list of campaigns using the template.

  • cURL
curl -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/email_templates/<TEMPLATE_UUID>.json

Sample response:

  • JSON
{
  "name": "my template",
  "created_at": "2016-06-07T22:27:56.000Z",
  "updated_at": "2016-06-14T00:53:04.000Z",
  "uuid": "1da9e1e8-feae-4ec3-be0a-7dba528590bb",
  "author": "Bertram Gilfoyle",
  "resource": {
    "subject": "hello",
    "content": "<!DOCTYPE html>\n<html>\n<body>\n<a href=\"https://www.getblueshift.com\">Hello world</a>\n</body>\n</html>"
  },
  "campaigns": [
    {
      "name": "my campaign",
      "uuid": "f63ebf4f-160b-42d8-b482-cbe0fc7de6b7",
      "status": "draft"
    },
    {
      "name": "my other campaign",
      "uuid": "ab67f1a7-efbb-46cd-8e9d-9a823e77bf1c",
      "status": "launched"
    }
  ]
}
 

Update

Updates the template and responds back with JSON of the template you just updated.

The following update request would modify the subject and content of an existing template.

  • cURL
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X PUT -d '{
  "resource": {
    "subject": "Hey there {{user.firstname}}",
    "content": "<!DOCTYPE html>\n<html>\n<body>\n<a href=\"https://www.getblueshift.com\">Hello world</a>\n</body>\n</html>"
  }
}' -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/email_templates/<TEMPLATE_UUID>.json

 

Escaping for JSON

Be sure to format your subject and content as a quoted string literal.

  • Incorrect: <a href="https://www.getblueshift.com">
  • Correct: <a href=\"https://www.getblueshift.com\">

Failure to properly escape your content will result in malformed JSON, resulting in either a request error or mangled content. You can paste your HTML into this online tool to see an example of how it should look.

 
 

Create

Creates a new template and responds back with JSON of the new template.

  • cURL
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{ 
"name": "My API Template",
"resource": { "subject": "Hey there {{user.firstname}}",
"content": "<!DOCTYPE html>\n<html>\n<body>\n<a href=\"https://www.getblueshift.com\">Hello world, now we're cookin!</a>\n</body>\n</html>"
"template_properties":{}
}' -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/email_templates.json
 

Test Send

Sends a test mail to a specific email address, using the personalization context for a given user. The following request will send a test mail to me@example.com

  • cURL
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{
  "id": "<TEMPLATE_UUID>",
  "personalize_for": "testuser@getblueshift.com",
  "recipients": ["me@example.com"]
}' -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/email_templates/test_send.json

Test send returns a status message to indicate a successful request.

  • JSON
{
  "status": "ok"
}
 

 

Push Templates

Index

Returns a JSON representation of your push templates.

  • cURL
curl -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/push_templates.json

Sample response:

  • JSON
 {
"templates": [{
"name": "my template",
"created_at": "2016-06-07T22:27:56.000Z",
"updated_at": "2016-06-14T00:53:04.000Z",
"uuid": "1da9e1e8-feae-4ec3-be0a-7dba528590bb",
"author": "Bertram Gilfoyle",
"resource": {
"updated_at": "2016-06-14T00:53:04.000Z"
}
}, {
"name": "my other template",
"created_at": "2016-06-08T22:14:56.000Z",
"updated_at": "2016-06-11T00:23:08.000Z",
"uuid": "8ab4a1c0-435b-4137-912e-c5cx445fa5cf",
"author": "Dinesh Chugtai",
"resource": {
"updated_at": "2016-06-14T00:53:04.000Z"
}
}]
}
 

Create

Creates a new push template and responds back with JSON of the new template

  • cURL
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '
{
"push_template": {
"name": "My Push Template",
"message_type": "json",
"device_type": "both",
"context": null,
"content": "{\"GCM\":{\"notification\":{\"title\":\"Notification Content\"}},\"APNS\":{\"aps\":{\"alert\":\"Hello world, now we're cookin!\"}}}",
"notification_type": "{\"apple\":\"plainPushNotification\",\"android\":\"plainPushNotification\"}"
},
"template_property": {
"name": "products",
"algorithm": "recommend_default",
"use_plasma": false,
"context": {},
"settings": {},
"skip_user_on_blank_products": true,
"skip_user_on_blank_event_products": true
}
}
' -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/push_templates.json
 

Test Send

Sends a test push to a user w/ a given email address.

  • cURL
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '
{
"uuid": "<PUSH TEMPLATE UUID>",
"email": <EMAIL ADDRESS FOR TEST PUSH>,
}
' -u <USERS_API_KEY>: https://api.getblueshift.com/api/v1/push_templates/test_push.json
 
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request