Using API to create posts and topics

Unsolved Technical Support
  • Can anyone provide the correct syntax to use when creating posts or topics via the API ?

    The documentation is a little lacking in this area - or perhaps I missed it.

    Thanks

  • Hi, @phenomlab!

    Calls to create:

    • a topic - /api/v3/topics/ (docs);
    • a post - /api/v3/topics/{tid} (docs).

    In my project I call the /api/v3/topics/ to create a new topic via Python and requests lib:

    data = {
        "cid": int(cid),
        "title": entry.title,
        "content": '\n'.join(description),
        "tags": tags
    }
    headers = {'Authorization': 'Bearer {token}'.format(token=os.environ.get('NODEBB_TOKEN'))}
    url = '{host}/api/v3/topics/'.format(host=os.environ.get('NODEBB_URL'))
    
    response = requests.post(
        url=url,
        headers=headers,
        json=data
    )
    response.raise_for_status()
    
  • @antosik excellent. Thanks very much.


Suggested Topics