sailthru / sailthru-node-client

Sailthru Node.js client
http://docs.sailthru.com
MIT License
17 stars 15 forks source link

How should Date objects be sent for user vars? #20

Closed evantahler closed 9 years ago

evantahler commented 9 years ago

Consider the example:

var client = require('sailthru-client').createSailthruClient(this.config.apiKey, this.config.apiSecret);
var payload = {
    email: 'person@thing.com',
    keysconflict: 'merge',
    vars: {
       type: 'happy user',
       joined_date: new Date(1234567),
    },
    fields: {keys: 1, lists: 1},
  };

The joined_date is stringified currently, and not represented as a timestamp when uploaded to Sailthru, for example:

screen shot 2015-09-29 at 5 31 42 pm
robwil commented 9 years ago

Hi Evan,

As the Sailthru API is JSON based, there is no Date datatype and there is no way to create a Date type var via the API. However, there are conventions that will allow the var to be treated as a date for certain Query Builder criteria as well as Zephyr functions that operate based on dates/times. The best approach is to use a Unix timestamp passed as an integer type. If you have further questions about this, feel free to reach out to Sailthru Support as it's more a general usage question.

Rob

evantahler commented 9 years ago

Got it. I would then suggest that this API cast all Date() objects to integers.