Constructor
new WolframAlphaAPI(appid)
You may get your 'appid' at https://developer.wolframalpha.com/portal/myapps/.
Remember, this appID must be kept secret.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
appid |
string
|
the appid, must be non-empty string. |
Methods
getFull(input) → {Promise.<(Object|string)>}
Takes 'input' (which is either a string, or an object of parameters), runs it through
the Wolfram|Alpha Full Results API, and returns a Promise that
either resolves an Object or a string of XML, or rejects if there's an error.
Parameters:
Name | Type | Description |
---|---|---|
input |
string |Object
|
string or object of parameters |
Returns:
- Type:
-
Promise.<(Object|string)>
Example
// {success: true, error: false, numpods: 6, datatypes: 'Math', timedout: '', timing: 1.08 ...
waApi.getFull('2+2').then(console.log, console.error);
// "<queryresult success='true' error='false' numpods='7' ...
waApi.getFull({input:'nyc to la', output:'xml'}).then(console.log, console.error);
// { success: false, error: false, numpods: 0, datatypes: '', timedout: '', ...
waApi.getFull('F9TVlu5AmVzL').then(console.log, console.error)
// TypeError: method only receives string or object
waApi.getFull().then(console.log, console.error);
getShort(input) → {Promise.<string>}
Takes 'input' (which is either a string, or an object of parameters), runs it through
the Wolfram|Alpha Short Answers API, and returns a Promise that
resolves a string of results, or rejects if there's an error.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
input |
string
|
Object
|
string or object of parameters |
Returns:
- Type:
-
Promise.<string>
Example
// "4"
waApi.getShort('2+2').then(console.log, console.error);
// "3966 kilometers"
waApi.getShort({i: 'nyc to la', units: 'metric'}).then(console.log, console.error);
// Error: Wolfram|Alpha did not understand your input
waApi.getShort('F9TVlu5AmVzL').then(console.log, console.error);
// TypeError: method only receives string or object
waApi.getShort().then(console.log, console.error);
getSimple(input) → {Promise.<DataURI>}
Takes 'input' (which is either a string, or an object of parameters), runs it through
the Wolfram|Alpha Simple API, and returns a Promise that
resolves a string of a "Data URI", or rejects if there's an error.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
input |
string |Object
|
string or object of parameters |
Returns:
- Type:
-
Promise.<DataURI>
Example
// "data:image/gif;base64,R0lGODlhHAK5AvcAAAAAAAAEAAgICAgMCBAQEBAUEBsdGzE0MTk8OTk4OS0uLSAkI...
waApi.getSimple('2+2').then(console.log, console.error);
// "data:image/gif;base64,R0lGODlhHAJNBfcAAAAAAAAEAAgICAgMCBAQEBAUEBgYGBgcGCAgICAkICksKSkoK...
waApi.getSimple({i: 'nyc to la', units: 'metric'}).then(console.log, console.error);
// Error: Wolfram|Alpha did not understand your input
waApi.getSimple('F9TVlu5AmVzL').then(console.log, console.error);
// TypeError: method only receives string or object
waApi.getSimple().then(console.log, console.error);
getSpoken(input) → {Promise.<string>}
Takes 'input' (which is either a string, or an object of parameters), runs it through
the Wolfram|Alpha Spoken Results API, and returns a Promise that
resolves a string of results, or rejects if there's an error.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
input |
string |Object
|
string or object of parameters |
Returns:
- Type:
-
Promise.<string>
Example
// "The answer is 4"
waApi.getSpoken('2+2').then(console.log, console.error);
// "The answer is about 3966 kilometers"
waApi.getSpoken({i: 'nyc to la', units: 'metric'}).then(console.log, console.error);
// Error: Wolfram Alpha did not understand your input
waApi.getSpoken('F9TVlu5AmVzL').then(console.log, console.error);
// TypeError: method only receives string or object
waApi.getSpoken().then(console.log, console.error);