Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Planka API with cURL #736

Closed
staze0 opened this issue May 2, 2024 · 2 comments
Closed

Request Planka API with cURL #736

staze0 opened this issue May 2, 2024 · 2 comments

Comments

@staze0
Copy link

staze0 commented May 2, 2024

Hello,

I try to automate things in Planka and between my other tools and Planka so I dig into the API but I am struggling with modification requests (here card creation, but I have tried other modification request too).

My configuration is:

  • Planka version = 1.17.1

Here a sample of my tests.


  1. Request to get the token / Result : OK
curl.exe -d 'emailOrUsername=USER&password=PWD' https://FQDN/api/access-tokens
{"item":"TOKEN"}
  1. Request to get data of one of my card / Result : OK
curl.exe -X GET -H "Authorization: Bearer TOKEN" https://FQDN/api/cards/1237021017109432278
{"item":{"id":"1237021017109432278","createdAt":"2024-05-02T13:19:56.604Z","updatedAt":"2024-05-02T20:20:47.425Z","position":65535,"name":"NAME","description":"DESCRIPTION","dueDate":"2024-05-08T10:00:00.000Z","stopwatch":{"total":21600,"startedAt":null},"boardId":"1202247906392802324","listId":"1202252203985732663","creatorUserId":"1202234652308276232","coverAttachmentId":null,"isSubscribed":false},"included":{"cardMemberships":[{"id":"1237026330009143262","createdAt":"2024-05-02T13:30:29.951Z","updatedAt":null,"cardId":"1237021017109432278","userId":"1202234652308276232"}],"cardLabels":[{"id":"1237021060637919192","createdAt":"2024-05-02T13:20:01.797Z","updatedAt":null,"cardId":"1237021017109432278","labelId":"1202256498315494469"},{"id":"1237021084436400089","createdAt":"2024-05-02T13:20:04.635Z","updatedAt":null,"cardId":"1237021017109432278","labelId":"1202255848886240321"}],"tasks":[],"attachments":[]}}

We can see the boardId and listId.
-> boardId = 1202247906392802324
-> listId = 1202252203985732663

  1. Request to create a card regarding the routes defined here (https://github.com/plankanban/planka/blob/ecc45c7a9eb77e0e38bbbb1880a42c72d088fb99/server/config/routes.js) / Result : NOK
curl.exe -X POST -H "Authorization: Bearer TOKEN" https://FQDN/api/boards/1202247906392802324/cards/
{"code":"E_NOT_FOUND"}
  1. Request to create a card with another method describe here (https://github.com/hwelch-fle/plankapy/blob/master/plankapy.py#L429) / Result : NOK but I get an explicit error message
curl.exe -X POST -H "Authorization: Bearer TOKEN" https://FQDN/api/lists/1202252203985732663/cards
{"code":"E_MISSING_OR_INVALID_PARAMS","problems":["\"name\" is required, but it was not defined."],"message":"The server could not fulfill this request (`POST /api/lists/1202252203985732663/cards`) due to 1 missing or invalid parameter."}
  1. Request with the missing parameter 'name' / Result : NOK
curl.exe -d 'name=TEST&listId=1202252203985732663' -X POST -H "Authorization: Bearer TOKEN" https://FQDN/api/lists/1202252203985732663/cards
  1. Finally when I try to get infos on this list with the endpoint /api/lists/<listId> I am getting this
curl.exe -X GET -H "Authorization: Bearer TOKEN" https://FQDN/api/lists/1202252203985732663
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="https://FQDN.be/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Planka is an open source project management software"/><link rel="apple-touch-icon" href="logo192.png"/><link rel="manifest" href="https://FQDN.be/manifest.json"/><title>Planka</title><script defer="defer" src="https://FQDN.be/static/js/main.1c3bb07c.js"></script><link href="https://FQDN/static/css/main.86a2be8a.css" rel="stylesheet"></head><script>window.BASE_URL="https://FQDN"</script><body id="app"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

So, I am wondering if anyone have already done this kind of thing with positive result and how if it is the case? I am aware of the documentation about API (https://docs.planka.cloud/docs/category/api) but I want to make it simple with request that can be done in almost every automation tool.

Thanks in advance for the help.

@meltyshev
Copy link
Member

Hi! I've just tried to create a card and this worked for me:

curl -X POST -H 'Authorization: Bearer TOKEN' -d 'name=test&position=123' http://localhost:1337/api/lists/869469508069229768/cards

5. Request to create a card regarding the routes defined here (ecc45c7/server/config/routes.js) / Result : NOK

curl.exe -X POST -H "Authorization: Bearer TOKEN" https://FQDN/api/boards/1202247906392802324/cards/
{"code":"E_NOT_FOUND"}

You seem to be referring to a 2 year old commit, the actual routes are here: https://github.com/plankanban/planka/blob/master/server/config/routes.js.

11. Finally when I try to get infos on this list with the endpoint /api/lists/<listId> I am getting this

curl.exe -X GET -H "Authorization: Bearer TOKEN" https://FQDN/api/lists/1202252203985732663
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="https://FQDN.be/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Planka is an open source project management software"/><link rel="apple-touch-icon" href="logo192.png"/><link rel="manifest" href="https://FQDN.be/manifest.json"/><title>Planka</title><script defer="defer" src="https://FQDN.be/static/js/main.1c3bb07c.js"></script><link href="https://FQDN/static/css/main.86a2be8a.css" rel="stylesheet"></head><script>window.BASE_URL="https://FQDN"</script><body id="app"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

There is no such endpoint, all lists can be retrieved by querying the entire board. But we've already added it in the v2 :)

@staze0
Copy link
Author

staze0 commented May 5, 2024

Hello @meltyshev

Thank you for your time and explanation. I step back and realize that even if my account was "Project Manager" of the project, he was not able to do anything on boards. After I add the rights to modify on boards, I was able to do what I want to do with cURL and web requests.

In conclusion, I consider my problem as resolved but maybe the error message need to be modify to specify that rights is not good because here I had an error message that the listId does not exist. It is purely details but if I had a message like "Your user do not have right to modify board/lists/whatever", I figured out the solution much faster.

Thanks again.

@staze0 staze0 closed this as completed May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants