Strawpolls are great, and we use them in chat all the time for getting opinions on things. But they're kinda annoying to make since you need a webbrowser to make them, and everyone knows that I access PPCG only through SE APIs and curl. So I want you to write some code that uses Strawpoll's API to make a strawpoll with the given options.


Take as input a list in any reasonable format of options as strings, and a title which is also a string. Then use the API to make a strawpoll with that title and those options and output the url.

Multiples should not be allowed, duplicate checking should be enforced, and captchas should not be necessary.


"My Awesome Poll"
["option 1", "I like pies", "I also like cakes"]

Output: http://strawpoll.me/7275997

This is , so shortest code in bytes wins!

  • 2
    \$\begingroup\$ (Just to help everyone) TL;DR: do this: https://strawpoll.me/api/v2/polls{"title":"This is a test poll.","options":["Option #1","Option #2"],"multi": true} \$\endgroup\$ – Leaky Nun Apr 4 '16 at 7:26
  • 1
    \$\begingroup\$ "NOTE: You must specify a "Content-Type: application/json" header in your request." \$\endgroup\$ – Leaky Nun Apr 4 '16 at 7:27
  • \$\begingroup\$ The API sort of doesn't work, or at least it doesn't work like the docs say it does \$\endgroup\$ – cat Apr 9 '16 at 21:32
  • \$\begingroup\$ https://strawpoll.me/api/v2/polls always responds with http 400 \$\endgroup\$ – cat Apr 9 '16 at 21:33
  • \$\begingroup\$ Are you required to return the strawpoll in http://? Can I return in https:// instead? \$\endgroup\$ – Value Ink Apr 10 '16 at 1:56

Factor, 257 262 bytes

TUPLE: p title options dupcheck ;
[ command-line rest [ first ] [ rest ] bi "normal" p boa >json "https://strawpoll.me/api/v2/polls" <post-request> "application/json" "Content-Type" set-header http-request nip json> id>> 10 base> "http://strawpoll.me/" prepend ]

Expects a name as the first command-line arg, then options after that.

Requires com-auto-use.


TUPLE: poll
  title options dupcheck ;

: post-json ( post-data url -- response data )
    "application/json" "Content-Type" set-header
  http-request ;

: strawpoll-main ( -- )
  command-line rest [ first ] [ rest ] bi "normal" poll boa
  >json "https://strawpoll.me/api/v2/polls" post-json nip
  json> id>> 10 base> "http://strawpoll.me/" prepend print ;

Ruby 2.2.4 + HTTParty: 129 bytes

Anonymous function; returns a string with the strawpoll URL. Remember to install the HTTParty gem before running.


If the URL can be returned with https:// instead of http://, 126 bytes:

  • \$\begingroup\$ Did you set the Content-Type: application/json header? \$\endgroup\$ – cat Apr 10 '16 at 11:15
  • \$\begingroup\$ I got a proper response back, so I'd assume that HTTParty does that for me already. \$\endgroup\$ – Value Ink Apr 10 '16 at 21:53
  • \$\begingroup\$ This gem won't install, which is really annoying since I'd like to figure out why I keep getting HTTP 400. \$\endgroup\$ – cat Apr 10 '16 at 23:14
  • \$\begingroup\$ What's your Ruby version? I updated mine to the version I have, and the gem says it needs 1.9.3+ \$\endgroup\$ – Value Ink Apr 10 '16 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.