mattermost-community / focalboard

Focalboard is an open source, self-hosted alternative to Trello, Notion, and Asana.
https://www.focalboard.com
Other
21.9k stars 1.97k forks source link

Question: Focalboard api not working as expected in the mattermost boards #4420

Closed IamGroot19 closed 1 year ago

IamGroot19 commented 1 year ago

Summary

Unable to perform operations on the integrated focalboard via API. Also, no mention of focalboard api in mattermost docs.

Expected behavior

I installed a preview version of mattermost via docker container (from these instructins. Ensured plugin is enabled and mattermost board is enabled. I want to perform operations on the mattermost board via API. For eg, writing a script to migrate our issues from another tool (say phabricator or gitlab issues) to focalboard. But I am unable to find any documentation around this. i tried the API endpoints mentioned in focalboard docs but they are not working either.

Few queries that i tried

// query related to teams (from mattermost api)
$ curl -X GET -H "Authorization: Bearer wjd5jd9amby7bd59ye4cgo3egy"    "http://127.0.0.1:8065/api/v4/teams"

[{"id":"6mnza3dgwiy7785ndk95ohbdsy","create_at":1672779224457,"update_at":1672779224457,"delete_at":0,"display_name":"sem","name":"sem","description":"","email":"trial@gmail.com","type":"O","company_name":"","allowed_domains":"","invite_id":"ukwofmfxn3yo389cngyrgouz9y","allow_open_invite":false,"scheme_id":null,"group_constrained":null,"policy_id":null,"cloud_limits_archived":false}]

// few queries related to boards
$ curl -X GET -H "Authorization: Bearer wjd5jd9amby7bd59ye4cgo3egy"    "http://127.0.0.1:8065/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><meta name="robots" content="noindex, nofollow"><meta name="referrer" content="no-referrer"><title>Mattermost</title><meta name="mobile-web-app-capable" content="yes"><meta name="application-name" content="Mattermost"><meta name="format-detection" content="telephone=no"><link rel="icon" type="image/png" href="/static/images/favicon/favicon-default-16x16.png" sizes="16x16"><link rel="icon" type="image/png" href="/static/images/favicon/favicon-default-24x24.png" sizes="24x24"><link rel="icon" type="image/png" href="/static/images/favicon/favicon-default-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/static/images/favicon/favicon-default-64x64.png" sizes="64x64"><link rel="icon" type="image/png" href="/static/images/favicon/favicon-default-96x96.png" sizes="96x96"><link rel="stylesheet" class="code_theme"><style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style><meta http-equiv="Content-Security-Policy" content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3"><script defer="defer" src="/static/main.94bef8661903342eb099.js"></script><meta name="apple-mobile-web-app-title" content="Mattermost" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="default" /><link rel="apple-touch-icon" sizes="76x76" href="/static/icon_76x76.png" /><link rel="apple-touch-icon" sizes="72x72" href="/static/icon_72x72.png" /><link rel="apple-touch-icon" sizes="60x60" href="/static/icon_60x60.png" /><link rel="apple-touch-icon" sizes="57x57" href="/static/icon_57x57.png" /><link rel="apple-touch-icon" sizes="152x152" href="/static/icon_152x152.png" /><link rel="apple-touch-icon" sizes="144x144" href="/static/icon_144x144.png" /><link rel="apple-touch-icon" sizes="120x120" href="/static/icon_120x120.png" /><link rel="manifest" href="/static/manifest.json" /></head><body class="font--open_sans enable-animations"><div id="root"><div class="error-screen"><h2>Cannot connect to Mattermost</h2><hr/><p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p><br/></div><div class="loading-screen" style="position:relative"><div class="loading__content"><div class="round round-1"></div><div class="round round-2"></div><div class="round round-3"></div></div></div></div><div id="root-portal"></div><noscript>To use Mattermost, please enable JavaScript.</noscript></body></html>

$ curl -X GET -H "Authorization: Bearer wjd5jd9amby7bd59ye4cgo3egy"    "http://127.0.0.1:8065/api/v2/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"
{"id":"api.context.404.app_error","message":"Sorry, we could not find the page.","detailed_error":"There doesn't appear to be an api call for the url='/api/v2/teams/6mnza3dgwiy7785ndk95ohbdsy/boards'.  Typo? are you missing a team_id or user_id as part of the url?","status_code":404}

$ curl -X GET -H "Authorization: Bearer wjd5jd9amby7bd59ye4cgo3egy"    "http://127.0.0.1:8065/api/v4/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"

{"id":"api.context.404.app_error","message":"Sorry, we could not find the page.","detailed_error":"There doesn't appear to be an api call for the url='/api/v4/teams/6mnza3dgwiy7785ndk95ohbdsy/boards'.  Typo? are you missing a team_id or user_id as part of the url?","status_code":404}bharath@tpx13:~/Documents/mnet_specific/SEM/sem-codebase/phab-migration/mattermost$ 

Observed behavior (that appears unintentional)

Pls advise with regards how to use API for boards. NOTE: I had previously opened an issue at mattermost-server repo (https://github.com/mattermost/mattermost-server/issues/21981) but was asked to reopen it here

sbishel commented 1 year ago

@wiggin77 - Could you help out with Boards API?

wiggin77 commented 1 year ago

@IamGroot19 the Focalboard API docs are here. There is a problem with the publisher not picking up some of the data structs but it will provide a list of APIs and same curl command.

IamGroot19 commented 1 year ago

@wiggin77 Yes, I am aware of the docs for focalboard API. But my question was different. I had enabled mattermost boards in the matermost server and tried to make a few API calls (based on the API documentation you had also pointed out). But I am not getting the response I expected.

For eg, the /teams/:teamID/boards API endpoint provides a response saying (pls chk rhe issue description):

We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.

I am not sure which of the following is the case: a) I am making some mistake in the API call b) The documentation is not clear enough c) The integration of focalboard into mattermost has some bug & hence there is an issue with API call.

