Create card from template using API

Viktor Potesil
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 4, 2024

I use following query in python to create a Trello card with checklist from template.

It works fine, but the problem is that an extra card get created duplicating the template.

So I have desired card named "Daily Tasks 2024-08-04" as well as extra card named " Daily tasks - template" both cards have checklist.

What am I doing wrong? I hoped the the 'keepFromSource': 'checklists', will help to resolve the problem, but it still does not work as desired.

import requests 
import datetime

# Trello API credentials
API_KEY = 'zzzz'
API_TOKEN = 'xxxx'
BOARD_ID = '5acf8b8faffb00d3bedf0b00'
LIST_ID = '5acf8d5ad1499e477fadc006'
TEMPLATE_CARD_ID = '669bf1242ea083cf40ab6c90'
# Trello API endpoint to create a card
url = "https://api.trello.com/1/cards"

# Card details
card_name = f"Daily Tasks {datetime.datetime.now().strftime('%Y-%m-%d')}"
card_desc = "This is an automated task created every morning."

query = {
   'key': API_KEY,
   'token': API_TOKEN,
   'idList': LIST_ID,
   'idCardSource': TEMPLATE_CARD_ID,
   'keepFromSource': 'checklists',
   'name': card_name,
   'desc': card_desc
}

response = requests.request("POST", url, params=query)

if response.status_code == 200:
   print("Card created successfully.")

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events