alphagov / e-petitions

This is the code base for the UK Government's e-petitions service (https://petition.parliament.uk)
https://petition.parliament.uk
MIT License
307 stars 78 forks source link

API Documentation #417

Closed liamnichols closed 8 years ago

liamnichols commented 8 years ago

This isn't really an issue, but more of a question..

I understand there is a REST API available for the website however I can't seem to find any documentation around the API... Is this available somewhere?

If it was in a really obvious place then my bad but if not then maybe it would be a good idea to provide a developer portal or some help pages referencing to it?

Thanks, Liam

pixeltrix commented 8 years ago

@liamnichols we haven't written any formal documentation yet but essentially the /petitions.json and /petitions/:id.json HTTP endpoints are probably what you're looking for. There's no authentication required for accessing the API. There's also no rate limiting since it's read-only but that may change if it gets abused (probably will happen at some point).

liamnichols commented 8 years ago

Ah, thanks for getting back to me... I found those, but also noticed that there were various query parameters that could be passed to filter the content and was wondering if they were documented?

I guess I could look through the source code to figure all this out but i'm more of a mobile developer so i'm not that familiar with it all...

Also, are you able to sign petitions or create new ones via the API?

Liam

pixeltrix commented 8 years ago

@liamnichols there are 3 query parameters which can be passed to /petitions.json - they are:

  1. q - a search string that will filter the results by PostgreSQL full-text search
  2. state - one of a pre-defined set of petition lists which defaults to 'all'
  3. page - a number indicating which page of results should be returned (numbered from 1 and fixed at 50 per page)

Also, are you able to sign petitions or create new ones via the API?

Not currently, for obvious reasons that it would make it easier for people to script signing and petition creation. Also it could be abused to make people sign a petition thinking one thing whereas it was another petition entirely so we want to control what people see when signing for their protection.

gazzwi86 commented 8 years ago

What is the likelihood of a post endpoint being opened up in the future?

henryhadlow commented 8 years ago

@gazzwi86 pretty much zero – the potential for abuse is too great. What use did you have in mind?

en-rphillips commented 8 years ago

On a similar topic, are you planning to expose anything for the "trending" petitions? I'm interested in data vis stuff, and this would be useful for me. @henryhadlow

pixeltrix commented 8 years ago

It would be pretty simple to add an API endpoint for trending petitions - just a matter of taking the query from the homepage and generating some JSON. Maybe it'd be better to just do a JSON template for the home page?

en-rphillips commented 8 years ago

@pixeltrix - Something which might offer more utility could be to accept date range params on /petitions.json ?

henryhadlow commented 8 years ago

@en-rphillips what use for this functionality did you have in mind?

en-rphillips commented 8 years ago

@henryhadlow I would like to show petition signing trends when mapped against news events (targeted roughly with date ranges).

e.g. after trump wins iowa - petition to bar trump from uk get's signed 200k+ times in 24hrs

at the moment my list of petitions always has the same popular stuff at the top

henryhadlow commented 8 years ago

That would be pretty interesting. That would require trending petitions over time. Probably just volume of signatures over time for each petition would be more generally useful. I'll look into the priority of this against other stuff we want to look at.

On 31 March 2016 at 14:29, Rob Phillips notifications@github.com wrote:

@henryhadlow https://github.com/henryhadlow I would like to show petition signing trends when mapped against news events (targeted roughly with date ranges).

e.g. after trump wins iowa - petition to bar trump from uk get's signed 200k+ times in 24hrs

at the moment my list of petitions always has the same popular stuff at the top

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/alphagov/e-petitions/issues/417#issuecomment-203935924

Henry Hadlow Product Manager GOV.UK Notify https://www.gov.uk/government/publications/govuk-notify/govuk-notify • petition.parliament.uk Government Digital Service https://gds.blog.gov.uk/