The Leanpub API

95 views
Skip to first unread message

Scott Patten

unread,
Aug 9, 2013, 7:40:12 PM8/9/13
to lea...@googlegroups.com

Hi All,

We've put together the beginnings of an API for Leanpub. Right now you can

  • publish and preview your book
  • get information on what step the publish or preview is at
  • get sales data.

It's pretty straightforward. To do a preview, you post to:

https://leanpub.com/SLUG/preview?api_key=YOUR_API_KEY

The full documentation is at https://leanpub.com/help/api. It explains all the options available and how to get your api key.

Please let us know what you like, what you wish it would do and what cool things you're built with it.

Enjoy!

Scott

--
Scott Patten
Co-founder, Leanpub and Ruboss
604 341-1701

Aaron Sumner

unread,
Aug 9, 2013, 8:04:51 PM8/9/13
to lea...@googlegroups.com
Thanks Scott! I've been looking forward to this. 

Aaron
--
You received this message because you are subscribed to the Google Groups "leanpub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leanpub+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gary Jones

unread,
Aug 10, 2013, 3:43:32 AM8/10/13
to lea...@googlegroups.com
Looks great Scott.

Presumably, the publish and preview actions for a slug are rejected if the API key doesn't match with the author? I.e. I can send a request to have scotttest999 published, with my API key.

As well as invidual data, can there be an endpoint to get information on total sales? E.g. Total number of happy people, total number of paid people, total refunds, total royalties etc? (I think this is all from the /slug/sales page)

Gary.

Ted M. Young [@jitterted]

unread,
Aug 10, 2013, 7:27:22 PM8/10/13
to lea...@googlegroups.com
This looks interesting. It'd be great if the documentation wasn't only in terms of curl, though. :)

;ted



Peter Armstrong

unread,
Aug 10, 2013, 8:05:27 PM8/10/13
to lea...@googlegroups.com
> Presumably, the publish and preview actions for a slug are rejected if the API key doesn't match with the author? I.e. I can send a request to have scotttest999 published, with my API key.

Yes, we reject API requests on stuff you don't own :)

> As well as invidual data, can there be an endpoint to get information on total sales? E.g. Total number of happy people, total number of paid people, total refunds, total royalties etc? (I think this is all from the /slug/sales page)

Yeah, we should hook up the CSV download actions to the API...

Cheers
Peter

Scott Patten

unread,
Aug 11, 2013, 3:27:27 PM8/11/13
to lea...@googlegroups.com
Gary, good idea. I've added an API call for total sales of your book. You do a get GET request to 


You can also get it in XML here:


Scott


--
You received this message because you are subscribed to the Google Groups "leanpub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leanpub+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gary Jones

unread,
Aug 12, 2013, 3:33:24 AM8/12/13
to lea...@googlegroups.com
Great. That, as of yesterday, hadn't been added to /help/api yet.

Gary.

Scott Patten

unread,
Aug 13, 2013, 12:46:07 AM8/13/13
to lea...@googlegroups.com
Hi Gary,

This is documented now.

Thanks,

Scott


On Mon, Aug 12, 2013 at 12:33 AM, Gary Jones <ga...@gamajo.com> wrote:
Great. That, as of yesterday, hadn't been added to /help/api yet.

Gary.
--
You received this message because you are subscribed to the Google Groups "leanpub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leanpub+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Mathias Weidner

unread,
Aug 21, 2013, 5:06:51 AM8/21/13
to lea...@googlegroups.com
Hello All,


Am Samstag, 10. August 2013 01:40:12 UTC+2 schrieb Scott Patten:

Hi All,

We've put together the beginnings of an API for Leanpub. Right now you can

I followed up by putting together Perl bindings for the API called WebService::Leanpub. I just uploaded it to CPAN, it should be available soon at http://search.cpan.org/~mamawe/.

This first version does only the basic things, which means at the moment it doesn't fetch other pages then the first for individual_purchases and it doesn't email on publish.
But it is accompanied by a command line program that makes the functionality available for Makefiles and the like.

Since this is in an early stage feel free to make suggestions regarding the Perl module.

Regards,

Mathias

Mathias Weidner

unread,
Aug 24, 2013, 5:15:08 AM8/24/13
to lea...@googlegroups.com
The API works great so far. You can in your logs some entries coming from "libwebservice-leanpub-perl/$VERSION" which come from the Perl binding.

What I am missing in regard to '/preview.json' is a possibility to generate a partial preview using Preview.txt like I can in the web interface.

Apart from that very good work, Thanks.

Mathias

Scott Patten

unread,
Aug 26, 2013, 3:01:26 PM8/26/13
to lea...@googlegroups.com

Hi Mathias,

I've just added support for this, and will be deploying it later today. It should be live in a couple of hours.

