Reputation: 81
i'm trying to invite a person via email to Trello from my website. Here is the API reference. When I try to invite him, the plain reply is "invalid key". Here is my function:
public function inviteEmployeeToTrello ($email, $name, $isAdmin)
{
$organazationTrelloID = 'myOrganazationID';
$trelloAuthToken = 'myTrelloAuthToken';
$trelloInviteUrl = 'https://trello.com/1/organizations/'.$organazationTrelloID.'/members';
if ($isAdmin == 1)
{
$type = 'admin';
}
else
{
$type = 'normal';
}
$fields = array(
'fullName' => $name,
'email' => $email,
'type' => $type,
'token' => $trelloAuthToken
);
// open connection
$ch = curl_init();
// set the url, number of PUT vars, PUT data
curl_setopt($ch, CURLOPT_URL, $trelloInviteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// exec
$replyRaw = curl_exec($ch);
$reply = json_decode($replyRaw, true);
// close connection
curl_close($ch);
dd($ch);
}
Upvotes: 0
Views: 898
Reputation: 21513
CURLOPT_POSTFIELDS does not want a JSON, if you want a urlencoded request, use http_build_query($fields) , or if you want a multipart/form-data request, just give it $fields array directly. (the API doc's doesn't seem to mention which request types it accept, though. urlencoded is the most common one.)
Upvotes: 1
Reputation: 10698
As the error code says, you forgot to pass your application key. Here's an example from the API reference :
https://api.trello.com/1/organizations/publicorg?members=all&member_fields=username,fullName&fields=name,desc&key=[application_key]&token=[optional_auth_token]
You have to include it in your query, hence in your case, add it to the
$fields
array :
$fields = array(
'fullName' => $name,
'email' => $email,
'type' => $type,,
'key' => $trelloAppKey
'token' => $trelloAuthToken
);
Upvotes: 1