Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Invalid Key in response to PHP cURL request for Boards

Andrew Walker
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!
July 28, 2021

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
Andrew Walker
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!
July 28, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 28, 2021

@Andrew Walker also note there is a developer community:

http://community.developer.atlassian.com

0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 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
AUG Leaders

Atlassian Community Events