Hunch API
Introduction
Hunch allows access to its data and embeddable content through an API. Developers can make use of this API in many ways, such as:
- Putting an embeddable version of a Hunch topic on your web site. For example, if you have a blog about dogs you could embed our "which dog breed is best for me" topic in your sidebar. Note: To embed Hunch on your site, you can also use the widget Hunch provides by copying the Embed code that appears on each result page.
- Porting Hunch to a mobile device or other platform such as SMS, Twitter, IVR etc.
- Querying our "taste database" for correlations, predictive variables, and more. For example, you could ask our taste database for the correlation between people who own guns and the people who like SUVs, or what the most salient personal trait is for predicting whether someone likes the movie Napoleon Dynamite. Over time we hope to provide a complete database of people's aggregated taste preferences. Note that all data provided here is anonymized and aggregated to protect our users' privacy.
Our API is free for non-commercial use. We ask that you attribute Hunch by providing a link to our Web site wherever you use our API.
Developer Registration
In order to utilize the features of the API, you must first become a registered developer. The process is simple. Just log into your Hunch account and fill out the form below. Your developer status will be linked to your Hunch account. You will be given a developer key, or devKey for short. You must keep this key secret, or else!
By becoming a registered developer, you will also be subscribed to our developer e-mail list and receive periodic updates regarding the Hunch API, including a notification when we launch and the API becomes accessible.
You must be logged in to register.
Documentation (tentative)
I. Overview
There are two different Hunch APIs. The first is the client-side JavaScript API, which you use if you want your users to connect with Hunch directly from your own Web site. The second is the server-side JSON API, which you use if either your server needs to pull data from Hunch, or if you are developing an application that is not web-based (such as a desktop or mobile device application).
II. Server-Side JSON API
This API is used by making HTTP GET or POST requests directly to Hunch's servers. Each request is of the form:
http://api.hunch.com/api/<Name of API Call>/?<URL-encoded Arguments>
The documentation will specify whether to use a GET or POST for each request. In general, a POST is required when you are changing the state of the Hunch system. Both the API call name and the argument names are case-sensitive. The response returned by the server is encoded in the JSON format. You can find details about this format, including parsing libraries written in every major language, here.
For these requests, you need to include a devKey argument. If all your requests are originating from your own servers, you need use your secret devKey as this argument. If your requests are originating from your users, such as from a desktop or mobile application, you need to use devKey=public_devKey. If you do not pass the argument correctly, you or your users may get cut off by our daily query limit. For reference, here are the query limits:
http://api.hunch.com/api/<Name of API Call>/?<URL-encoded Arguments>
The documentation will specify whether to use a GET or POST for each request. In general, a POST is required when you are changing the state of the Hunch system. Both the API call name and the argument names are case-sensitive. The response returned by the server is encoded in the JSON format. You can find details about this format, including parsing libraries written in every major language, here.
For these requests, you need to include a devKey argument. If all your requests are originating from your own servers, you need use your secret devKey as this argument. If your requests are originating from your users, such as from a desktop or mobile application, you need to use devKey=public_devKey. If you do not pass the argument correctly, you or your users may get cut off by our daily query limit. For reference, here are the query limits:
- For requests including the public_devKey, an unlimited number of your users can query our API, but each user is limited to 1000 requests per day per IP address.
- For requests including your secret devKey, you are limited to 5000 requests per day per devKey.
Contact us to increase this limit at api@hunch.com. - For requests not including a devKey, the limit is 50 requests per day per IP address. We recommend you only do this for testing purposes.
A. Common
getQuestion
This returns information pertaining to a Hunch question.
Request method:
GET
Example API query:
http://api.hunch.com/api/getQuestion/?questionId=425553&questionImgSize=100x100
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getQuestion/?questionId=425553&questionImgSize=100x100
| Input Arguments | |
| questionId | The internal identifier for a question. This can be found using searchForQuestion. |
| questionImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable, should the question be a picture question. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"question": {"id": 425553,
"text": "Alien abductions. Are they:",
"imageUrl": "http://hunch.com/media/img/s/R/o/g/Rog-3028823.jpg",
"responseIds": [1537163, 1537153],
"topicId": "THAY"} }
| Output Variables | |||||||||||
| question | The question referenced by the specified input argument questionId. It is composed of the following variables:
|
||||||||||
getResponse
This returns information pertaining to a response to a question.
Request method:
GET
Example API query:
http://api.hunch.com/api/getResponse/?responseId=1537153&responseImgSize=100x100
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getResponse/?responseId=1537153&responseImgSize=100x100
| Input Arguments | |
| responseId | The internal identifier for a response to a question. This can be found using getQuestion. |
| responseImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable, should the response be a picture response. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"response": {"id": 1537153,
"text": "Real",
"order": 1,
"questionId": 425553,
"topicId": "THAY"} }
| Output Variables | |||||||||||||
| response | The response referenced by the specified input argument responseId. It is comprised of the following variables:
|
||||||||||||
getResult
This returns information pertaining to a Hunch result.
Request method:
GET
Example API query:
http://api.hunch.com/api/getResult/?resultId=218&resultImgSize=100x100
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getResult/?resultId=218&resultImgSize=100x100
| Input Arguments | |
| resultId | The internal identifier for the result. This can be found by using searchForResult. |
| resultImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"result": {"id": 218,
"name": "Apple MacBook Air",
"type": "laptop",
"urlName": "apple-macbook-air",
"description": "With the MacBook Air, Apple has created...",
"imageUrl": "http://hunch.com/media/img/s/a/p/p/apple-macbook-air-2889683._f100_100.jpg",
"readMoreUrl": "http://www.apple.com/macbookair/",
"hunchUrl": "http://hunch.com/laptops/result/apple-macbook-air/218/",
"topicId": 2 } }
| Output Variables | |||||||||||||||||||
| result |
The result referenced by the specified input argument resultId. It is comprised of the following variables:
|
||||||||||||||||||
getTopic
This returns information pertaining to a Hunch topic.
Request method:
GET
Example API query:
http://api.hunch.com/api/getTopic/?topicId=3&topicImgSize=100x100
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getTopic/?topicId=3&topicImgSize=100x100
| Input Arguments | |
| topicId or urlName | Use one of these arguments to reference the topic. The topicId is the internal numerical identifier for the topic. The urlName is the textual identifier for the topic, such as console-video-games, which can be found in the Hunch URL for the topic, such as http://hunch.com/console-video-games/ |
| topicImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"topic": {"id": 3,
"decision": "Where should I go on vacation?",
"urlName": "vacations",
"shortName": "Vacations",
"hunchUrl": "http://hunch.com/vacations/",
"imageUrl": "http://hunch.com/media/img/s/v/L/H/vLH-3242833._f100_100.jpg",
"resultType": "destination",
"eitherOrTopic": 0,
"category": { "categoryUrlName": "entertainment-media",
"categoryName": "Entertainment & Media",
"categoryImageUrl": "http://hunch.com/media/img/categories/Book_Movies.gif" } } }
| Output Variables | |||||||||||||||||||||||||
| topic |
The topic referenced by the specified input argument topicId or topicUrlName. It consists of the following variables:
|
||||||||||||||||||||||||
searchForTopic
This returns topic search results for the query you give it.
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForTopic/?query=cars
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForTopic/?query=cars
| Input Arguments | |
| query | A url-escaped search query for a topic. |
Example API response:
{"topics": [ { "id": "16063",
"decision": "Should I sell my car?",
"urlName": "sell-my-car",
"score": 5.643917 },
{ "id": "114",
"decision": "Should I buy or lease a car?",
"urlName": "should-i-buy-or-lease-a-car",
"score": 5.625218 } ] }
| Output Variables | |||||||||
| topics |
A list of topic search results for the input query. Each element of the list is composed of the following variables:
|
||||||||
searchForResult
This returns result search results for the query you give it.
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForResult/?query=tesla&topicId=25
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForResult/?query=tesla&topicId=25
| Input Arguments | |
| query | A url-escaped search query for a result. |
| topicId | The topic in which you wish to search for a result. |
Example API response:
{"results": [ { "id": "217533",
"name": "Tesla Roadster",
"urlName": "tesla-roadster",
"score": 12.990862 },
{ "id": "1801683",
"name": "Tesla Model S",
"urlName": "tesla-model-s",
"score": 9.0936030 } ] }
| Output Variables | |||||||||
| results |
A list of result search results for the input query. Each element of the list is composed of the following variables:
|
||||||||
searchForQuestion
This returns question search results for the query you give it.
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForQuestion/?query=aliens+ufos
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/searchForQuestion/?query=aliens+ufos
| Input Arguments | |
| query | A url-escaped search query for a question. Questions are indexed by both the question text and response text. |
| extended | Optional argument that, if passed with a value of 1, will cause the output to include a responses variable that includes the id, text, order, and imageUrl of each response to the question |
Example API response:
{ "questions": [{ "id": 419753,
"questionText": "Do you believe in UFOs or alien visits to Earth?",
"answers": ["No", "Yes"] },
{ "id": 425553,
"questionText": "Alien abductions. Are they:",
"answers": ["Fake", "Real"] }] }
| Output Variables | |||||||
| questions |
A list of questions returned by the search, each comprised of the following variables:
|
||||||
listCategories
This returns a list of categories on Hunch.
Request method:
GET
Example API query:
http://api.hunch.com/api/listCategories/
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/listCategories/
| Input Arguments | |
| There are no input arguments for this call. |
Example API response:
{"categories": [ {"urlName": "autos",
"name": "Autos"
"imageUrl": "http://hunch.com/media/img/categories/Auto.gif"},
{"urlName": "beauty-personal-care",
"name": "Beauty & Personal Care",
"imageUrl": "http://hunch.com/media/img/categories/Beauty_style.gif"},
...
{"urlName": "culture-humanities",
"name": "Culture & Humanities",
"imageUrl": "http://hunch.com/media/img/categories/Lifestyle.gif"} ] }
| Output Variables | |||||||
| categories |
A list of Hunch categories of topics. Each category is composed of the following variables:
|
||||||
listTopics
This returns a list of topics in a given Hunch category.
Request method:
GET
Example API query:
http://api.hunch.com/api/listTopics/?categoryUrlName=culture-humanities&topicImgSize=40x40
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/listTopics/?categoryUrlName=culture-humanities&topicImgSize=40x40
| Input Arguments | |
| categoryUrlName | The textual identifier for the category. |
| topicImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"topics": [ { "id": 53,
"decision": "Which broadway show should I see?",
"imageUrl": "http://hunch.com/media/img/s/w/i/c/wicked-1122623._f100_100.jpg",
"resultType": "show",
"urlName": "broadway-shows",
"shortName": "Broadway Shows",
"eitherOrTopic": 0 },
...
{ "id": 87,
"decision": "Which foreign language should I learn?",
"imageUrl": "http://hunch.com/media/img/s/f/r/e/french-4491._f100_100.png",
"resultType": "language",
"urlName": "which-foreign-language-should-i-learn",
"shortName": "Foreign Languages",
"eitherOrTopic": 0 } ] }
| Output Variables | |||||||||||||||
| topics |
A list of Hunch topics for the given category. Each topic is composed of the following variables:
|
||||||||||||||
recentTopics
This returns a list of topics recently added to Hunch.
Request method:
GET
Example API query:
http://api.hunch.com/api/recentTopics/?n=20&topicImgSize=40x40
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/recentTopics/?n=20&topicImgSize=40x40
| Input Arguments | |
| n | The number of topics you wish to return (maximum of 50). |
| topicImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"topics": [ { "id": 53,
"decision": "Which broadway show should I see?",
"imageUrl": "http://hunch.com/media/img/s/w/i/c/wicked-1122623._f100_100.jpg",
"resultType": "show",
"urlName": "broadway-shows",
"shortName": "Broadway Shows",
"eitherOrTopic": 0 },
...
{ "id": 87,
"decision": "Which foreign language should I learn?",
"imageUrl": "http://hunch.com/media/img/s/f/r/e/french-4491._f100_100.png",
"resultType": "language",
"urlName": "which-foreign-language-should-i-learn",
"shortName": "Foreign Languages",
"eitherOrTopic": 0 } ] }
| Output Variables | |||||||||||||||
| topics |
A list of Hunch topics for the given category. Each topic is composed of the following variables:
|
||||||||||||||
recommendTopics
This returns a list of topics recommended for a specific user.
Request method:
GET
Example API query:
http://api.hunch.com/api/recommendTopics/?authToken=55c085ccfeac249547de08744eab&n=20&topicImgSize=40x40
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/recommendTopics/?authToken=55c085ccfeac249547de08744eab&n=20&topicImgSize=40x40
| Input Arguments | |
| n | The number of topics you wish to return (maximum of 50). |
| authToken | The authToken for the user obtaining the recommended topics. |
| topicImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"topics": [ { "id": 53,
"decision": "Which broadway show should I see?",
"imageUrl": "http://hunch.com/media/img/s/w/i/c/wicked-1122623._f100_100.jpg",
"resultType": "show",
"urlName": "broadway-shows",
"shortName": "Broadway Shows",
"eitherOrTopic": 0 },
...
{ "id": 87,
"decision": "Which foreign language should I learn?",
"imageUrl": "http://hunch.com/media/img/s/f/r/e/french-4491._f100_100.png",
"resultType": "language",
"urlName": "which-foreign-language-should-i-learn",
"shortName": "Foreign Languages",
"eitherOrTopic": 0 } ] }
| Output Variables | |||||||||||||||
| topics |
A list of Hunch topics for the given category. Each topic is composed of the following variables:
|
||||||||||||||
B. Statistics
With this section of the API, you can query the Hunch data set for various statistics pertaining to THAY (Teach Hunch About You) questions and responses. The probability model we expose for this data is as follows: The event space is comprised of a user answering a question (or multiple questions if you are querying for statistics that span more than one response). Each response is a separate random variable that takes on the value 1 if the response was chosen by the user, and 0 if another response to the question was chosen. If you are querying for the statistics for a single response, the sample size is the number of users who have answered the question that the response corresponds to. If you are querying for two responses (for correlation statistics or otherwise), the sample size is the number of users who have answered both questions that correspond to each result.
responseStats
This returns statistical information pertaining to a given THAY Hunch response.
Request method:
GET
Example API query:
http://api.hunch.com/api/responseStats/?responseId=109
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/responseStats/?responseId=109
| Input Arguments | |
| responseId | The internal ID for a Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion. |
Example API response:
{ "sampleMean": 0.54580801944106927,
"sampleVariance": 0.2479618834067473,
"sampleStdDev": 0.49795771246838549,
"standardError": 0.0077626059967443872,
"confidenceInterval": 0.015214707753618998,
"sampleSize": 4115 }
| Output Variables | |
| sampleMean | The mean of the sample, ranging from 0-1. This is an unbiased estimator of the probability that this response is answered when its question is asked. |
| sampleVariance | Unbiased estimator of the population variance, computed from the sample |
| sampleStdDev | Unbiased estimator of the population standard deviation, computed from the sample |
| standardError | Standard error of the mean |
| confidenceInterval | 95% confidence interval around the mean (with probability 0.95 to one, the actual population average falls between the sample mean plus or minus this value) |
| sampleSize | The number of times this response's question was answered |
responsePairStats
This returns statistical information pertaining to the relationship between two THAY Hunch response.
Request method:
GET
Example API query:
http://api.hunch.com/api/responsePairStats/?response1Id=109&response2Id=113
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/responsePairStats/?response1Id=109&response2Id=113
| Input Arguments | |
| response1Id | The internal ID for the first Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion. |
| response2Id | The internal ID for the second Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion. |
Example API response:
{ "sampleMean1": 0.54753431621759019,
"sampleMean2": 0.069649211997966448
"sampleVariance1": 0.24780347898992308,
"sampleVariance2": 0.064814674780713039,
"sampleStdDev1": 0.49779863297313609,
"sampleStdDev2": 0.25458726358699296,
"covariance": -0.0005147222587387906,
"correlationRho": -0.0040614637056410529,
"sampleSize": 3934 }
| Output Variables | |
| sampleMean1 | The mean of the first response from the sample, ranging from 0-1. This is an unbiased estimator of the probability that this response is answered when its question is asked. | sampleMean2 | The mean of the second response from the sample, ranging from 0-1. This is an unbiased estimator of the probability that this response is answered when its question is asked. |
| sampleVariance1 | Unbiased estimator of the population variance of the random variable for the first response, computed from the sample |
| sampleVariance2 | Unbiased estimator of the population variance of the random variable for the second response, computed from the sample |
| sampleStdDev1 | Unbiased estimator of the population standard deviation of the random variable for the first response, computed from the sample |
| sampleStdDev2 | Unbiased estimator of the population standard deviation of the random variable for the second response, computed from the sample |
| covariance | Unbiased estimator of the covariance between the two random variables corresponding to the two response, computed from the sample |
| correlationRho | Pearson sample correlation coefficient (r), a best estimate for the correlation between the two response random variables |
| sampleSize | The number of users answering both responses' questions. |
responsePositiveCorrelations
This returns the THAY responses most strongly positively correlated to a given THAY response.
Request method:
GET
Example API query:
http://api.hunch.com/api/responsePositiveCorrelations/?responseId=109&n=5
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/responsePositiveCorrelations/?responseId=109&n=5
| Input Arguments | |
| responseId | The internal ID for a Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion. |
| n | The max number of correlated responses you wish to return (maximum 50). |
Example API response:
{ "correlations": [[1790324, 0.40824829046386302],
[1789044, 0.35634832254989918],
[1523833, 0.35169521481684363],
[1532633, 0.32513018339366734],
[253581, 0.31082489959181037]] }
| Output Variables | |
| correlations | A list of pairs of the form (responseId, correlationRho). Each responseId is the identifier corresponding to the THAY response, and each correlationRho is the Pearson correlation coefficient (r) between the two responses. |
responseNegativeCorrelations
This returns the THAY responses most strongly negatively correlated to a given THAY response.
Request method:
GET
Example API query:
http://api.hunch.com/api/responseNegativeCorrelations/?responseId=109&n=5
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/responseNegativeCorrelations/?responseId=109&n=5
| Input Arguments | |
| responseId | The internal ID for a Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion. |
| n | The max number of correlated responses you wish to return (maximum 50). |
Example API response:
{ "correlations": [[1790314, -0.40824829046386302],
[1789054, -0.35634832254989941],
[1523843, -0.35169521481684363],
[1445993, -0.32761525463309382],
[1532643, -0.32513018339366734]] }
| Output Variables | |
| correlations | A list of pairs of the form (responseId, correlationRho). Each responseId is the identifier corresponding to the THAY response, and each correlationRho is the Pearson correlation coefficient (r) between the two responses. |
similarResults
This returns the most similar results to a given result in the same topic.
Request method:
GET
Example API query:
http://api.hunch.com/api/similarResults/?resultId=218&n=5
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/similarResults/?resultId=218&n=5
| Input Arguments | |
| resultId | The internal ID for a Hunch result. This can be obtained through calls to searchForResult. |
| n | The max number of similar results you wish to return (maximum 50). |
Example API response:
{ "similarItemIds": [219, 792143, 908453, 2087263, 2367223] }
| Output Variables | |
| similarItemIds | A list of Hunch result IDs similar to the result with the input resultId |
predictResponses
This returns predictions for THAY responses a user might have given, provided a list of results they liked.
Request method:
GET
Example API query:
http://api.hunch.com/api/predictResponses/?resultIds=218.219&n=5
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/predictResponses/?resultIds=218.219&n=5
| Input Arguments | |
| resultIds | A "." separated list of internal IDs for Hunch results. |
| n | The max number of predicted responses you wish to return (maximum 50). |
Example API response:
{ "predictedResponseIds": [1532633, 1445983, 1386554, 253581, 1645064] }
| Output Variables | |
| predictedResponseIds | A list of Hunch response IDs predicted based on the input resultIds |
predictResults
This returns predictions for results a user might like in a topic, provided a list of THAY responses given.
Request method:
GET
Example API query:
http://api.hunch.com/api/predictResults/?responseIds=1532633.1445983.1386554.253581.1645064&topicId=1
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/predictResults/?responseIds=1532633.1445983.1386554.253581.1645064&topicId=1
| Input Arguments | |
| responseIds | A "." separated list of internal IDs for Hunch THAY responses. |
| topicId | The ID for the topic you wish to return results from |
Example API response:
{ "predictedResultIds": [218, 219, 2102564, 649, ... 1114353, 528214, 528224] }
| Output Variables | |
| predictedResultIds | A list of Hunch result IDs in the topic, ranking predicted based on the input responseIds |
C. Topic Play
nextQuestion
This returns the next question that would be asked in a Hunch topic play question sequence.
Request method:
GET
Example API query:
http://api.hunch.com/api/nextQuestion/?topicId=1&qaState=1388654
Example API response:
OR, if there are no more questions to ask:
Request method:
GET
Example API query:
http://api.hunch.com/api/nextQuestion/?topicId=1&qaState=1388654
| Input Arguments | |
| topicId | The internal identifier for the topic. |
| qaState | Optional argument for the state of the user. To get the first question to ask, this argument is not needed. When the question and possible responses are returned, each response returned has a qaState variable. In the next call, pass the qaState variable corresponding to the response the user answered. Repeat this until there are no more questions to ask and the API only returns rankedResultResponses. |
| authToken | Optional argument obtained by a call to getAuthToken. If a valid authToken is provided for a user, the gameplay will be enhanced and customized for that user based on his or her answers to THAY questions and other information that Hunch uses for profiling. |
| questionImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the question imageUrl output variable, should the returned question be a picture question. If this argument is not specified, the default of 160x160 is used. |
| responseImgSize | Optional argument of the form widthxheight. Specifies the size of the images which are referenced by the response imageUrl output variables, should the responses be picture responses. If this argument is not specified, the default of 160x160 is used. |
| topicImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the topic imageUrl output variable. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{"nextQuestion": { "questionId": 8,
"questionNumber": 1,
"questionText": "On which game console will you be playing this game?",
"responses": [ { "responseId": 22,
"responseText": "Wii",
"qaState": "22" },
{ "responseId": 23,
"responseText": "Xbox 360",
"qaState": "23" },
{ "responseId": 24,
"responseText": "Playstation 3",
"qaState": "24" },
{ "responseText": "Skip this question",
"qaState": "-8" } ] },
"prevQaState": "",
"topic": { "topicId": 1,
"topicDecision": "Which console video game is right for me?",
"hunchUrl": "http://hunch.com/console-video-games/",
"imageUrl": "http://hunch.com/media/img/s/o/r/a/orange-box-the-xbox-360-1697943._f160_160.jpg",
"category": { "categoryUrlName": "entertainment-media",
"categoryName": "Entertainment & Media",
"categoryImageUrl": "http://hunch.com/media/img/categories/Book_Movies.gif" } },
"rankedResultResponses": "" }
OR, if there are no more questions to ask:
{"rankedResultResponses": "1388654.1738583.18.37.25.1787423.1657443.1801463.15.1597154"}
| Output Variables | |||||||||||||||||||
| nextQuestion |
The next question that should be presented to the user in the topic play. It is composed of the following fields:
|
||||||||||||||||||
| topic |
The topic which is being played, as specified by the topicId input argument. It consists of the following variables:
|
||||||||||||||||||
| prevQaState | The qaState to be passed into the next nextQuestion call if the user chooses to go backwards. | ||||||||||||||||||
| rankedResultResponses | This variable is returned without others when the question answering is done. At this point, you should pass the value of this variable as an argument to the rankedResults call to get the results to display to the user. This variable is also included when there is a nextQuestion to ask, and should be passed to rankedResults if the user wishes to skip to the end immediately and see resuls. | ||||||||||||||||||
rankedResults
This returns a ranked list of results that match the responses you give it.
Request method:
GET
Example API query:
http://api.hunch.com/api/rankedResults/?topicId=1&responses=1388664.1738583.19
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/rankedResults/?topicId=1&responses=1388664.1738583.19
| Input Arguments | |
| topicId | The internal identifier for the topic you wish to rank results in. |
| responses | Optional argument for the responses. This is typically taken straight from the rankedResultResponses variable that nextQuestion returns at the end of a topic play. |
| authToken | Optional argument obtained by a call to getAuthToken. If a valid authToken is provided for a user, the results will be enhanced and customized for that user based on his or her answers to THAY questions and other information that Hunch uses for profiling. |
Example API response:
{"rankedResultIds": [ 1788223, 527854, 1894974, 527864, 1057433, ... 2023413, 2039163, 2054283 ],
"wildCardResultId": 2023413,
"hunchUrl": "http://hunch.com/console-video-games/all/" }
| Output Variables | |
| rankedResultIds | A ranked list of result identifiers, each a resultId that can be passed to getResult. |
| wildCardResultId | Sometimes-included identifier for the "wildcard" result. |
| hunchUrl | The URL on Hunch.com where a list of all the results can be found. |
| eitherOrPct | Included if the topic is an "Either/Or" topic. It is a list of integers from 0-100, each a percent match for the corresponding rankedResultIds entry at the same list index. |
D. Authentication
Authentication of a Hunch user through the server-side API involves a layer of security so that developers are not given access to a user's password. These are the steps needed to authenticate a user:
- Register your application with Hunch, and you will receive an appKey, which is safe to let others see (unlike your devKey).
- When a user wishes to sign into your application, ask for their username, and make a call to getAuthToken with your appKey and their username. Your app will get back an authToken and a URL.
- Direct the user to the URL in a web browser. The user will need to sign in if they aren't already. Once at that URL, the user can Accept or Reject your authToken request.
- Pass the authToken to any API call that will accept it (some will require it), and your app will be making the call on the authenticated user's behalf. If the authToken is not yet accepted by the user, the call will return as if no authToken argument was given. Your app can call getAuthStatus to determine if the authToken has been accepted or not.
getAuthToken
This returns an authentication token used to authenticate an API call as coming from a specific user.
Request method:
GET
Example API query:
http://api.hunch.com/api/getAuthToken/?username=gattis&appKey=b2013176cff4c904fb6f
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getAuthToken/?username=gattis&appKey=b2013176cff4c904fb6f
| Input Arguments | |
| username | The username of the user who your app wishes to authenticate. |
| appKey | The unique identifier for your application. Register your application with Hunch to obtain an appKey. |
Example API response:
{"authToken": "55c085ccfeac249547de08744eab4e244d81c258",
"verifyUrl": "http://hunch.com/authorize/?avrjo"}
| Output Variable | |
| authToken | Pass this token into various API calls that accept it (such as nextQuestion and rankedResults), and the return values will be customized for the authenticated user. The user must accept the authentication request by visiting the verifyUrl in a browser before the authToken is activated. |
| verifyUrl | Direct the user to this URL in a web browser, and they can sign into their Hunch account and accept the authentication request. |
getAuthStatus
Returns the status of an authToken obtained from the call to getAuthToken.
Request method:
GET
Example API query:
http://api.hunch.com/api/getAuthStatus/?authToken=55c085ccfeac249547de08744eab
Example API response:
Request method:
GET
Example API query:
http://api.hunch.com/api/getAuthStatus/?authToken=55c085ccfeac249547de08744eab
| Input Arguments | |
| authToken | The authToken returned by a call to getAuthToken. |
Example API response:
{"status": "accepted"}
| Output Variable | |
| status | The status of the authToken. It can be one of "accepted", "rejected", or "pending". Only an "accepted" authToken will authenticate a user. |
E. Contribute
teachHunchAboutYou
This fetches a user's next THAY question and also teaches Hunch that a user has answered a specific THAY question and wishes to store it.
Request method:
POST
Example API query:
Example API response:
Request method:
POST
Example API query:
POST /api/teachHunchAboutYou/ HTTP/1.1 Host: api.hunch.com Content-Length: 68 Content-Type: application/x-www-form-urlencoded questionId=212&responseId=109&authToken=55c085ccfeac249547de08744eab
| Input Arguments | |
| authToken | The authToken for the user. |
| questionId | The question ID for the question that the user answered. Optional if you wish to just fetch the next question. |
| responseId | The response ID for the response that the user answered. Optional if you wish to just fetch the next question. |
| questionImgSize | Optional argument of the form widthxheight. Specifies the size of the image which is referenced by the question imageUrl output variable, should the returned question be a picture question. If this argument is not specified, the default of 160x160 is used. |
| responseImgSize | Optional argument of the form widthxheight. Specifies the size of the images which are referenced by the response imageUrl output variables, should the responses be picture responses. If this argument is not specified, the default of 160x160 is used. |
Example API response:
{ "storedResponseId": 109,
"nextQuestion" : { "questionId": 729234,
"questionText": "Are you afraid of the dark?",
"responses": [ {"responseId": 2576074,
"responseText": "Yes"},
{"responseId": 2576084,
"responseText": "No"},
{"responseId": -729234,
"responseText": "Skip this question"} ] },
"percentWithSameAnswer": 44 }
| Output Variable | |||||||||||||||
| storedResponseId | If a response was submitted, confirmation that the response with this ID was stored for the user. | ||||||||||||||
| nextQuestion |
The next THAY question that should be presented to the user. It is composed of the following fields:
|
||||||||||||||
| percentWithSameAnswer | If a response was submitted, the percent of Hunch users with the same answer to the question. | ||||||||||||||
trainResult
This trains Hunch that a user with the given responses has left positive or negative feedback on the given result.
Request method:
POST
Example API query:
Example API response:
Request method:
POST
Example API query:
POST /api/trainResult/ HTTP/1.1 Host: api.hunch.com Content-Length: 86 Content-Type: application/x-www-form-urlencoded resultId=218&responses=729234.200.1168&rating=1&authToken=55c085ccfeac249547de08744eab
| Input Arguments | |
| authToken | The authToken for the user. |
| resultId | The result ID for the result that the user rated. |
| responses | A "." separated list of response IDs that the user left before rating the item. These responses are necessary for Hunch to learn. |
| rating | An integer representing the rating. "0" indicates a dislike, "1" indicates a like, and "2" indicates a favorite. |
Example API response:
{ "trainingRecorded": true }
| Output Variable | |
| trainingRecorded | A boolean indicating whether or not the training was successfully recorded. |
III. Client-Side JavaScript API
To utilize the JavaScript API, you will need to include this code in the <HEAD> section of your HTML:
<script type="text/javascript" src="http://api.hunch.com/api/js/"></script>
<link rel="stylesheet" type="text/css" href="http://api.hunch.com/api/css/" />
This gives any JavaScript running on your page access to a global hunch object variable. This object has various functions, each of which will perform an asynchronous HTTP API call from the user's browser to Hunch's servers.<link rel="stylesheet" type="text/css" href="http://api.hunch.com/api/css/" />
A. Higher-Level Calls
These calls internally make use of many lower-level calls to provide ready-made embedded interfaces for common tasks, such as embedding a Hunch topic for your users to play or displaying a Hunch Result.
The functions you call contain a htmlDivId argument, which is the id attribute of the HTML <DIV> element in which you wish to embed the particular Hunch content.
The functions you call contain a htmlDivId argument, which is the id attribute of the HTML <DIV> element in which you wish to embed the particular Hunch content.
hunch.playTopic
This embeds a playabe Hunch topic in an HTML DIV element on your web site.
Example JavaScript Call:
hunch.playTopic("my-hunch-div", 42);
Example JavaScript Call:
hunch.playTopic("my-hunch-div", 42);
| Input Arguments | |
| htmlDivId | The HTML "id" attribute of the "DIV" element you wish to use. |
| topicId | The internal topic identifier for the topic you wish to embed. |
hunch.showResult
This embeds a Hunch result in an HTML DIV element on your web site.
Example JavaScript Call:
hunch.showResult("my-hunch-div", 1788223);
Example JavaScript Call:
hunch.showResult("my-hunch-div", 1788223);
| Input Arguments | |
| htmlDivId | The HTML "id" attribute of the "DIV" element you wish to use. |
| itemId | The internal result identifier for the result you wish to embed. |
B. Lower-Level Calls
These functions all have a callback argument, which is a javascript function you create that gets called once the asynchronous API call returns. The callback function is called with a single argument, which is a javascript object containing the response. The structure of this response object is detailed below for each call.
hunch.nextQuestion ( qaState, topicId, questionImgSize, responseImgSize, topicImgSize, callback )
This responds with the next question that would be asked in a Hunch topic play question sequence.
See the server-side nextQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side nextQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.nextQuestion( "", 25, "160x160", "100x100", "36x36",
function (response) {
alert(response["nextQuestion"]["questionText"]);
});
hunch.rankedResults ( responses, topicId, callback )
This responds with a ranked list of results that match the responses you give it.
See the server-side rankedResults documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side rankedResults documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.rankedResults( "1388654.1738583.18.37.25.1787423.1657443.1801463.15.1597154", 1,
function (response) {
alert(response["rankedResultIds"]);
});
hunch.getResult ( resultId, resultImgSize, callback )
This responds with information pertaining to a Hunch result.
See the server-side getResult documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side getResult documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.getResult( 1788223, "125x150",
function (response) {
alert(response["result"]["name"]);
});
hunch.getQuestion ( questionId, questionImgSize, callback )
This responds with information pertaining to a Hunch question.
See the server-side getQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side getQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.getQuestion( 425553, "160x160",
function (response) {
alert(response["question"]["text"]);
});
hunch.getResponse ( responseId, responseImgSize, callback )
This responds with information pertaining to a response to a Hunch question.
See the server-side getResponse documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side getResponse documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.getResponse( 1537153, "100x100",
function (response) {
alert(response["response"]["text"]);
});
hunch.getTopic ( urlName, topicImgSize, callback )
This responds with information pertaining to a Hunch topic.
See the server-side getTopic documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side getTopic documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.getTopic( "vacations", "36x36",
function (response) {
alert(response["topic"]["decision"]);
});
hunch.searchForTopic ( query, callback )
This responds with topic search results for the query you give it.
See the server-side searchForTopic documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side searchForTopic documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.searchForTopic( "cars",
function (response) {
alert(response["topics"][0]["decision"]);
});
hunch.searchForResult ( query, topicId, callback )
This responds with result search results for the query you give it.
See the server-side searchForResult documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side searchForResult documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.searchForResult( "tesla", 25,
function (response) {
alert(response["results"][0]["name"]);
});
hunch.searchForQuestion ( query, callback )
This responds with question search results for the query you give it.
See the server-side searchForQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side searchForQuestion documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.searchForQuestion( "aliens+ufos",
function (response) {
alert(response["questions"][0]["questionText"]);
});
hunch.listCategories ( callback )
This responds with a list of the categories on Hunch.
See the server-side listCategories documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side listCategories documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.listCategories( function (response) {
alert(response["categories"][0]["name"]);
});
hunch.listTopics ( categoryUrlName, callback )
This responds with a list of topics for a given category on Hunch.
See the server-side listTopics documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side listTopics documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.listTopics( "culture-humanities",
function (response) {
alert(response["topics"][0]["decision"]);
});
hunch.authenticateUser ( callbackUrl )
This brings the user to a Hunch log-in page, which, upon successful login, will redirect back to the given callback url.
See the server-side authenticateUser documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side authenticateUser documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.authenticateUser( "http://hunch.com/developers/" );
hunch.responseStats ( responseId, callback )
This responds with statistical information pertaining to a given THAY Hunch response.
See the server-side responseStats documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side responseStats documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.responseStats( 109,
function (response) {
alert(response["sampleMean"]);
});
hunch.responsePositiveCorrelations ( responseId, n, callback )
This responds with the THAY responses most strongly positively correlated to a given THAY response.
See the server-side responsePositiveCorrelations documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side responsePositiveCorrelations documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.responsePositiveCorrelations( 109, 5,
function (response) {
alert(response["correlations"][0]);
});
hunch.responseNegativeCorrelations ( responseId, n, callback )
This responds with the THAY responses most strongly negatively correlated to a given THAY response.
See the server-side responseNegativeCorrelations documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side responseNegativeCorrelations documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.responseNegativeCorrelations( 109, 5,
function (response) {
alert(response["correlations"][0]);
});
hunch.responsePairStats ( response1Id, response2Id, callback )
This responds with statistical information pertaining to the relationship between two THAY Hunch response.
See the server-side responsePairStats documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
See the server-side responsePairStats documentation for explanation of the input arguments and values contained in the response.
Example JavaScript Call:
hunch.responsePairStats( 109, 113,
function (response) {
alert(response["correlationRho"]);
});
API Ideas
This is a list of applications we would like to see that could be developed using our API in the future. Not all of these are possible with the current API.- iPhone App
- Live flash visualization of topics that people are playing right now, a la digg Labs
- Flash visualization of live activity in my community
- Widget that shows off your answers to Teach Hunch About You for your blog/website
- Auto-publish your Teach Hunch About You answers, favorites, and plays to Twitter, Facebook
- Badge trophy case
- Facebook nemesis detector
- Hunch Zeitgeist... e.g. this week people are Hunching recession topics
- Predict your answer to Teach Hunch About You questions
- Individual Hunch topics like ("What should I wear today?") wired into iGoogle
- Factoids widget that shows off random correlations
- IM bot that lets you play a topic in a chat window
- Flash graph for users clustered by similarity
- Flash proximity graphs for people in your various taste neighborhoods, e.g. Sense-of-Humor neighborhood, Personality neighborhood
- Voice activiated 1800-find-a-bar
- Bookmarklet for adding any item on a webpage to Hunch