From 42e4bc31059f17cea825275a6a82357f9889848b Mon Sep 17 00:00:00 2001 From: Mirko Genovese Date: Wed, 7 Feb 2024 16:03:03 +0100 Subject: [PATCH] Update api.py Add card with label and add a label to a card --- api.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/api.py b/api.py index fa9b8de61..205bfcd6a 100755 --- a/api.py +++ b/api.py @@ -41,6 +41,8 @@ If *nix: chmod +x api.py => ./api.py users python3 api.py listattachments BOARDID # List attachments python3 api.py cardsbyswimlane BOARDID LISTID python3 api.py getcard BOARDID LISTID CARDID + python3 api.py addlabel BOARDID LISTID CARDID LABELID + python3 api.py addcardwithlabel AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION LABELIDS Admin API: python3 api.py users # All users @@ -181,6 +183,52 @@ if arguments == 10: print(body.text) # ------- ADD CUSTOM FIELD TO BOARD END ----------- +if arguments == 8: + + if sys.argv[1] == 'addcardwithlabel': + # ------- ADD CARD WITH LABEL START ----------- + authorid = sys.argv[2] + boardid = sys.argv[3] + swimlaneid = sys.argv[4] + listid = sys.argv[5] + cardtitle = sys.argv[6] + carddescription = sys.argv[7] + labelIds = sys.argv[8] # Aggiunto labelIds + + cardtolist = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + # Add card + headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)} + post_data = { + 'authorId': '{}'.format(authorid), + 'title': '{}'.format(cardtitle), + 'description': '{}'.format(carddescription), + 'swimlaneId': '{}'.format(swimlaneid), + 'labelIds': labelIds + } + + body = requests.post(cardtolist, data=post_data, headers=headers) + print(body.text) + + # If ok id card + if body.status_code == 200: + card_data = body.json() + new_card_id = card_data.get('_id') + + # Updating card + if new_card_id: + edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + new_card_id + put_data = {'labelIds': labelIds} + body = requests.put(edcard, data=put_data, headers=headers) + print("=== EDIT CARD ===\n") + body = requests.get(edcard, headers=headers) + data2 = body.text.replace('}', "}\n") + print(data2) + else: + print("Error obraining ID.") + else: + print("Error adding card.") + # ------- ADD CARD WITH LABEL END ----------- + if arguments == 7: if sys.argv[1] == 'addcard': @@ -239,6 +287,26 @@ if arguments == 6: print(data2) # ------- EDIT CUSTOMFIELD END ----------- +if arguments == 5: + + if sys.argv[1] == 'addlabel': + + # ------- EDIT CARD ADD LABEL START ----------- + boardid = sys.argv[2] + listid = sys.argv[3] + cardid = sys.argv[4] + labelIds = sys.argv[5] + edcard = wekanurl + apiboards + boardid + s + l + s + listid + s + cs + s + cardid + print(edcard) + headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)} + put_data = {'labelIds': labelIds} + body = requests.put(edcard, data=put_data, headers=headers) + print("=== ADD LABEL ===\n") + body = requests.get(edcard, headers=headers) + data2 = body.text.replace('}',"}\n") + print(data2) + # ------- EDIT CARD ADD LABEL END ----------- + if arguments == 4: if sys.argv[1] == 'newuser':