How to archive cards with the api ?

sebastien_margheriti
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!
February 4, 2025

Hello, I'm using the trello api with PHP to add, update and archive cards on a specific board.

When I want to archive cards (with archiveAllCards), I get the following error (only with this function. No errors with the rest) : 

 

unauthorized permission requested

2 answers

1 accepted

1 vote
Answer accepted
DiMaggio Tucci
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2025

Do you only get that error with that function?

Have you already authorized your application using these steps? If not, you can't just start making API calls; you have to go through that process first.

Are you including the token and key in the correct order/format, as detailed here?

 

Without more information, it's hard to say. But an "unauthorized" error leads me to believe this has something to do with that part of the request.

sebastien_margheriti
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!
February 4, 2025

I get this error only with this function yes. 

Creating a new card is working for example. Getting all the cards from a list is also okay.

When creating my token, I gave the permissions read, write and account.

 

EDIT : updating the name of a list is also NOT working. 

So getting cards, adding cards is work.
Delete cards, update name of the list, is not working

DiMaggio Tucci
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2025

@sebastien_margheriti 

Can you post what the call looks like (don't post your ACTUAL sensitive information, just indicate where it is in the call)

sebastien_margheriti
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!
February 4, 2025

<?php
require_once 'vendor/autoload.php';


$headers = array(
'Accept' => 'application/json'
);

$query = array(
'key' => 'my_api_key',
'token' => 'my_token',
);

$response = Unirest\Request::post(
'https://api.trello.com/1/lists/67a1db506b41865c9f1b9370/archiveAllCards',
$query
);

echo '<pre>';
var_dump($response);
echo '</pre>';

?>

sebastien_margheriti
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!
February 4, 2025

I found my mistake. I didn't include the $headers in the post call !

Unirest\Request::post(
'https://api.trello.com/1/lists/67a1db506b41865c9f1b9370/archiveAllCards',
$headers,
$query
);

Like this, it's working now.

The code in the documentation API is also incorrect in PHP (it doesn't include the headers) :

https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-archiveallcards-post

DiMaggio Tucci
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2025

So glad to hear it! Let me know if I can be of further assistance. Sometimes all it takes is a rubber duck!

 

I think headers are assumed after they are explained in the documentation, which can be confusing.

Like sebastien_margheriti likes this
0 votes
Rasmus Wulff Jensen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2025

The API call needs to be a POST call and look like this:

https://api.trello.com/1/lists/<listId>/archiveAllCards?key=<key>&token=<token>

 I've just tested on a Test-board of mine and there it worked as expected

Also make sure your token is a read/write token (but given your can add cards that should be covered)

Suggest an answer

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

Atlassian Community Events