Trello - Updating a cards position and color at the same time

Viewed 199

I'm trying to have my board update based on some results and having a hard time finding the best way to update both a card's position and the color. The idea is to have a card update based on a result, red and to the top to catch my attention; but if everything is working correctly, then green and to the bottom.

So far I have:

def updateCard():
    url = f"https://api.trello.com/1/cards/{CARD_ID}/cover"

    headers = {
       "Accept": "application/json"
    }

    query = {
       'key': API_KEY,
       'token': OAUTH_TOKEN,
       'name': 'New Title',
       'desc': 'New Description',
       'pos': 'bottom',
       'value': {'color': 'green'}
    }

    response = requests.request(
       "PUT",
       url,
       headers=headers,
       json=query
    )

    print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

The pseudo code is from: https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put and added my own variables.

I noticed that for changing the color, I need to pass the json variable in the response, and have the URL end with '/cover'. However, this does not work when trying to update the position. If I take the /cover out of the URL, then the position gets updated. Is there a way to have both update at the same time.

Thanks in advance!

2 Answers

I don't know Trello's API, and I can't test it without setting up a developer account, but my instinct is that you might be able to change your query like so:

. . .

url = f"https://api.trello.com/1/cards/{CARD_ID}"

. . .

query = {
       'key': API_KEY,
       'token': OAUTH_TOKEN,
       'value': {
           'name': 'New Title',
           'desc': 'New Description',
           'pos': 'bottom',
           'cover': {'color': 'green'}
       }
    }

It looks like "cover" is a nested object under the "card" object, so you can just put an object in that field. When you're updating the card's position, you should be going for the card object directly, not the /cover field. You would use the /cover endpoint if you intended your request only to be scoped to the cover of the card.

EDIT: Trying a new request format

The workaround to this issue so far (and if anyone has a better syntax, feel free to add a comment):

url = f"https://api.trello.com/1/cards/{CARD_ID}"
url_cover = f"https://api.trello.com/1/cards/{CARD_ID}/cover"

headers = {
   "Accept": "application/json"
}

query = {
   'key': API_KEY,
   'token': OAUTH_TOKEN,
   'name': 'New Title 3',
   'desc': 'New Description',
   'pos': 'top'
}

json = {
        'key': API_KEY,
        'token': OAUTH_TOKEN,
        'value': {
        'brightness': 'dark',
        'color': card_color,
        'size': 'full'}}

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

response = requests.request(
   "PUT",
   url_cover,
   headers=headers,
   json=json
)
Related