APIs
Umajin Cloud Services API’s you can leverage in your applications.
1) Advance Feed Setup
2) JSON-T Data Transformation
Sometimes we have very hierarchical data that needs to be flattened or processed so it can be used in a feed.
Video tutorial on JSON-T.
How Can I Transform It?
You can test transformation rules against your data here:
http://cms.umajin.com/json_transform_test.php
You can build new transformation rules with this handy helper here:
http://cms.umajin.com/json_transform_builder.php
You need to have your desired output format in mind, when transforming your input json data.
Umajin App Creator feeds use a simple flat json format.
Guidelines For What Output JSON Should Look Like
- Square brackets around the outside of everything (indicating that this is an array/list of items) [ ]
- Curly brackets around each feed item [{ }]
- Comma between feed items [{ },{ }]
- Feed Items can have properties aka name value pairs, put Semicolon between the name and value [{name1:value1},{ }]
- Double quotes around the name and the value [{“name1″:”value1”},{“name2″:”value2”}]
- Comma between name value pairs in a feed item [{“name1″:”value1”, “name1b”:”value1b”},{“name2″:”value2”}]
An Example
In the example below the input Json data has root level properties, that we want to discard.
Then we want each of the entries in the posts array to become a feed item.
Finally we want to build up a property from the posts item’s tags array.
Example input JSON Data (This is example limited to one posts item, the real data had multiple posts items)
{ "status": "ok", "count": 10, "count_total": 537, "pages": 54, "posts": [ { "id": 3799, "url": "http://wikinewzealand.org/?post_type=graph&p=3799", "title": "000645 Market capitalisation value of top 50 companies on NZX as at end of June, 2001-2014, 2014 NZD billions", "date": "2014-08-04 00:01:03", "tags": [ { "id": 1367, "slug": "capital", "title": "Capital", "description": "", "post_count": 6 }, { "id": 730, "slug": "exchange", "title": "Exchange", "description": "", "post_count": 5 }, { "id": 1372, "slug": "stock", "title": "Stock", "description": "", "post_count": 5 }, { "id": 1374, "slug": "trading", "title": "Trading", "description": "", "post_count": 2 } ], "custom_fields": { "number": [ "000645" ] } } ] }
{ "status": "ok", "count": 10, "count_total": 537, "pages": 54, "posts": [ { "id": 3799, "url": "http://wikinewzealand.org/?post_type=graph&p=3799", "title": "000645 Market capitalisation value of top 50 companies on NZX as at end of June, 2001-2014, 2014 NZD billions", "date": "2014-08-04 00:01:03", "tags": [ { "id": 1367, "slug": "capital", "title": "Capital", "description": "", "post_count": 6 }, { "id": 730, "slug": "exchange", "title": "Exchange", "description": "", "post_count": 5 }, { "id": 1372, "slug": "stock", "title": "Stock", "description": "", "post_count": 5 }, { "id": 1374, "slug": "trading", "title": "Trading", "description": "", "post_count": 2 } ], "custom_fields": { "number": [ "000645" ] } } ] }
Example transformation rules (JSON format):
{ "self":"[{posts}]", "posts[*]":"{"title":"{$.title}","url":" {$.url}","graph":"http://wikinewzealand.org/graphs/{$.custom_fields.number}.png","tags":"{$.tags}"},", "self.posts[*].tags[*]":"{$.title}," }
{ "self":"[{posts}]", "posts[*]":"{"title":"{$.title}","url":" {$.url}","graph":"http://wikinewzealand.org/graphs/{$.custom_fields.number}.png","tags":"{$.tags}"},", "self.posts[*].tags[*]":"{$.title}," }
Rule tips:
self is a shortcut for the root level of the json (in the example input {self.status} would be replaced with “ok”
The rule name should reference a level of the input json data
$ is a placeholder for the rule name, which is handy when hte rule name is quite long (eg self.posts[*].tags[*]),
[*] in the rule name means execute this rule on each item in the array
Lets go through each rule :
"self":"[{posts}]" :
"self":"[{posts}]" :
This is putting square brackets around everything. {posts} will be replaced with the result of the rule posts[*].
Removing the “” escape characters and formatting it a bit, we get something a bit easier to read
"posts[*]":"{"title":"{$.title}","url":"{$.url}","graph":"http://wikinewzealand.org/graphs/{$.custom_fields.number}.png","tags":"{$.tags}"},",
"posts[*]":"{"title":"{$.title}","url":"{$.url}","graph":"http://wikinewzealand.org/graphs/{$.custom_fields.number}.png","tags":"{$.tags}"},",
Looking at the {} tokens used:
{$.title} really means {posts[*].title}
{$.url} really means {posts[*].url}
{$.custom_fields.number} really means {posts[*].custom_fields.number}, so we get the value of the number property of the custom_fields object which is a child of the posts item.
{$.tags} will contain the output from running the “self.posts[*].tags[*]” rule.
Note the trailing comma, so that if there are multiple posts then they will have a comma between them.
"self.posts[*].tags[*]":"{$.title},"
"self.posts[*].tags[*]":"{$.title},"
This goes through the array of tags for each posts item, it builds up a list of the tags.title values with commas between them.
Example output from performing the transformation:
[ { "title":"000645 Market capitalisation value of top 50 companies on NZX as at end of June, 2001-–2014, 2014 NZD billions", "url":"http://wikinewzealand.org/?post_type=graph&p=3799", "graph":"http://wikinewzealand.org/graphs/000645.png", "tags":"Capital,Exchange,Stock,Trading" } ]
[ { "title":"000645 Market capitalisation value of top 50 companies on NZX as at end of June, 2001-–2014, 2014 NZD billions", "url":"http://wikinewzealand.org/?post_type=graph&p=3799", "graph":"http://wikinewzealand.org/graphs/000645.png", "tags":"Capital,Exchange,Stock,Trading" } ]
There is a final step which removes any trailing commas from both the list of tags.title values and the posts items.
3) Turning Form Submissions Into A Feed
press the ‘share’ button to generate this API feed
this generates a REST call like this;
http://api.fingertapps.com/1.2/get-form-share.php?formid=3&num_results=20&share_token=xxx
http://api.fingertapps.com/1.2/get-form-share.php?formid=3&num_results=20&share_token=xxx
use this as a direct URL source or use it for a new feed in the Dashboard