api.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # vi:ts=4:et
  4. # Wekan API Python CLI, originally from here, where is more details:
  5. # https://github.com/wekan/wekan/wiki/New-card-with-Python3-and-REST-API
  6. # TODO:
  7. # addcustomfieldtoboard: There is error: Settings must be object. So adding does not work yet.
  8. try:
  9. # python 3
  10. from urllib.parse import urlencode
  11. except ImportError:
  12. # python 2
  13. from urllib import urlencode
  14. import json
  15. import requests
  16. import sys
  17. arguments = len(sys.argv) - 1
  18. syntax = """=== Wekan API Python CLI: Shows IDs for addcard ===
  19. # AUTHORID is USERID that writes card or custom field.
  20. If *nix: chmod +x api.py => ./api.py users
  21. Syntax:
  22. User API:
  23. python3 api.py user # Current user and list of current user boards
  24. python3 api.py boards USERID # Boards of USERID
  25. python3 api.py swimlanes BOARDID # Swimlanes of BOARDID
  26. python3 api.py lists BOARDID # Lists of BOARDID
  27. python3 api.py list BOARDID LISTID # Info of LISTID
  28. python3 api.py createlist BOARDID LISTTITLE # Create list
  29. python3 api.py addcard AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION
  30. python3 api.py editcard BOARDID LISTID CARDID NEWCARDTITLE NEWCARDDESCRIPTION
  31. python3 api.py customfields BOARDID # Custom Fields of BOARDID
  32. python3 api.py customfield BOARDID CUSTOMFIELDID # Info of CUSTOMFIELDID
  33. python3 api.py addcustomfieldtoboard AUTHORID BOARDID NAME TYPE SETTINGS SHOWONCARD AUTOMATICALLYONCARD SHOWLABELONMINICARD SHOWSUMATTOPOFLIST # Add Custom Field to Board
  34. python3 api.py editcustomfield BOARDID LISTID CARDID CUSTOMFIELDID NEWCUSTOMFIELDVALUE
  35. python3 api.py listattachments BOARDID # List attachments
  36. python3 api.py cardsbyswimlane SWIMLANEID LISTID
  37. python3 api.py getcard BOARDID LISTID CARDID
  38. python3 api.py addlabel BOARDID LISTID CARDID LABELID
  39. python3 api.py addcardwithlabel AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION LABELIDS
  40. python3 api.py editboardtitle BOARDID NEWBOARDTITLE
  41. python3 api.py createlabel BOARDID LABELCOLOR LABELNAME (Color available: `white`, `green`, `yellow`, `orange`, `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`, `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`, `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`, `indigo`)
  42. python3 api.py editcardcolor BOARDID LISTID CARDID COLOR (Color available: `white`, `green`, `yellow`, `orange`, `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`, `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`, `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`, `indigo`)
  43. python3 api.py addchecklist BOARDID CARDID TITLE ITEM1 ITEM2 ITEM3 ITEM4 (You can add multiple items or just one, or also without any item, just TITLE works as well. * If items or Title contains spaces, you should add ' between them.)
  44. Admin API:
  45. python3 api.py users # All users
  46. python3 api.py boards # All Public Boards
  47. python3 api.py newuser USERNAME EMAIL PASSWORD
  48. """
  49. if arguments == 0:
  50. print(syntax)
  51. exit
  52. # TODO:
  53. # print(" python3 api.py attachmentjson BOARDID ATTACHMENTID # One attachment as JSON base64")
  54. # print(" python3 api.py attachmentbinary BOARDID ATTACHMENTID # One attachment as binary file")
  55. # print(" python3 api.py attachmentdownload BOARDID ATTACHMENTID # One attachment as file")
  56. # print(" python3 api.py attachmentsdownload BOARDID # All attachments as files")
  57. # ------- SETTINGS START -------------
  58. # Username is your Wekan username or email address.
  59. # OIDC/OAuth2 etc uses email address as username.
  60. username = 'testtest'
  61. password = 'testtest'
  62. wekanurl = 'http://localhost:4000/'
  63. # ------- SETTINGS END -------------
  64. """
  65. === ADD CUSTOM FIELD TO BOARD ===
  66. Type: text, number, date, dropdown, checkbox, currency, stringtemplate.
  67. python3 api.py addcustomfieldtoboard cmx3gmHLKwAXLqjxz LcDW4QdooAx8hsZh8 "SomeField" "date" "" true true true true
  68. === USERS ===
  69. python3 api.py users
  70. => abcd1234
  71. === BOARDS ===
  72. python3 api.py boards abcd1234
  73. === SWIMLANES ===
  74. python3 api.py swimlanes dYZ
  75. [{"_id":"Jiv","title":"Default"}
  76. ]
  77. === LISTS ===
  78. python3 api.py lists dYZ
  79. []
  80. There is no lists, so create a list:
  81. === CREATE LIST ===
  82. python3 api.py createlist dYZ 'Test'
  83. {"_id":"7Kp"}
  84. # python3 api.py addcard AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION
  85. python3 api.py addcard ppg dYZ Jiv 7Kp 'Test card' 'Test description'
  86. === LIST ATTACHMENTS WITH DOWNLOAD URLs ====
  87. python3 api.py listattachments BOARDID
  88. """
  89. # ------- API URL GENERATION START -----------
  90. loginurl = 'users/login'
  91. wekanloginurl = wekanurl + loginurl
  92. apiboards = 'api/boards/'
  93. apiattachments = 'api/attachments/'
  94. apiusers = 'api/users'
  95. apiuser = 'api/user'
  96. apiallusers = 'api/allusers'
  97. e = 'export'
  98. s = '/'
  99. l = 'lists'
  100. sw = 'swimlane'
  101. sws = 'swimlanes'
  102. cs = 'cards'
  103. cf = 'custom-fields'
  104. bs = 'boards'
  105. apbs = 'allpublicboards'
  106. atl = 'attachmentslist'
  107. at = 'attachment'
  108. ats = 'attachments'
  109. users = wekanurl + apiusers
  110. user = wekanurl + apiuser
  111. allusers = wekanurl + apiallusers
  112. # ------- API URL GENERATION END -----------
  113. # ------- LOGIN TOKEN START -----------
  114. data = {"username": username, "password": password}
  115. body = requests.post(wekanloginurl, json=data)
  116. d = body.json()
  117. apikey = d['token']
  118. # ------- LOGIN TOKEN END -----------
  119. if arguments == 10:
  120. if sys.argv[1] == 'addcustomfieldtoboard':
  121. # ------- ADD CUSTOM FIELD TO BOARD START -----------
  122. authorid = sys.argv[2]
  123. boardid = sys.argv[3]
  124. name = sys.argv[4]
  125. type1 = sys.argv[5]
  126. settings = str(json.loads(sys.argv[6]))
  127. # There is error: Settings must be object. So this does not work yet.
  128. #settings = {'currencyCode': 'EUR'}
  129. print(type(settings))
  130. showoncard = sys.argv[7]
  131. automaticallyoncard = sys.argv[8]
  132. showlabelonminicard = sys.argv[9]
  133. showsumattopoflist = sys.argv[10]
  134. customfieldtoboard = wekanurl + apiboards + boardid + s + cf
  135. # Add Custom Field to Board
  136. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  137. post_data = {'authorId': '{}'.format(authorid), 'name': '{}'.format(name), 'type': '{}'.format(type1), 'settings': '{}'.format(settings), 'showoncard': '{}'.format(showoncard), 'automaticallyoncard': '{}'.format(automaticallyoncard), 'showlabelonminicard': '{}'.format(showlabelonminicard), 'showsumattopoflist': '{}'.format(showsumattopoflist)}
  138. body = requests.post(customfieldtoboard, data=post_data, headers=headers)
  139. print(body.text)
  140. # ------- ADD CUSTOM FIELD TO BOARD END -----------
  141. if arguments == 8:
  142. if sys.argv[1] == 'addcardwithlabel':
  143. # ------- ADD CARD WITH LABEL START -----------
  144. authorid = sys.argv[2]
  145. boardid = sys.argv[3]
  146. swimlaneid = sys.argv[4]
  147. listid = sys.argv[5]
  148. cardtitle = sys.argv[6]
  149. carddescription = sys.argv[7]
  150. labelIds = sys.argv[8] # Aggiunto labelIds
  151. cardtolist = wekanurl + apiboards + boardid + s + l + s + listid + s + cs
  152. # Add card
  153. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  154. post_data = {
  155. 'authorId': '{}'.format(authorid),
  156. 'title': '{}'.format(cardtitle),
  157. 'description': '{}'.format(carddescription),
  158. 'swimlaneId': '{}'.format(swimlaneid),
  159. 'labelIds': labelIds
  160. }
  161. body = requests.post(cardtolist, data=post_data, headers=headers)
  162. print(body.text)
  163. # If ok id card
  164. if body.status_code == 200:
  165. card_data = body.json()
  166. new_card_id = card_data.get('_id')
  167. # Updating card
  168. if new_card_id:
  169. edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + new_card_id
  170. put_data = {'labelIds': labelIds}
  171. body = requests.put(edcard, data=put_data, headers=headers)
  172. print("=== EDIT CARD ===\n")
  173. body = requests.get(edcard, headers=headers)
  174. data2 = body.text.replace('}', "}\n")
  175. print(data2)
  176. else:
  177. print("Error obraining ID.")
  178. else:
  179. print("Error adding card.")
  180. # ------- ADD CARD WITH LABEL END -----------
  181. if arguments == 7:
  182. if sys.argv[1] == 'addcard':
  183. # ------- ADD CARD START -----------
  184. authorid = sys.argv[2]
  185. boardid = sys.argv[3]
  186. swimlaneid = sys.argv[4]
  187. listid = sys.argv[5]
  188. cardtitle = sys.argv[6]
  189. carddescription = sys.argv[7]
  190. cardtolist = wekanurl + apiboards + boardid + s + l + s + listid + s + cs
  191. # Add card
  192. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  193. post_data = {'authorId': '{}'.format(authorid), 'title': '{}'.format(cardtitle), 'description': '{}'.format(carddescription), 'swimlaneId': '{}'.format(swimlaneid)}
  194. body = requests.post(cardtolist, data=post_data, headers=headers)
  195. print(body.text)
  196. # ------- ADD CARD END -----------
  197. if arguments == 6:
  198. if sys.argv[1] == 'editcard':
  199. # ------- EDIT CARD START -----------
  200. boardid = sys.argv[2]
  201. listid = sys.argv[3]
  202. cardid = sys.argv[4]
  203. newcardtitle = sys.argv[5]
  204. newcarddescription = sys.argv[6]
  205. edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid
  206. print(edcard)
  207. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  208. put_data = {'title': '{}'.format(newcardtitle), 'description': '{}'.format(newcarddescription)}
  209. body = requests.put(edcard, data=put_data, headers=headers)
  210. print("=== EDIT CARD ===\n")
  211. body = requests.get(edcard, headers=headers)
  212. data2 = body.text.replace('}',"}\n")
  213. print(data2)
  214. # ------- EDIT CARD END -----------
  215. if sys.argv[1] == 'editcustomfield':
  216. # ------- EDIT CUSTOMFIELD START -----------
  217. boardid = sys.argv[2]
  218. listid = sys.argv[3]
  219. cardid = sys.argv[4]
  220. customfieldid = sys.argv[5]
  221. newcustomfieldvalue = sys.argv[6]
  222. edfield = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid + s + 'customFields' + s + customfieldid
  223. #print(edfield)
  224. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  225. post_data = {'_id': '{}'.format(customfieldid), 'value': '{}'.format(newcustomfieldvalue)}
  226. #print(post_data)
  227. body = requests.post(edfield, data=post_data, headers=headers)
  228. print("=== EDIT CUSTOMFIELD ===\n")
  229. data2 = body.text.replace('}',"}\n")
  230. print(data2)
  231. # ------- EDIT CUSTOMFIELD END -----------
  232. if arguments == 5:
  233. if sys.argv[1] == 'addlabel':
  234. # ------- EDIT CARD ADD LABEL START -----------
  235. boardid = sys.argv[2]
  236. listid = sys.argv[3]
  237. cardid = sys.argv[4]
  238. labelIds = sys.argv[5]
  239. edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid
  240. print(edcard)
  241. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  242. put_data = {'labelIds': labelIds}
  243. body = requests.put(edcard, data=put_data, headers=headers)
  244. print("=== ADD LABEL ===\n")
  245. body = requests.get(edcard, headers=headers)
  246. data2 = body.text.replace('}',"}\n")
  247. print(data2)
  248. # ------- EDIT CARD ADD LABEL END -----------
  249. if sys.argv[1] == 'editcardcolor':
  250. # ------- EDIT CARD COLOR START -----------
  251. boardid = sys.argv[2]
  252. listid = sys.argv[3]
  253. cardid = sys.argv[4]
  254. newcolor = sys.argv[5]
  255. valid_colors = ['white', 'green', 'yellow', 'orange', 'red', 'purple', 'blue', 'sky', 'lime', 'pink', 'black',
  256. 'silver', 'peachpuff', 'crimson', 'plum', 'darkgreen', 'slateblue', 'magenta', 'gold', 'navy',
  257. 'gray', 'saddlebrown', 'paleturquoise', 'mistyrose', 'indigo']
  258. if newcolor not in valid_colors:
  259. print("Invalid color. Choose a color from the list.")
  260. sys.exit(1)
  261. edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid
  262. print(edcard)
  263. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  264. put_data = {'color': '{}'.format(newcolor)}
  265. body = requests.put(edcard, data=put_data, headers=headers)
  266. print("=== EDIT CARD COLOR ===\n")
  267. body = requests.get(edcard, headers=headers)
  268. data2 = body.text.replace('}', "}\n")
  269. print(data2)
  270. # ------- EDIT CARD COLOR END -----------
  271. if arguments >= 4:
  272. if sys.argv[1] == 'newuser':
  273. # ------- CREATE NEW USER START -----------
  274. username = sys.argv[2]
  275. email = sys.argv[3]
  276. password = sys.argv[4]
  277. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  278. post_data = {'username': '{}'.format(username),'email': '{}'.format(email),'password': '{}'.format(password)}
  279. body = requests.post(users, data=post_data, headers=headers)
  280. print("=== CREATE NEW USER ===\n")
  281. print(body.text)
  282. # ------- CREATE NEW USER END -----------
  283. if sys.argv[1] == 'getcard':
  284. # ------- LIST OF CARD START -----------
  285. boardid = sys.argv[2]
  286. listid = sys.argv[3]
  287. cardid = sys.argv[4]
  288. listone = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid
  289. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  290. print("=== INFO OF ONE LIST ===\n")
  291. print("URL:", listone) # Stampa l'URL per debug
  292. try:
  293. response = requests.get(listone, headers=headers)
  294. print("=== RESPONSE ===\n")
  295. print("Status Code:", response.status_code) # Stampa il codice di stato per debug
  296. if response.status_code == 200:
  297. data2 = response.text.replace('}', "}\n")
  298. print(data2)
  299. else:
  300. print(f"Error: {response.status_code}")
  301. print(f"Response: {response.text}")
  302. except Exception as e:
  303. print(f"Error in the GET request: {e}")
  304. # ------- LISTS OF CARD END -----------
  305. if sys.argv[1] == 'createlabel':
  306. # ------- CREATE LABEL START -----------
  307. boardid = sys.argv[2]
  308. labelcolor = sys.argv[3]
  309. labelname = sys.argv[4]
  310. label_url = wekanurl + apiboards + boardid + s + 'labels'
  311. print(label_url)
  312. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  313. # Object to send
  314. put_data = {'label': {'color': labelcolor, 'name': labelname}}
  315. print("URL:", label_url)
  316. print("Headers:", headers)
  317. print("Data:", put_data)
  318. try:
  319. response = requests.put(label_url, json=put_data, headers=headers)
  320. print("=== CREATE LABELS ===\n")
  321. print("Response Status Code:", response.status_code)
  322. print("Response Text:", response.text)
  323. except Exception as e:
  324. print("Error:", e)
  325. # ------- CREATE LABEL END -----------
  326. if sys.argv[1] == 'addchecklist':
  327. # ------- ADD CHECKLIST START -----------
  328. board_id = sys.argv[2]
  329. card_id = sys.argv[3]
  330. checklist_title = sys.argv[4]
  331. # Aggiungi la checklist
  332. checklist_url = wekanurl + apiboards + board_id + s + cs + s + card_id + '/checklists'
  333. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  334. data = {'title': checklist_title}
  335. response = requests.post(checklist_url, data=data, headers=headers)
  336. response.raise_for_status()
  337. result = json.loads(response.text)
  338. checklist_id = result.get('_id')
  339. print(f"Checklist '{checklist_title}' created. ID: {checklist_id}")
  340. # Aggiungi gli items alla checklist
  341. items_to_add = sys.argv[5:] # Gli argomenti successivi sono considerati come titoli degli items
  342. for item_title in items_to_add:
  343. checklist_item_url = wekanurl + apiboards + board_id + s + cs + s + card_id + s + 'checklists' + s + checklist_id + '/items'
  344. item_data = {'title': item_title}
  345. item_response = requests.post(checklist_item_url, data=item_data, headers=headers)
  346. item_response.raise_for_status()
  347. item_result = json.loads(item_response.text)
  348. checklist_item_id = item_result.get('_id')
  349. print(f"Item '{item_title}' added. ID: {checklist_item_id}")
  350. if arguments == 3:
  351. if sys.argv[1] == 'editboardtitle':
  352. # ------- EDIT BOARD TITLE START -----------
  353. boardid = sys.argv[2]
  354. boardtitle = sys.argv[3]
  355. edboardtitle = wekanurl + apiboards + boardid + s + 'title'
  356. print(edboardtitle)
  357. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  358. post_data = {'title': boardtitle}
  359. body = requests.put(edboardtitle, json=post_data, headers=headers)
  360. print("=== EDIT BOARD TITLE ===\n")
  361. #body = requests.get(edboardtitle, headers=headers)
  362. data2 = body.text.replace('}',"}\n")
  363. print(data2)
  364. if body.status_code == 200:
  365. print("Succesfull!")
  366. else:
  367. print(f"Error: {body.status_code}")
  368. print(body.text)
  369. # ------- EDIT BOARD TITLE END -----------
  370. if sys.argv[1] == 'createlist':
  371. # ------- CREATE LIST START -----------
  372. boardid = sys.argv[2]
  373. listtitle = sys.argv[3]
  374. list = wekanurl + apiboards + boardid + s + l
  375. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  376. post_data = {'title': '{}'.format(listtitle)}
  377. body = requests.post(list, data=post_data, headers=headers)
  378. print("=== CREATE LIST ===\n")
  379. print(body.text)
  380. # ------- CREATE LIST END -----------
  381. if sys.argv[1] == 'list':
  382. # ------- LIST OF BOARD START -----------
  383. boardid = sys.argv[2]
  384. listid = sys.argv[3]
  385. listone = wekanurl + apiboards + boardid + s + l + s + listid
  386. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  387. print("=== INFO OF ONE LIST ===\n")
  388. body = requests.get(listone, headers=headers)
  389. data2 = body.text.replace('}',"}\n")
  390. print(data2)
  391. # ------- LISTS OF BOARD END -----------
  392. if sys.argv[1] == 'customfield':
  393. # ------- INFO OF CUSTOM FIELD START -----------
  394. boardid = sys.argv[2]
  395. customfieldid = sys.argv[3]
  396. customfieldone = wekanurl + apiboards + boardid + s + cf + s + customfieldid
  397. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  398. print("=== INFO OF ONE CUSTOM FIELD ===\n")
  399. body = requests.get(customfieldone, headers=headers)
  400. data2 = body.text.replace('}',"}\n")
  401. print(data2)
  402. # ------- INFO OF CUSTOM FIELD END -----------
  403. if sys.argv[1] == 'cardsbyswimlane':
  404. # ------- RETRIEVE CARDS BY SWIMLANE ID START -----------
  405. boardid = sys.argv[2]
  406. swimlaneid = sys.argv[3]
  407. cardsbyswimlane = wekanurl + apiboards + boardid + s + sws + s + swimlaneid + s + cs
  408. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  409. print("=== CARDS BY SWIMLANE ID ===\n")
  410. print("URL:", cardsbyswimlane) # Debug
  411. try:
  412. body = requests.get(cardsbyswimlane, headers=headers)
  413. print("Status Code:", body.status_code) # Debug
  414. data = body.text.replace('}', "}\n")
  415. print("Data:", data)
  416. except Exception as e:
  417. print("Error GET:", e)
  418. # ------- RETRIEVE CARDS BY SWIMLANE ID END -----------
  419. if arguments == 2:
  420. # ------- BOARDS LIST START -----------
  421. userid = sys.argv[2]
  422. boards = users + s + userid + s + bs
  423. if sys.argv[1] == 'boards':
  424. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  425. #post_data = {'userId': '{}'.format(userid)}
  426. body = requests.get(boards, headers=headers)
  427. print("=== BOARDS ===\n")
  428. data2 = body.text.replace('}',"}\n")
  429. print(data2)
  430. # ------- BOARDS LIST END -----------
  431. if sys.argv[1] == 'board':
  432. # ------- BOARD INFO START -----------
  433. boardid = sys.argv[2]
  434. board = wekanurl + apiboards + boardid
  435. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  436. body = requests.get(board, headers=headers)
  437. print("=== BOARD ===\n")
  438. data2 = body.text.replace('}',"}\n")
  439. print(data2)
  440. # ------- BOARD INFO END -----------
  441. if sys.argv[1] == 'customfields':
  442. # ------- CUSTOM FIELDS OF BOARD START -----------
  443. boardid = sys.argv[2]
  444. boardcustomfields = wekanurl + apiboards + boardid + s + cf
  445. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  446. body = requests.get(boardcustomfields, headers=headers)
  447. print("=== CUSTOM FIELDS OF BOARD ===\n")
  448. data2 = body.text.replace('}',"}\n")
  449. print(data2)
  450. # ------- CUSTOM FIELDS OF BOARD END -----------
  451. if sys.argv[1] == 'swimlanes':
  452. boardid = sys.argv[2]
  453. swimlanes = wekanurl + apiboards + boardid + s + sws
  454. # ------- SWIMLANES OF BOARD START -----------
  455. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  456. print("=== SWIMLANES ===\n")
  457. body = requests.get(swimlanes, headers=headers)
  458. data2 = body.text.replace('}',"}\n")
  459. print(data2)
  460. # ------- SWIMLANES OF BOARD END -----------
  461. if sys.argv[1] == 'lists':
  462. # ------- LISTS OF BOARD START -----------
  463. boardid = sys.argv[2]
  464. lists = wekanurl + apiboards + boardid + s + l
  465. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  466. print("=== LISTS ===\n")
  467. body = requests.get(lists, headers=headers)
  468. data2 = body.text.replace('}',"}\n")
  469. print(data2)
  470. # ------- LISTS OF BOARD END -----------
  471. if sys.argv[1] == 'listattachments':
  472. # ------- LISTS OF ATTACHMENTS START -----------
  473. boardid = sys.argv[2]
  474. listattachments = wekanurl + apiboards + boardid + s + ats
  475. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  476. print("=== LIST OF ATTACHMENTS ===\n")
  477. body = requests.get(listattachments, headers=headers)
  478. data2 = body.text.replace('}',"}\n")
  479. print(data2)
  480. # ------- LISTS OF ATTACHMENTS END -----------
  481. if arguments == 1:
  482. if sys.argv[1] == 'users':
  483. # ------- LIST OF USERS START -----------
  484. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  485. print(users)
  486. print("=== USERS ===\n")
  487. body = requests.get(users, headers=headers)
  488. data2 = body.text.replace('}',"}\n")
  489. print(data2)
  490. # ------- LIST OF USERS END -----------
  491. if sys.argv[1] == 'user':
  492. # ------- LIST OF ALL USERS START -----------
  493. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  494. print(user)
  495. print("=== USER ===\n")
  496. body = requests.get(user, headers=headers)
  497. data2 = body.text.replace('}',"}\n")
  498. print(data2)
  499. # ------- LIST OF ALL USERS END -----------
  500. if sys.argv[1] == 'boards':
  501. # ------- LIST OF PUBLIC BOARDS START -----------
  502. headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
  503. print("=== PUBLIC BOARDS ===\n")
  504. listpublicboards = wekanurl + apiboards
  505. body = requests.get(listpublicboards, headers=headers)
  506. data2 = body.text.replace('}',"}\n")
  507. print(data2)
  508. # ------- LIST OF PUBLIC BOARDS END -----------