Create global variable

Create global variable that lets you control content in multiple templates.


You can define a global variable that can be used as a snippet in multiple templates for email, sms, etc.

Then you can easily update it with one call, with no need to change every occurrence in template.

You can define either text or integer content, but only one of them (for example: "text_content": "January Promotions").

POST

/global-variables/

Data
Type
Description
name
string
The name of a global variable you want to create
integer_content
integer
Integer content you want to define
text_content
string
Text content you want to define
author
string
Unique ID of an agent
curl -X POST -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
  "name": "Some global variable"
  "text_content": "January Promotions"
  "author": 1
}' "https://<your_app_subdomain>.user.com/api/public/global-variables/"

Response

{
  "id": 3589,
  "name": "Some global variable",
  "name_std": "some_global_variable",
  "integer_content": "",
  "text_content": "January Promotions",
  "author": 1
  "created_at":"2020-01-24T09:00:15.800900Z",
  "updated_at":"2020-01-24T09:00:15.801042Z",
}
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://<your_app_subdomain>.user.com/api/public/global-variables/",
  "method": "POST",
  "headers": {
    "authorization": "Token <your_64_char_api_key>",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\n  \"name\": \"Some global variable\"\n \"text_conent\": \"January Promotions\"\n \"author\": \"1\"\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var data = JSON.stringify({
  "name": "Some global variable"
  "text_content": "January Promotions"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/global-variables/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");

xhr.send(data);
var request = require("request");

var options = { method: 'POST',
  url: 'https://<your_app_subdomain>.user.com/api/public/global-variables/',
  headers:
   { 'content-type': 'application/json',
     authorization: 'Token <your_64_char_api_key>' },
  body: { name: 'Some global variable', text_content: 'January Promotions' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/global-variables/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"name\": \"Some global variable\"\n \"text_content\": \"January Promotions\"\n}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Token <your_64_char_api_key>",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import requests

url = "https://<your_app_subdomain>.user.com/api/public/global-variables/"

payload = "{\n  \"name\": \"Some global variable\",\n \"text_content\": \"January Promotions\"\n}"
headers = {
    'authorization': "Token <your_64_char_api_key>",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
import requests

url = "https://<your_app_subdomain>.user.com/api/public/global-variables/"

payload = {
    "name": "Some global variable",
    "text_content": "January Promotions"
}

headers = {
    "authorization": "Token <your_64_char_api_key>",
    "content-type": "application/json"
}

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

print(response.json)