Okay, I'm not getting this one right off so we'll see if I'm missing the obvious.
Given the request
curl "https://api.me.com/v1/visitors" --data "visitor=%7B%0A++%22funnels%22%3A+%7B%7D%2C%0A++%22_partition%22%3A+96%2C%0A++%22metric_sets%22%3A+%7B%0A++++%2234%22%3A+%7B%0A++++++%22safari%22%3A+1%0A++++%7D%0A++%7D%2C%0A++%22flags%22%3A+%7B%0A++++%22Book+Pack+Purchaser%22%3A+false%2C%0A++++%22Boat+PP+Viewer%22%3A+true%2C%0A++++%22Boat+Purchaser%22%3A+false%2C%0A++++%22Mobile+Shopper%22%3A+true%2C%0A++++%22Visitor+Buy%22%3A+false%2C%0A++++%22Testing%22%3A+true%2C%0A++++%22Book+Pack+PP+Viewer%22%3A+false%2C%0A++++%22Women%27s+Dept+Visitors%22%3A+true%2C%0A++++%22Boat+Abandoner%22%3A+false%0A++%7D%2C%0A++%22replaces%22%3A+%5B%5D%2C%0A++%22shard_token%22%3A+21000096%0A%7D"
You'll notice that the --data passed is a JSON object that has been encoded.
{"not":"my design"}
You could go here to encode it: http://www.url-encode-decode.com/ basically it turns into:
{
"funnels": {},
"_partition": 96,
"metric_sets": {
"34": {
"safari": 1
}
},
"flags": {
"Book Purchaser": false,
"Boat PP Viewer": true,
"Boat Purchaser": false,
"Mobile Shopper": true,
"Visitor Buy": false,
"Testing": true,
"Book Pack PP Viewer": false,
"Women's Dept Visitors": true,
"Boat Abandoner": false
},
"replaces": [],
"shard_token": 21000096
}
Well I can't figure out how to get the value into a JSON object in a Script so I can start mashing up the data. I got a...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Script-ProcessRequestVars">
<DisplayName>Script-ProcessRequestVars</DisplayName>
<FaultRules/>
<Properties/>
<ResourceURL>jsc://Script-ProcessRequestVars.js</ResourceURL>
</Javascript>
With a...
var processRequestPayload = function(){
context.setVariable("my.requestVerb",context.proxyRequest.method);
context.setVariable("my.visitor",context.proxyRequest.body.asForm['visitor'][0]);
var visitObj = JSON.parse(context.proxyRequest.body.asForm['visitor'][0]);
var shard = visitObj.shard_token;
};
function init() {
processRequestPayload();
}
init();
But all I get is a...
{
"fault": {
"faultstring": "Execution of Script-ProcessRequestVars failed on line 4 with error: 1",
"detail": {
"errorcode": "steps.javascript.ScriptExecutionFailedLineNumber"
}
}
}
What am I missing??