Ebook Glue has a really simple HTTP API at https://ebookglue.com/convert
that can help you convert your content to ePub and Mobipocket files. A GET request will allow you to convert a web page, while a POST request will allow you to create a Mobipocket, ePub, or HTML file from many popular document formats.
Ebook Glue also allows you to customize your ebooks with book covers, device-specific optimizations, custom stylesheets, content parsing, and automatic chapter detection.
If you get stuck, email [email protected]
For updates on the system status of the API, visit our API status dashboard hosted on Google App Engine.
To authenticate, set the token parameter on every request with your full API key. Every request must have your API key to be processed.
Keep your API key secret - all requests to the API should be proxied if you wish to make requests from a client device.
curl -o converted.epub \ https://ebookglue.com/convert?token=your-api-key
import requests # http://python-requests.org/ payload = { 'token': 'your-api-key', } r = requests.get('https://ebookglue.com/convert', params=payload) print r.status_code
require 'rest_client' # https://github.com/rest-client/rest-client params = { :token => 'your-api-key' } RestClient.get 'https://ebookglue.com/convert', params
var sys = require('util'), rest = require('./restler'); // https://npmjs.org/package/restler var api_key = 'your-api-key'; rest.get("https://ebookglue.com/convert", { 'data': { 'token': api_key } }).on('complete', function (data, response) { sys.puts(response.statusCode); });
package main import ( "fmt" "net/url" "net/http" ) func main() { v := url.Values{} apiKey := "your-api-key" v.Set("token", apiKey) apiUrl := "https://ebookglue.com/convert" + v.Encode() resp, _ := http.Get(apiUrl) fmt.Println(resp.Status) }
The code example above will result in a HTTP 401 error if you have not entered a valid API key as the token. Since there are no parameters being passed, it will result in a HTTP 400 error if you're properly authenticated (see below for required parameters on API requests). Here is a list of the HTTP error codes used by the Ebook Glue API:
Converting a web page or feed (RSS or Atom) involves a GET request to https://ebookglue.com/convert
including the URL of the web page or feed you'd like to convert (CSS and images will be included from web pages) and the format of the output (epub or mobi).
curl -o converted.epub \ https://ebookglue.com/convert?token=your-api-key&url=http://www.newyorker.com/online/blogs/books/2013/09/oyster-iphone-app-ereader-what-does-it-mean-to-own-a-book.html?printable=true¤tPage=all
import requests # http://python-requests.org/ payload = { 'token': 'your-api-key', 'url': 'http://www.newyorker.com/online/blogs/books/2013/09/oyster-iphone-app-ereader-what-does-it-mean-to-own-a-book.html?printable=true¤tPage=all', } r = requests.get('https://ebookglue.com/convert', params=payload) print r.status_code
require 'rest_client' # https://github.com/rest-client/rest-client params = { :token => 'your-api-key', :url => 'http://www.newyorker.com/online/blogs/books/2013/09/oyster-iphone-app-ereader-what-does-it-mean-to-own-a-book.html?printable=true¤tPage=all' } RestClient.get 'https://ebookglue.com/convert', params
var sys = require('util'), rest = require('./restler'); // https://npmjs.org/package/restler var api_key = 'your-api-key', article = 'http://www.newyorker.com/online/blogs/books/2013/09/oyster-iphone-app-ereader-what-does-it-mean-to-own-a-book.html?printable=true¤tPage=all'; rest.get("https://ebookglue.com/convert", { 'data': { 'token': api_key, 'url': article } }).on('complete', function (data, response) { sys.puts(response.statusCode); });
package main import ( "fmt" "net/url" "net/http" ) func main() { v := url.Values{} apiKey := "your-api-key" v.Set("token", apiKey) apiUrl := "https://ebookglue.com/convert" + v.Encode() resp, _ := http.Get(apiUrl) fmt.Println(resp.Status) }
Converting a file involves a POST request to https://ebookglue.com/convert
that is multipart/form-data
including the file you would like to convert (you can convert multiple document formats into HTML, ePub, and Mobipocket files) and the format of the output (epub or mobi).
curl -o converted.epub \ -F "token=your-api-key" \ -F "[email protected]" \ https://ebookglue.com/convert
import requests # http://python-requests.org/ data = { 'token': "your-api-key", } files = { 'file': file_object, } r = requests.post("https://ebookglue.com/convert", data=data, files=files) print r.status_code
require 'rest_client' # https://github.com/rest-client/rest-client params = { :file => File.new('/path/to/file/index.html'), :token => 'your-api-key' } RestClient.post 'https://ebookglue.com/convert', params
var sys = require('util'), fs = require('fs'), rest = require('./restler'); // https://npmjs.org/package/restler var api_key = 'your-api-key', article = 'http://www.newyorker.com/online/blogs/books/2013/09/oyster-iphone-app-ereader-what-does-it-mean-to-own-a-book.html?printable=true¤tPage=all'; fs.stat("index.html", function(err, stats) { rest.get("https://ebookglue.com/convert", { 'multipart': true, 'data': { 'token': api_key, 'file': rest.file('index.html', null, stats.size, null, "text/html") } }).on('complete', function (data, response) { sys.puts(response.statusCode); }); });
package main import ( "fmt" "mime/multipart" "net/http" ) func main() { apiKey := "your-api-key" client := &Client{} apiUrl := "https://ebookglue.com/convert" buf := new(bytes.Buffer) w := multipart.NewWriter(buf) label, _ := w.CreateFormField("token") label.Write([]byte(apiKey)) fw, _ := w.CreateFormFile("file", "index.html") fd, _ := os.Open("index.html") io.Copy(fw, fd) defer fd.Close() w.Close() req, _ := http.NewRequest("POST", apiUrl, buf) req.Header.Set("Content-Type", w.FormDataContentType()) resp, _ := client.Do(req) fmt.Println(resp.Status) }
When issuing a GET request to Ebook Glue, you need to pass URL's for some of the parameters. Make sure your URL is the full URL (including the http://
) and publicly accessible.
When issuing a POST request to Ebook Glue, you need to provide file uploads for some of the parameters as a regular file upload similar to a <input type="file">
.
The format parameter controls the output format. By default, ePub files are generated, but you can explicitly set the value of the format parameter to epub or mobi for ePub or Mobipocket books respectively. Although ePub is the standard format for ebooks, Amazon Kindle devices only support Mobipocket books.
By default, ebooks will not have any specific metadata associated with the files. You can set the metadata parameter with a JSON-encoded string containing all of the metadata you would like to include. If an item is not included in your JSON string or you don't supply the metadata property in your request, the metadata fields will be left blank. Here is an example of the properties that can be included:
{ "authors": ["Carl Sagan"], "title": "Pale Blue Dot", "tags": ["space exploration", "astronomy"], "isbn": "978-0345376596", "language": "English", "pubdate": "1997-9-8", "publisher": "Ballantine Books", "producer": "Shantanu Bala", "series": "Works by Carl Sagan", "series_index": "12", "sort": { "author": "Sagan, Carl", "title": "Pale Blue Dot" } }
A few notes on book metadata: The pubdate parameter accepts an ISO-encoded date string. The sort parameter accepts an object with an extra title and author that will be used to sort the book when displayed in a list. The producer of the book is the person who is preparing the digital copy, while the publisher is generally the person or organization in charge of the publication of the book.
By default, ebooks will not have any book covers unless you specify one. When fetching a web page, you set the cover parameter to the URL of the cover you would like to use (for GET requests to the API) or the image file itself (for POST requests). The best height:width ratio is 4:3, and higher resolution images are recommended, but Ebook Glue will ensure that your book cover will not be stretched or cropped. Instead, blank space will be added to either increase the height or width appropriately.
Ebook Glue allows you to optimize your ebooks to display well on different devices. Since each device has a unique form factor, Ebook Glue gives you pre-defined CSS rules that help ensure your ebook looks good. Set the device parameter to:
Ebook Glue allows you to specify an extra stylesheet that can be used to modify the appearance of your ebook. Note that not all devices are capable of renderring all CSS rules. The stylesheet parameter allows you to specify the URL of a stylesheet to include (for GET requests to the API) or the CSS file itself (for POST requests).
Unless you specify an XPath expression in the chapters parameter, Ebook Glue will use elements with the class chapter
as well as h1
and h2
elements containing the words, "chapter," "book," "prologue," "epilogue," "part," or "section."
If you need help with the Ebook Glue conversion API, send an email to [email protected]