Extension:StructuredDiscussions/API

Most Flow API read and write interactions are submodules of. Flow also implements a query property  and a parsing utility module.

= Detection =

(details below) is one way to check if Flow is enabled on the specified pages.

You can alternatively use  to retrieve page info including content model. The content model will be 'flow-board' if it's enabled. Compare Special:ApiSandbox and Special:ApiSandbox.

In client-side JavaScript (for gadgets and user scripts), call.

= action=flow =

(Since this edit operation has to be an HTTP POST, the link in the generated example above won't work.)

Replying
In a reply you're replying to a particular post in a workflow (a topic). Flow objects are identified by UUIDs see Flow/Architecture.

To reply to a topic action=flow submodule=reply format=json repreplyTo=050fed5dc6bd5085237590b11c2fa805 repcontent=My reply, with wikitext.
 * you'll need a token. Flow recently switched to using the regular 'edit' token for most operations, so you can use  to get the editing token if it hasn't been cached yet in the session. it's cached.
 * Issue a  API request with , identifying the topic workflow. The parameters for a reply include the topic and the post.

render=true token=43a71deb105e7c0be7e8eeab4bdff4f7+\ workflow=050f698e3f6e5624fa1590b11c27932f
 * Set  if you want the server to respond with the "fully-decorated" HTML to interact with the new post (preview buttons, actions, etc.).
 * UUID format will soon change to be more compact, using 88-bit represented as alphadecimal.
 * Obviously you get the topic and post to respond by making API queries, rather than hardcoding these numbers.

Note that a wiki may store Flow content with  'html' or 'wikitext', but in any edit submission you must submit wikitext.

If successful, the server responds with the  of the new post, and the HTML to insert into the DOM.

Note this API request doesn't name the page on which the topic appears. Users interact with topics on a Flow board with a wiki page name, but a topic might (eventually) appear on multiple pages, e.g. a user's "subscription feed".

On WMF wikis, Flow stores post content as HTML with embedded Parsoid markup so that something resembling the original wikitext can be reconstituted for editing. This will not be the case on all wikis, others might store as wikitext.

Block requests
When you make a "Block" API request such as, the API normally returns a   containing updated information about the top 10 topics on the board, including their HTML. This allows the Flow board to redisplay the board contents, but it can be a lot of data.

If you are just trying to add a topic and you're not interested in the board contents, you should pass the flag  (180588)

Flow returns the metadata in a top-level  key in the API response. For consistency the information about the new content is returned as topic-page, topic-id, topic-revision-id, post-id, header-post-id (but see T84954), etc.

Editing the board header
If you want to update the Flow board header, it's similar
 * make a GET request  to get the current contents. This will return a   including a UUID of the most recent version of the header in , and its contents in.
 * make a POST request, . Set   to the revision returned by the GET request and set   to your updated wikitext.

The update may fail with  if someone else updated this board's header between the two requests; if so the return has a   giving the new latest revision, so you can retry with that. However, you should avoid clobbering the previous editors' work (e.g. by presenting an edit conflict form, or re-running the algorithm if a bot is making the requests, etc.).

Posting a new topic from on-wiki JavaScript
If an on-wiki user script or gadget needs to be post a new topic, the best way is to use MessagePoster. The advantage is that you don't need to know whether the talk pages uses old-style talk pages or Flow. It will work either way (LiquidThreads is not supported).

= action=flow-parsoid-utils =