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:
  • 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

Input Arguments
questionIdThe internal identifier for a question. This can be found using searchForQuestion.
questionImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the question
textThe text of the question
imageUrlIf the question is a picture question, the url to the image on our site
responseIdsA list of internal identifiers for the responses to the question
topicIdThe internal identifier for the topic that the question belongs to, or "THAY" if the question comes from Teach Hunch About You



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

Input Arguments
responseIdThe internal identifier for a response to a question. This can be found using getQuestion.
responseImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the response
textThe text of the response
imageUrlIf the response is a picture response, the url to the image on Hunch.
orderThe display order of the response within the question. 0 is the first response, 1 is the second, and so on.
questionIdThe internal identifier for this response's question
topicIdThe internal identifier for the topic that the response belongs to, or "THAY" if the response comes from Teach Hunch About You


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

Input Arguments
resultIdThe internal identifier for the result. This can be found by using searchForResult.
resultImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the result.
nameThe textual name of the result.
typeA textual name describing the type of the result.
urlNameThe simplified textual name of the result which can be used in a hyperlink URL.
descriptionThe description of the result.
imageUrlThe URL to the result's image, hosted by Hunch.
readMoreUrlA link external to Hunch where a user can read more about a result.
hunchUrlThe link to the result on the Hunch website.
topicIdThe internal identifier for the topic which the result belongs to.



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

Input Arguments
topicId or urlNameUse 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/
topicImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the topic
decisionThe full textual name of the topic, in the form of a question.
urlNameThe simplified textual name for the topic that can be used in a hyperlink URL.
shortNameThe shortened textual name for the topic.
hunchUrlThe URL on the Hunch website for playing the topic.
imageUrlThe URL of the topic's image, hosted by Hunch
resultTypeA short textual name for the type of result contained within the topic.
eitherOrTopicA binary bit representing whether or not the topic is an "Either-Or" topic: 1 if it is, 0 if it is not.
category The main category for the topic. It consists of the following variables:
categoryUrlNameThe textual identifier for the category, which is a simplified name for a category that can be used in a URL.
categoryNameThe full textual name for the category.
categoryImageUrlThe URL to the category's image, hosted by Hunch



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

Input Arguments
queryA 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:
idThe internal identifier for the topic.
decisionThe full textual name of the topic, in the form of a question.
urlNameThe simplified textual name for the topic that can be used in a hyperlink URL.
scoreThe score for the relevancy of this search result



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

Input Arguments
queryA url-escaped search query for a result.
topicIdThe 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:
idThe internal identifier for the result.
nameThe textual name of the result.
urlNameThe simplified textual name for the result that can be used in a hyperlink URL.
scoreThe score for the relevancy of this search result



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

Input Arguments
queryA url-escaped search query for a question. Questions are indexed by both the question text and response text.
extendedOptional 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:
idThe internal identifier for the question returned. This is to be used in other calls to reference this question.
questionTextThe text of the question
answersThe text of the responses to the question


listCategories
This returns a list of categories on Hunch.

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:
urlNameThe textual identifier for the category, which is a simplified name for a category that can be used in a URL.
nameThe full textual name for the category.
imageUrlThe URL to the category's image, hosted by Hunch



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

Input Arguments
categoryUrlNameThe textual identifier for the category.
topicImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the topic.
decisionThe full textual name for the topic, in the form of a question.
imageUrlThe URL for the topic's image, hosted by Hunch.
resultTypeA short textual name for the type of results contained in the topic.
urlNameA textual identifier for the topic, which is a simplified name for a topic that can be used in a URL.
shortNameA shortened textual name for the topic.
eitherOrTopicA binary bit representing whether or not the topic is an "Either-Or" topic: 1 if it is, 0 if it is not.



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

Input Arguments
nThe number of topics you wish to return (maximum of 50).
topicImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the topic.
decisionThe full textual name for the topic, in the form of a question.
imageUrlThe URL for the topic's image, hosted by Hunch.
resultTypeA short textual name for the type of results contained in the topic.
urlNameA textual identifier for the topic, which is a simplified name for a topic that can be used in a URL.
shortNameA shortened textual name for the topic.
eitherOrTopicA binary bit representing whether or not the topic is an "Either-Or" topic: 1 if it is, 0 if it is not.



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

Input Arguments
nThe number of topics you wish to return (maximum of 50).
authTokenThe authToken for the user obtaining the recommended topics.
topicImgSizeOptional argument of the form width
x
height. 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:
idThe internal identifier for the topic.
decisionThe full textual name for the topic, in the form of a question.
imageUrlThe URL for the topic's image, hosted by Hunch.
resultTypeA short textual name for the type of results contained in the topic.
urlNameA textual identifier for the topic, which is a simplified name for a topic that can be used in a URL.
shortNameA shortened textual name for the topic.
eitherOrTopicA binary bit representing whether or not the topic is an "Either-Or" topic: 1 if it is, 0 if it is not.





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

Input Arguments
responseIdThe 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
sampleMeanThe 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.
sampleVarianceUnbiased estimator of the population variance, computed from the sample
sampleStdDevUnbiased estimator of the population standard deviation, computed from the sample
standardErrorStandard error of the mean
confidenceInterval95% 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)
sampleSizeThe 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

Input Arguments
response1IdThe internal ID for the first Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion.
response2IdThe 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
sampleMean1The 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.
sampleMean2The 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.
sampleVariance1Unbiased estimator of the population variance of the random variable for the first response, computed from the sample
sampleVariance2Unbiased estimator of the population variance of the random variable for the second response, computed from the sample
sampleStdDev1Unbiased estimator of the population standard deviation of the random variable for the first response, computed from the sample
sampleStdDev2Unbiased estimator of the population standard deviation of the random variable for the second response, computed from the sample
covarianceUnbiased estimator of the covariance between the two random variables corresponding to the two response, computed from the sample
correlationRhoPearson sample correlation coefficient (r), a best estimate for the correlation between the two response random variables
sampleSizeThe 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

Input Arguments
responseIdThe internal ID for a Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion.
nThe 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
correlationsA 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

Input Arguments
responseIdThe internal ID for a Hunch THAY response. This can be obtained through calls to searchForQuestion and getQuestion.
nThe 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
correlationsA 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

Input Arguments
resultIdThe internal ID for a Hunch result. This can be obtained through calls to searchForResult.
nThe max number of similar results you wish to return (maximum 50).

Example API response:
{ "similarItemIds": [219, 792143, 908453, 2087263, 2367223] }


Output Variables
similarItemIdsA 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

Input Arguments
resultIdsA "." separated list of internal IDs for Hunch results.
nThe max number of predicted responses you wish to return (maximum 50).

Example API response:
{ "predictedResponseIds": [1532633, 1445983, 1386554, 253581, 1645064] }


Output Variables
predictedResponseIdsA 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

Input Arguments
responseIdsA "." separated list of internal IDs for Hunch THAY responses.
topicIdThe ID for the topic you wish to return results from

Example API response:
{ "predictedResultIds": [218, 219, 2102564, 649, ... 1114353, 528214, 528224] }


Output Variables
predictedResultIdsA 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

Input Arguments
topicIdThe internal identifier for the topic.
qaStateOptional 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.
authTokenOptional 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.
questionImgSizeOptional argument of the form width
x
height. 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.
responseImgSizeOptional argument of the form width
x
height. 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.
topicImgSizeOptional argument of the form width
x
height. 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:
questionIdThe internal identifier for the question.
questionNumberThe question number (out of 10) that the user is currently on.
questionTextThe textual content of the question being asked.
imageUrlIf the question is a picture question, the url to the image hosted by Hunch
responses A list of the response that belong to this question. Each is composed of the following fields:
responseIdThe internal identifier for the response.
responseTextThe textual content of the response.
qaStateThe qaState to be passed into the next nextQuestion call if the user chooses this response.
imageUrlIf the response is a picture response, the url to the image hosted by Hunch
topic The topic which is being played, as specified by the topicId input argument. It consists of the following variables:
topicIdThe internal identifier for the topic.
topicDecisionThe textual name for the topic.
hunchUrlThe URL at Hunch where a user can play this topic.
imageUrlThe URL to the topic's image, hosted by Hunch.
category The main category for the topic. It consists of the following variables:
categoryUrlNameThe textual identifier for the category, which is a simplified name for a category that can be used in a URL.
categoryNameThe full textual name for the category.
categoryImageUrlThe URL to the category's image, hosted by Hunch
prevQaStateThe qaState to be passed into the next nextQuestion call if the user chooses to go backwards.
rankedResultResponsesThis 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

Input Arguments
topicIdThe internal identifier for the topic you wish to rank results in.
responsesOptional argument for the responses. This is typically taken straight from the rankedResultResponses variable that nextQuestion returns at the end of a topic play.
authTokenOptional 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
rankedResultIdsA ranked list of result identifiers, each a resultId that can be passed to getResult.
wildCardResultIdSometimes-included identifier for the "wildcard" result.
hunchUrlThe URL on Hunch.com where a list of all the results can be found.
eitherOrPctIncluded 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:
  1. Register your application with Hunch, and you will receive an appKey, which is safe to let others see (unlike your devKey).
  2. 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.
  3. 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.
  4. 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

Input Arguments
usernameThe username of the user who your app wishes to authenticate.
appKeyThe 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
authTokenPass 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.
verifyUrlDirect 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

Input Arguments
authTokenThe authToken returned by a call to getAuthToken.

Example API response:
{"status": "accepted"}

Output Variable
statusThe 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:
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
authTokenThe authToken for the user.
questionIdThe question ID for the question that the user answered. Optional if you wish to just fetch the next question.
responseIdThe response ID for the response that the user answered. Optional if you wish to just fetch the next question.
questionImgSizeOptional argument of the form width
x
height. 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.
responseImgSizeOptional argument of the form width
x
height. 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
storedResponseIdIf 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:
questionIdThe internal identifier for the question.
questionTextThe textual content of the question being asked.
imageUrlIf the question is a picture question, the url to the image hosted by Hunch
responses A list of the response that belong to this question. Each is composed of the following fields:
responseIdThe internal identifier for the response.
responseTextThe textual content of the response.
imageUrlIf the response is a picture response, the url to the image hosted by Hunch
percentWithSameAnswerIf 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:
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
authTokenThe authToken for the user.
resultIdThe result ID for the result that the user rated.
responsesA "." separated list of response IDs that the user left before rating the item. These responses are necessary for Hunch to learn.
ratingAn integer representing the rating. "0" indicates a dislike, "1" indicates a like, and "2" indicates a favorite.

Example API response:
{ "trainingRecorded": true }

Output Variable
trainingRecordedA 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.

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.

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);

Input Arguments
htmlDivIdThe HTML "id" attribute of the "DIV" element you wish to use.
topicIdThe 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);

Input Arguments
htmlDivIdThe HTML "id" attribute of the "DIV" element you wish to use.
itemIdThe 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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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