Skip to content

Javascript

Tagging a User

This is a simple JavaScript example to update a user's first name in StreetHawk for a particular "cuid" so that you can provide real-time triggered campaigns based on these "tags".

// Data must be submitted as a list
var data = [{
              "sh_cuid": "exmaple@company.com",
              "key": "sh_first_name",
              "string": "Joe"
           }];

function tagUser (data) {
  var url = <API HOST>+"/v2/tags';
  var appKey = <APP KEY>;
  var authToken = <AUTH TOKEN>;
  var params = JSON.stringify(data);

  var xhr = new XMLHttpRequest();
  xhr.open('POST', url, true);
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xhr.setRequestHeader('Accept', 'application/json');
  xhr.setRequestHeader('X-App-Key', appKey);
  xhr.setRequestHeader('X-Auth-Token', authToken);
  xhr.send(params);

  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 &amp;amp;&amp;amp; xhr.status == 200) {
        var response = JSON.parse(xhr.responseText);
        console.log(response.value);
    } else {
        console.log(xhr.response);
    }
  }
}

tagUser(data);