I am trying to develop an ESB connector for ToodleDo API v3. In that API, I need to add an array of tasks with various parameters. The number of parameters in one element of the array, can be different from other elements. The API call looks as below.
http://api.toodledo.com/3/tasks/add.php access_token=yourtoken tasks=[{"title"%3A"My Task"}%2C{"title"%3A"Another"%2C"star"%3A"1"%2C"ref"%3A"98765"}%2C{"title"%3A""%2C"ref"%3A"1234"}] fields=folder,star Tasks are added by creating a JSON object and submitting a POST to the API. Also I need to encode the data before transferring via the URL. I tried this operation by using javascript. I just tried with two parameters in the array (Mandatory -title and optional - star). My code is as below. <![CDATA[ var added = 0; var query = ""; var taskString = '{"tasks":' + mc.getProperty('uri.var.tasks') + '}'; if (mc.getProperty('uri.var.tasks') != null && mc.getProperty('uri.var.tasks') != "") { var taskObj = eval ("(" + taskString + ")"); if(Boolean(added)) { query = query + ',"tasks":['; }else { query = query + '"tasks":['; added = 1; } var count = 0; for (var i in taskObj.tasks) { if (taskObj.tasks.hasOwnProperty(i)) { if(count == 0 ) { query=query + '{\"title\":\"'+mc.getProperty('uri.var.title')+'\",'; query=query + '{\"star\":\"'+mc.getProperty('uri.var.star')+'\"}'; count =1; }else { query=query + ',{\"title\":\"'+mc.getProperty('uri.var.title')+'\",'; query=query + '{\"star\":\"'+mc.getProperty('uri.var.star')+'\"}'; } } } query = query + ']'; var encoded_query= encodeURIComponent(query); } mc.setProperty('uri.var.encoded_query', encoded_query); ]]> </script> And I have wrritten the payload factory as below. <payloadFactory media-type="xml"> <format> <xform> <access_token>$1</access_token> <tasks>$2</tasks> <fields>$3</fields> </xform> <!--{ "access_token" : "$1", "tasks" : "$2" "fields" : "$3" }--> </format> <args> <arg expression="$func:access_token" /> <arg expression="get-property('uri.var.encoded_query')" /> <arg expression="$func:fields" /> </args></payloadFactory> But it gives me an error as below. [2014-09-10 22:39:22,129] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.access_token>. Returning empty result. Error>>> Unexpected character ({) at position 96. [2014-09-10 22:39:22,130] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.tasks>. Returning empty result. Error>>> Unexpected character ({) at position 96. [2014-09-10 22:39:22,130] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.fields>. Returning empty result. Error>>> Unexpected character ({) at position 96. [2014-09-10 22:39:22,132] ERROR - ScriptMediator Failed to get the JSON payload from the input stream. Error>>> com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 101 What am I missing? How can I modify this to work with all the optional parameters? Thank you Dinithi De Silva Associate Software Engineer Mob: +94 716 667 655
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev