Skip to content

Creating a Time Based Column Filter Using a REST API

You can convert Unix time columns to type timestamp by making a PUT API call to the /audiences/${PARENT_SEGMENT_ID} endpoint.

Prerequisites

  • Only columns that contain Unix time can be converted to timestamp. Unix time is stored as a 10-digit number (e.g. 1691244585). In the Treasure Console, these Unix time columns are usually of type long or string (??).
  • The API call requires a parent segment ID. Use the URL on the browser address bar to get the . For example: https://console.treasuredata.com/app/ps/${PARENT_SEGMENT_ID}/e/${SEGMENT_ID}/3/da
  • You will need to identify the appropriate Audience API for your region. See Treasure API baseURLs.
  • You will need to obtain an API key to authenticate the API call. See Getting Your API Keys.

Limitations

  • Treasure Data does not support "all columns" set to true in the Parent Segment’s behavior configuration. Instead, choose "columns".

REST API Calls

  1. Obtain the current parent segment configuration.
curl -X GET \  
https://<endpoint>/audiences/<parent segment id> \  
-H 'Authorization: TD1 <apikey>'  
  1. Save the contents from the response to a text editor, and replace the type of the column with "timestamp".

Example

In the following example, we've replaced the column type with "timestamp".

"scheduleOption": null,  
"defaultTimeFilterEnabled": true,  
"schema": [  
  {  
    "name": "unix_time_col",  
    "type": "timestamp",  
    "parentColumn": "unix_time_col",  
    "matrixColumnName": "unix_time_col"  
  },  
  {  
    "name": "unix_time_col",  
    "type": "string",  
    "parentColumn": "unix_time_col_2",  
    "matrixColumnName": "unix_time_col_2"  
  },  
]  
  1. Update your existing parent segment with the new definition.

Example

Pass the modified Json in step 2 with the -d parameter.

curl -X PUT \  
https://<endpoint>/audiences/<parent segment id> \  
-H 'Authorization: TD1 <apikey>' \  
-H 'Content-Type: application/json' \  
-d '{ updated json definition }'   
  1. Test your REST API calls. Create a segment by specifying the column you changed to a data type of timestamp.