I've added it to the documentation, but the gist of it is that instead of posting to https://leanpub.com/SLUG/preview.json you post to https://leanpub.com/SLUG/preview/subset.json.

Scott



--
You received this message because you are subscribed to the Google Groups "leanpub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leanpub+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mathias Weidner

unread,
Aug 30, 2013, 3:52:11 AM8/30/13
to lea...@googlegroups.com


Am Montag, 26. August 2013 21:01:26 UTC+2 schrieb Scott Patten:

Hi Mathias,

I've just added support for this, and will be deploying it later today. It should be live in a couple of hours.

thanks, this works with version 0.1.0 of the perl module WebService::Leanpub which I have just uploaded to CPAN. It should be available in a couple of hours.

Regards,

Mathias

Seth Vincent

unread,
Aug 30, 2013, 10:55:24 PM8/30/13
to lea...@googlegroups.com
I just created a node.js wrapper for the api: https://github.com/sethvincent/node-leanpub-client

It's on npm, so you can install it with npm install leanpub-client

I found myself wishing there were a book info endpoint that I could use to get/post/put the book title, description, a few settings, and maybe even the download urls for the preview/published book and sample.

There are a couple todos/known issues left on this wrapper:
  • it currently only supports json.
  • paging through all individual purchases currently isn't supported. that'll be an easy fix.
My next steps with it will likely include integration with grunt.js by creating a grunt task for building preview/published versions of the book.

Currently it has a status() method that polls the job status endpoint every 10 seconds. It's on by default but can be disabled by passing poll: false in the options object.

Please try this out and let me know if any issues come up.

Thanks,
Seth Vincent
Message has been deleted

Ted M. Young [@jitterted]

unread,
Apr 30, 2014, 8:26:01 PM4/30/14
to lea...@googlegroups.com
(btw, you might want to change your API key, as that's "private" to your account.)

You shouldn't be getting a redirect for the https link, it should have returned some JSON data, e.g., for me:


returned:

{"book":"guide-to-leanpub-formatting","url":"https://leanpub.com/guide-to-leanpub-formatting","total_author_royalties":"0.0","total_book_royalties":"0.0","num_happy_readers":10,"num_happy_paid_purchas
es":0,"num_refunded_purchases":0,"unpaid_royalties":"0.0","royalties_currently_due":"0.0","royalties_due_on_first_of_next_month":"0.0","paid_royalties":"0.0"}

Or, you can ask for XML using sales.xml: 


which returns:

<?xml version="1.0" encoding="UTF-8"?>
<sales>
  <book>guide-to-leanpub-formatting</book>
  <total-author-royalties type="decimal">0.0</total-author-royalties>
  <total-book-royalties type="decimal">0.0</total-book-royalties>
  <num-happy-readers type="integer">10</num-happy-readers>
  <num-happy-paid-purchases type="integer">0</num-happy-paid-purchases>
  <num-refunded-purchases type="integer">0</num-refunded-purchases>
  <unpaid-royalties type="decimal">0.0</unpaid-royalties>
  <royalties-currently-due type="decimal">0.0</royalties-currently-due>
  <royalties-due-on-first-of-next-month type="decimal">0.0</royalties-due-on-first-of-next-month>
  <paid-royalties type="decimal">0.0</paid-royalties>
</sales>


Does that help?

;ted

On Wed, Apr 30, 2014 at 2:47 PM, David Wechsler <dwec...@gmail.com> wrote:
Hey Scott,

I'm looking to try to use this in a google spreadsheet "dashboard" and I'm running into a few issues.  The first is that I am trying to see what the data that gets returned looks like.  To see how it all looks, I installed curl and tried some of the examples in the API documentation, e.g. 

C:\Program Files\cURL\bin>curl "http://leanpub.com/electricfertilizerbook/sales.
json?api_key=MY_API_KEY"

And I get:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

or with the https I get from:  curl "https://leanpub.com/electricfertilizerbook/sales.json?api_key=3wr6RR3LP1ahT00mREQiWK"

Once this gets figured out, then getting it into google docs should be a lot easier.


Thanks for your help!
-David

--
You received this message because you are subscribed to the Google Groups "leanpub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leanpub+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Patten

unread,
Apr 30, 2014, 9:09:19 PM4/30/14
to lea...@googlegroups.com
Hi David,

It looks like you're being redirected to a different capitalization of your book's slug. When I do this:


it works (replace $LEANPUB_API_KEY with your key).,

Also, Ted is completely right: you should change your API key if that is your current one.

Thanks,

Scott

David Wechsler

unread,
May 1, 2014, 9:53:37 AM5/1/14
to lea...@googlegroups.com
Hey Scott, Ted:

Thanks for your help!  It was a capitalization problem.... and I changed my API key that I forgot to edit out of my post.  It works great in google docs (I'm using an ImportJSON script I found).  

Thanks again!
-David
Reply all
Reply to author
Forward
0 new messages