-1

I am trying to create a comment on my card whenever a card is created on my trello board. I have access to my Api key and Token.

    $json = file_get_contents("php://input");
    $data = json_decode($json,true);
    $fp = fopen("myjson.txt",'w');
    fwrite($fp,$json);
    fclose($fp);
    $id = (string) $data["action"]["data"]["card"]["id"];
    $actionThatTriggered = (string) $data["action"]["type"];

   if($actionThatTriggered == "createCard"){
     $ch = curl_init();
     curl_setopt($ch,CURLOPT_URL,"https://api.trello.com/1/cards/".$id."/actions/comments?text=hello+world&key=".$apikey."&token=".$tokennumber);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
     curl_setopt($ch,CURLOPT_POST,true);
     curl_setopt($ch,CURLOPT_HEADER,false);
     $server_response = curl_exec($ch);
     curl_close($ch);
}

I am able to store the response from webhook in myjson.txt but unable to send a curl POST request to comment on the card which is created. I have hosted this file on a apache2 server which is running.

Also when i am running this script independently through my kernel, i can see a new comment made on my card. I think there is some issue with hosting a file on a server.

I am new to web stuff, so a detailed explanation will be really helpful.

1 Answers1

0

By Default, json_decode returns the object, if you wish to returns the output in associative array, you will have to pass the 2nd argument as boolean value "true". So, replace 2nd line with following:

$data = json_decode($json, true);
Farhan
  • 253
  • 2
  • 9