No internet connection
  1. Home
  2. Documentation
  3. API

How to Like and Subscribe to Pages via the API

By KajMagnus @KajMagnus2021-09-15 15:04:27.458Z2021-09-15 15:27:09.043Z

You can let your users Like vote a Talkyard page, and subscribe to it via the API.

But first, read about the Talkyard API authentication, including about how to enable the API.

Now. Let your backend server, with an API secret, do as follows:

Send a POST request to /-/v0/do with this payload:

POST http://your-talkyard-site/-/v0/do  {
  doActions: [{
    asWho:  'USER_REF',
    doWhat: 'SetVote',
    doHow: {
      whatPage: 'PAGE_REF',
      whatVote: 'Like',
      howMany: 1   // 0 to delete the vote
    }
  }, {
    asWho: 'USER_REF',
    doWhat: 'SetNotfLevel',
    doHow: {
      whatPage: 'PAGE_REF'
      whatLevel: 'NewPosts'   // 'Normal' to undo
    }
  }]
}'

where:

  • USER_REF is e.g: username:someones_talkyard_username or, if you use Single Sign-On: ssoid:user-id-in-your-database
  • PAGE_REF is e.g.: pagepath:/URL-path/to/the/page/in/the/talkyard/forum e.g. pagepath:/-1234/page-slug; or pageid:1234.

Currently each action is done in its own database transaction, and the server aborts the current action and any subsequent actions, on any error. — Later, there'll be a way to you to control transactions yourself, maybe a singleTransaction: true/false JSON field.

***

Here're Typescript types for the Do API JSON request body:
https://github.com/debiki/talkyard/blob/fc86e04364aba9341078046dd7591ccfd8b773ab/tests/e2e-wdio7/pub-api.ts#L840

Here's an end-to-end test where you can see source code calling the Do API:
https://github.com/debiki/talkyard/blob/main/tests/e2e-wdio7/specs/do-api-like-and-subscribe.2br.e2e.ts
At the bottom of that file, there's a function makeLikeAndSubscribeActions() that constructs JSON for Like voting and subscribing.

  • 0 replies