Talkyard API authentication
To use non-public parts of the API, you need to generate an API secret: Go to https:// your talkyard site /-/admin/settings/features
and click Enable API and save the settings. Now, the API tab appears — go there and generate an API secret.
Note that this API secret is very secret — don't send it in emails to anyone, don't share it with anyone.
Then, when doing API requests from your server to Talkyard's API, include an Authorization header:
Authorization: Basic BASE64_TEXT
where BASE64_TEXT
is: tyid=2:API_SECRET
but base64 encoded. "tyid" means Talkyard ID, and 2 is the Sysbot user id.
So, tyid=2
means that the API request is being done as the Sysbot user (Sysbot is a Talkyard user intended for API requests. There's also a System user with id 1 but it cannot do API requests).
And API_SECRET
is the API secret you generated in the API tab.
Linked from:
- JJoão Ferreira @joao.parana
Hi @KajMagnus, can you post an curl request example here ?
Tanks in advance.
- KajMagnus @KajMagnus2020-06-04 10:35:37.458Z2020-06-04 11:20:47.024Z
Hi João, yes, see below, from an end-to-end test that upserst an external user into Talkyard's databse. (Just a test, not any real secrets.)
Notice theAuthorization: Basic ...
line.curl \ -X POST \ -H 'Content-Type: application/json' \ -H 'Authorization: Basic dGFsa3lhcmRJZD0yOmQ3angxMzhseHZ0ODlqbzNmeW1lY29hcnk=' \ -d '{"ssoId":"mariasSsoId","primaryEmailAddress":"e2e-test--maria@example.com","isEmailAddressVerified":true,"username":"maria","fullName":"Maria"}' \ http://e2e-test-cid-0-0-now-6669.localhost/-/v0/sso-upsert-user-generate-login-secret [0-0] Now you can try: http://e2e-test-cid-0-0-now-6669.localhost/-/v0/login-with-secret?oneTimeSecret=61f99pz5cx0iecsutnbu596p4&thenGoTo=/ [0-0] ... gets back a one time login secret [0-0] Got back login secret: 61f99pz5cx0iecsutnbu596p4 [0-0] ... redirects Maria to the Talkyard login-with-secret endpoint [0-0] Go: http://e2e-test-cid-0-0-now-6669.localhost/-/v0/login-with-secret?oneTimeSecret=61f99pz5cx0iecsutnbu596p4&thenGoTo=/by-michael-category-a
(the e2e tests log the API requests they make, as cURL requests, for debugging / developer friendliness)
The above request should be the same as:
curl --user tyid=2:d7jx138lxvt89jo3fymecoary http://e2e-test-cid-0-0-now-6669.localhost/-/v0/ ...
whered7jx138lxvt89jo3fymecoary
is the API secret (just a dummy test secret).
... Oh it's not, instead, the above request uses a deprecatedtalkyardId=2:d7jx138lxvt89jo3fymecoary
format. Should be:tyid= ...
nowadays.If you go here:
https:// your server /-/admin/api
and click Show for an API Secret, you'll see thatcurl --user ...
line.