5

I have been looking at the API for some time and can discern no ready answer: Is it possible to create a question using the API, which contains embedded images?

I can achieve the same by replicating the actions of the front end in code, however I can see no clear way of doing this in the API.

I value any information with evidence which you may be able to provide.

1

2 Answers 2

6

There used to be a way if you use an access token and request key from one of the Stack Exchange mobile app to upload the image. It does not work anymore now that the mobile apps have been discontinued; one of my scripts now simply tries to mimic browser requests (logging in, and using the image uploader).

You'll need to make a POST call to https://mobile.stackexchange.com/1/image/upload and supply the following parameters (as application/x-www-form-urlencoded):

  • access_token
  • key (the iOS app uses kJ1geZUa*oJVMN229qwESg((, the Android app r0aEx)wmOcRhhPMdffXeUQ(()
  • image_mime_type: image/png, image/jpeg or image/gif (other image types are not supported)
  • image_name: just a random string, doesn't really matter
  • filter: vqc7J (I have no idea which fields these correspond to, since this call is not documented)
  • image_data: the image data, encoded as Base64

If the upload succeeds, you'll get the URL back (the response is in the usual API style, a root object with an items array; there'll be a single item with a url property).

You can then use this URL in the Markdown you supply to the create question API method. Of course, it might be easier using another image hosting server, but keeping it on Stack Exchange's imgur channel is commendable.

0
2

Thanks to Shadow Wizard for confirming this: it appears that there is no facility for achieving the exact functionality of the front end, but that there is a corollary method which can be used.

Much appreciated!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .