Skip to main content
2 of 10
added 39 characters in body
Sean Allred
  • 823
  • 5
  • 16

Why is the API giving a different response for preview true/false with POST requests?

I cannot figure out how to correctly POST to the API with curl, so feel free to edit this Q to use curl if you know how. As it stands, clone SX -- Stack Exchange for Emacs! (or install M-x package-install RET sx RET from MELPA) and require sx-load.

When the following expressions are evaluated, we receive different responses.

(sx-method-call "answers"
  :id 7192
  :submethod "upvote"
  :auth 'warn
  :url-method 'post
  :keywords (list (cons 'preview 'true))             ;; NOTE
  :site "emacs")

=>
[((question_id . 7189)
  (answer_id . 7192)
  (creation_date . 1420761994)
  (last_edit_date . 1420762419)
  (last_activity_date . 1420762419)
  (score . 4)
  (is_accepted . t)
  (owner
   (link . "http://emacs.stackexchange.com/users/105/drew")
   (display_name . "Drew")
   (profile_image . "https://www.gravatar.com/avatar/32a8e553d85d193ee5ae1533ce6ec158?s=128&d=identicon&r=PG&f=1")
   (user_type . "registered")
   (user_id . 105)
   (reputation . 6689)))]

versus

(sx-method-call "answers"
  :id 7192
  :submethod "upvote"
  :auth 'warn
  :url-method 'post
  :keywords (list (cons 'preview 'false))            ;; NOTE
  :site "emacs")

=>
[((question_id . 7189)
  (answer_id . 7192)
  (creation_date . 1420761994)
  (last_edit_date . 1420762419)
  (last_activity_date . 1420762419)
  (score . 3)
  (is_accepted . t)
  (owner
   (link . "http://emacs.stackexchange.com/users/105/drew")
   (display_name . "Drew")
   (profile_image . "https://www.gravatar.com/avatar/32a8e553d85d193ee5ae1533ce6ec158?s=128&d=identicon&r=PG&f=1")
   (user_type . "registered")
   (user_id . 105)
   (reputation . 6689)))]

Note the difference:

  • when preview=true, .score=4
  • when preview=false, .score=3

However, the POST does succeed; .score is updated when you re-retrieve the answer:

(sx-method-call "answers"
  :id 7192
  :site "emacs")

=>
[((question_id . 7189)
  (answer_id . 7192)
  (creation_date . 1420761994)
  (last_edit_date . 1420762419)
  (last_activity_date . 1420762419)
  (score . 4)
  (is_accepted . t)
  (owner
   (link . "http://emacs.stackexchange.com/users/105/drew")
   (display_name . "Drew")
   (profile_image . "https://www.gravatar.com/avatar/32a8e553d85d193ee5ae1533ce6ec158?s=128&d=identicon&r=PG&f=1")
   (user_type . "registered")
   (user_id . 105)
   (reputation . 6699)))]

Note that to reproduce the issue with the elisp examples provided, you must sx-authenticate first.

Sean Allred
  • 823
  • 5
  • 16