The ZenQuotes API is an incredibly easy to use data feed for your website or app. Developers love integrating our service into their projects. Some common use cases include: start pages, Discord bots, mental health apps, and IoT devices.
It is our goal to provide a quality, reliable API that both inspires and provokes thought. Our collection of quotes are specially curated by the development team and are never auto-scraped from the internet like you will find with most other low quality API providers.
In this guide we will go over each available call option and best practices for development. Please note that you may need an API key and active subscription to get a response from some options, see the Use Limits section for more information.
Guide Contents
- Basic API Structure
- Response
- Operating Modes
- How to Fetch Quotes for your Website or App
- How to Generate List of Available Authors
- Request quotes by keyword
- Image Mode
- Get the quote for today
- Get a single random quote
- API Usage Limits and Attribution
1. Basic API Structure
ZenQuotes API calls are designed to be easy to use and understand. The result data is formatted as a JSON array. Pre-formatted HTML output is available in addition to individual plain text values.
The basic elements of an API call are as follows:
https://api.viewbits.com/v1/zenquotes?mode=[mode]&author=[author]&keyword=[keyword]
where:
- v1/zenquotes = ZenQuotes API URL. Required.
- [mode] = Retrieval type [stats, random, batch, today, authors, image]. Required.
- [keyword] = Filter results by a specific keyword. Optional, key required.
- [author] = Filter results by a specific author tag. Optional, key required.
- [key] = API key for use with premium subscriptions, be sure to obfuscate or hide this in your source code to prevent hijacking. Optional.
2. Response
The resulting API data is formatted as a JSON array. Pre-formatted HTML output is available in addition to raw individual values.
- q = quote text
- a = author name
- i = author image (key required)
- c = character count (key required)
- h = pre-formatted HTML quote
Example Quote Object
{
"q": "Lack of emotion causes lack of progress and lack of motivation.",
"a": "Tony Robbins",
"i": "#/img/tony-robbins.jpg",
"c": "63",
"h": "<blockquote>“Lack of emotion causes lack of progress and lack of motivation.” — <footer>Tony Robbins</footer></blockquote>"
}
3. Operating Modes
https://api.viewbits.com/v1/zenquotes?mode=[mode]
Mode | Description |
stats | Get developer stats like number of quote and author entries. |
random | Get a single random quote object. |
batch | Generate a JSON array of 50 quote objects. |
today | Get the quote object of the day. Refreshes 00:00 UTC. |
authors* | Get a list of available authors and tags. |
image | Generate an image with quote text. |
4. How to Fetch Quotes for your Website or App
https://api.viewbits.com/v1/zenquotes?mode=batch
This is the most efficient way for developers to load random quotes. Use a batch API call and store the results as a local file in your project. This will keep a cache of quotes that you can loop locally rather than calling the server each time you want to refresh a single quote.
After a set interval (an hour or so), call the ZenQuotes API again to refresh your local app cache. Using this method will keep load times down and free up resources for others as your user base increases. In the event the API service is unavailable, you will still have an available data set in your app to pull from.
5. Generate List of Available Authors
https://api.viewbits.com/v1/zenquotes?mode=authors&key=[your_key]
The standard [authors] call can be used to generate an array of authors in the ZenQuotes database, with links to their individual random quote API calls. You will need to append your API key to the provided author links within your app.
Author JSON Object
{
"a": "Abraham Lincoln",
"t": "abraham-lincoln",
"i": "#/img/abraham-lincoln.jpg",
"l": "#"
}
a = Author display name
t = Author tag
i = Author image (if exists)
6. Request quotes by keyword
To filter quotes by a keyword, simply add &keyword=[keyword] to the end of your request:
https://api.viewbits.com/v1/zenquotes?mode=batch&keyword=[happiness]&key=[YOUR_API_KEY]
In this example, the API would return a maximum of 50 random quotes matching the keyword “happiness”. You can use this in conjunction with the authors filter to only return quote matching the keyword and specified author.
7. Image Mode
https://api.viewbits.com/v1/zenquotes?mode=image
Generate an inspirational image from a random quote. This can also be used in conjunction with the author and keyword filter when an API key is provided.
8. Get the quote for today
https://api.viewbits.com/v1/zenquotes/?mode=today
Each day we feature a single quote from our database, which you can call using the [today] call. To reduce server load, this response should be loaded into your app cache and refreshed daily rather than making a call each time you want to display the quote in your project. New quote is generated at midnight server time (00:00 CST).
9. Get a single random quote
https://api.viewbits.com/v1/zenquotes?mode=random
This is the most simple ZenQuotes API request and will generate a single, random quote on each call. Use the [random] call sparingly, as it has little practical use for large scale projects. You generally should be caching a batch of quotes in your app locally as described in the previous sections.
You may find the [random] call useful for generating a random quote of the day for your project rather than using the standard [today] call to set yourself apart from others. This call is also good for students first learning how to use the API.
If you wanted to pull a random quote from a specific author, it would be best to use the batch call with author keyword to load a local app cache and pull a random entry from there. However, it is possible to call mode=random with an author or keyword.
10. API Usage Limits and Attribution
Requests are restricted by IP to 5 per 30 second period by default. An API key or registered IP is required for unlimited access and to disable CORS. We require that you show attribution with a backlink when using the free version of this API.