For referennce, I ran a local setup of mattermost server on the "preview mode" via a docker container. (Also, i ensured that mattermost board was enabled in the server settings).

My apologies if I didnt frame the question clearly in the issue's description.

wiggin77 commented 1 year ago

@IamGroot19 I see the docs have the incorrect URL prefix for running Boards as a plugin. For example:

http://localhost:8065/api/v2/teams/{teamID}/boards should be http://localhost:8065/plugins/focalboard/api/v2/teams/{teamID}/boards

Also, you'll need to provide CSRF tokens as described here.

IamGroot19 commented 1 year ago

@wiggin77 I went thru the article you linked regarding CSRF token & still have trouble making requests. Would appreciate some help.

Obtaining CSRF token

$ curl -i -d '{"login_id":"bsr", "password":"12345"}' -H "X-Requested-With: XMLHttpRequest" http://localhost:8065/api/v4/users/login
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: MMAUTHTOKEN=6xorca7qg3rz3nk4soduqt7gqh; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000; HttpOnly
Set-Cookie: MMUSERID=tnouobug9tg6xnx354gzjon93r; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000
Set-Cookie: MMCSRF=gzi675msziyj8dauocmz4g1hjc; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000
Token: 6xorca7qg3rz3nk4soduqt7gqh
Vary: Accept-Encoding
X-Request-Id: og5t6yypjjdcjqe3cpunhc6qbh
X-Version-Id: 7.5.2.7.5.2.d491c2db3a5411d22519e52c3623ef9e.false
Date: Thu, 12 Jan 2023 07:56:36 GMT
Content-Length: 711

Using CSRF token

// trial 1
$ curl -H "Authorization: Bearer gzi675msziyj8dauocmz4g1hjc" "http://localhost:8065/plugins/focalboard/api/v2/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"
{"error":"checkCSRFToken FAILED","errorCode":400}

// trial 2
$ curl -H "Authorization: Token gzi675msziyj8dauocmz4g1hjc" "http://localhost:8065/plugins/focalboard/api/v2/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"
{"error":"checkCSRFToken FAILED","errorCode":400}
IamGroot19 commented 1 year ago

Update (for someone else who stumbles upon similar issue):

After a bit of trial & error, I figured out correct set of headers.:

// Get the CSRF token first 
$ curl -i -d '{"login_id":"bsr", "password":"12345"}' -H "X-Requested-With: XMLHttpRequest" http://localhost:8065/api/v4/users/login
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: MMAUTHTOKEN=6xorca7qg3rz3nk4soduqt7gqh; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000; HttpOnly
Set-Cookie: MMUSERID=tnouobug9tg6xnx354gzjon93r; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000
Set-Cookie: MMCSRF=gzi675msziyj8dauocmz4g1hjc; Path=/; Expires=Sat, 11 Feb 2023 07:56:36 GMT; Max-Age=2592000
Token: 6xorca7qg3rz3nk4soduqt7gqh
Vary: Accept-Encoding
X-Request-Id: og5t6yypjjdcjqe3cpunhc6qbh
X-Version-Id: 7.5.2.7.5.2.d491c2db3a5411d22519e52c3623ef9e.false
Date: Thu, 12 Jan 2023 07:56:36 GMT
Content-Length: 711

// Then use the csrf + auth token like:
$ curl -H "Authorization: Bearer 6xorca7qg3rz3nk4soduqt7gqh" -H "X-CSRF-Token: gzi675msziyj8dauocmz4g1hjc"  -H "X-Requested-With: XMLHttpRequest"   "http://localhost:8065/plugins/focalboard/api/v2/teams/6mnza3dgwiy7785ndk95ohbdsy/boards"