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!
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.
@Andrew Walker also note there is a developer community:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.