iPetitions is a free service that allows anyone to create an online petition and distribute a link for people to virtually sign it. To date their website claims they have collected over 25 million signatures collectively across their petitions.
At work there was a need to take the number of signatures from a petition on iPetitions and display it across the campus on our digital signs.
I first contacted iPetitions Support and asked if they had an API that I could use to get this value from a particular petition. This was their response:
No, we do not have any interface that would serve only for that. Naturally, you can see the number of signatories on any particular petition, but you can transfer that number manually (retype it, basically), or utilize our widget (which shows the number of signatures on a petition, but you cannot separate just that part).
I first thought to myself "You don't have an API, Really?" (See here for why you should have an API) and I found their suggestion that I manually retype the number as signatures came in each time quite humorous.
I took a look at their widget and while it did provide a way to embed the number of signatures on the petition on an external website. It didn't offer any flexibility on how to display or format the number so this wouldn't work. We needed the number to fit into a specific campaign and it had to look seemless.
Due to the lack of an API I thought I would write my own. I wrote a PHP script that parses the elements out of the widget HTML and return the number of signatures in XML form so that I could then easily parse into our digital signage system like so:
This allows me to get the number of signatures into our system and format it as needed. I've open sourced this script so you can implement signatures from iPetition's petitions in your projects:
Note: My script can break at anytime due to iPetitions changing their code.
I hope this helps someone out.