Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,231
Community Members
 
Community Events
165
Community Groups

Invalid Key in response to PHP cURL request for Boards

I am just starting into the Trello API so I am certain I have done something basic wrong. I want to get a list of the Boards for my account, so I am doing a GET request. I pass my API Key and the token from authorizing on my account. I am doing this in PHP with no special libraries in use. My code looks like this:

$ch = curl_init('https://api.trello.com/1/members/NY_USERNAME/boards');
$trello_params = array('token' => 'MY_TOKEN', 'key' => 'MY_KEY');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $trello_params);
$ch_return = curl_exec($ch);
echo 'Returned: ' . $ch_return;

All I ever get back is "invalid key." Please help!

2 answers

1 accepted

1 vote
Answer accepted

The page you linked is where I started. :)

I did suspect MY_KEY is the problem. As you suggested, I went to Postman and tried the request from there. I got exactly the response I hoped to get from the PHP query, so the token and key are valid.

I figured out the problem is how I am making the request in PHP. The URL needs to contain the key and token instead of having them in the post fields. So I removed the POSTFIELDS line, changed the init to not have a parameter, and then set the URL cURL option using a URL with the key and token. My revised code is something like this:

$ch = curl_init();
$base_url = 'https://api.trello.com/1/members/MYUSERNAME/boards';
$trello_params = array('token' => 'MY_TOKEN', 'key' => 'MY_KEY');
$trello_data = http_build_query($trello_params);
$trello_url = $base_url . '?' . $trello_data;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $trello_url);
$ch_return = curl_exec($ch);
echo 'Returned: ' . $ch_return;

I hope this helps anyone else who encounters this issue.

Iain Dooley Community Leader Jul 28, 2021

@Andrew Walker also note there is a developer community:

http://community.developer.atlassian.com

0 votes
Hana Kučerová Community Leader Jul 28, 2021

Hi @Andrew Walker ,

welcome to the Atlassian Community!

"invalid key" means - something is wrong with key 'MY_KEY' (as you probably suspect)

Have you seen this page how to obtain token and key?

I would recommend you to use some app like Postman to test the token and key and then proceed with the PHP script, if you know, you are able to authenticate with these.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Trello

Taco Tuesday: New years' resolutions with Trello

Congratulations to @Laura Holton , our latest winner of Taco Tuesday! And thanks to @Kristján Geir Mathiesen for sharing the picture of Taco having fun with his new friend  B...

2,352 views 28 40
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you