Page MenuHomePhabricator

API result for submodule=new-topic: no easy way to get info about the just-posted topic
Closed, ResolvedPublic

Description

I posted a topic to a Flow board using the action=flow&submodule=new-topic web API module, resulting in the following post: https://test.wikipedia.org/wiki/Topic:S7xiyvpkn2y1s1t9.

The following Python code is part of a test script for a bot I'm writing, and posts a new topic to the specified Flow board:

def postflow(page, topic, message, site):
"""testing posting a new Flow topic through the API"""
token = site.get_token('csrf')
cooptitle = 'Wikipedia:Co-op/Mentorship match'
kwargs = {'action': 'flow',
'page': cooptitle,
'submodule': 'new-topic',
'token': token,
'nttopic': topic,
'ntcontent': message,
'workflow': 's7hjfbzj7bjwke99'}
query2 = site.api(**kwargs)
return query2

Calling this in the Python interpreter, as:

>>> flowpost2 = mbapi.postflow('page', 'test topic', 'test message', site)
>>> pprint.pprint(flowpost2)

yields the following result: https://gist.github.com/fhocutt/62f7b05c3f4e1e2f0dac

My bot needs to log the timestamp and post or topic ID of the topics it posts. I was expecting to find some portion of the API result that was more like the response to action=edit, which returns the newrevid and the newtimestamp, so:

{u'contentmodel': u'wikitext',
 u'newrevid': 219714,
 u'newtimestamp': u'2014-12-14T05:32:09Z',
 u'oldrevid': 218886,
 u'pageid': 68971,
 u'result': u'Success',
 u'title': u'Sandbox'}

The documentation at https://www.mediawiki.org/wiki/Extension:Flow/API also suggests that the result should include values for created-topic-id and created-post-id:

<?xml version="1.0"?><api>
  <flow>
    <new-topic status="ok">
      <result>
        <topiclist created-topic-id="rwwggvyb8pz4w54x" created-post-id="rwwggvyfx3a2wpa9" />
      </result>
    </new-topic>
  </flow>
</api>

Instead, the ID and timestamp (along with a lot of other information) are provided for every single topic on the page, and I can't find any way to identify which one is the just-posted topic besides comparing the timestamps for all the topics to find the most recent one.

Could the API result for submodule=new-topic requests include some easy way to find details about the topic created?

Event Timeline

• Fhocutt raised the priority of this task from to Needs Triage.
• Fhocutt updated the task description. (Show Details)
• Fhocutt changed Security from none to None.
• Fhocutt subscribed.

TopicList.php's commit() returns an array with the created-topic-id, but the function isn't documented as returning anything and I don't think any caller does anything with the info since WorkflowLoader was changed in some rewrite..

Change 180588 had a related patch set uploaded (by EBernhardson):
Add commit metadata to api response and flag for onlymetadata

https://gerrit.wikimedia.org/r/180588

Patch-For-Review

EBernhardson triaged this task as Medium priority.

Change 180588 merged by jenkins-bot:
Add commit metadata to api response and flag for metadataonly

https://gerrit.wikimedia.org/r/180588

Change 180980 had a related patch set uploaded (by Mattflaschen):
Add commit metadata to api response and flag for metadataonly

https://gerrit.wikimedia.org/r/180980

Patch-For-Review

Change 180980 abandoned by Mattflaschen:
Add commit metadata to api response and flag for metadataonly

Reason:
Wrong branch

https://gerrit.wikimedia.org/r/180980

Change 180981 had a related patch set uploaded (by Mattflaschen):
Add commit metadata to api response and flag for metadataonly

https://gerrit.wikimedia.org/r/180981

Patch-For-Review

Change 180981 merged by jenkins-bot:
Add commit metadata to api response and flag for metadataonly

https://gerrit.wikimedia.org/r/180981

As Architecture/Flow/API now says, add ntmetadataonly=true to API request on testwiki and you get back an abbreviated response containing the following.

{
 "warnings": {
   "main": {
     "*": "Unrecognized parameter: 'ntreplyTo'"
   }  
 },
 "flow": {
   "new-topic": {
     "status": "ok",
     "workflow": "rl8xwn9lohyq4rjs",
     "committed": {
       "topiclist": {
         "topic-page": "Topic:S887bk82yb5i96wd",
         "topic-id": "s887bk82yb5i96wd",
         "topic-revision-id": "s887bk84ifl5ldm5",
         "post-id": "s887bk84ihk6pfl9",
         "post-revision-id": "s887bk84ihk6pfl9"
       }      
     }    
   }  
 }
}