How to send an action using a webhook in trello?

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.

What is the HTTP response that you get back? Can you share the responses message and data?

1 Like

@bentley Thanks a lot taking time and replying, I have managed to get it work there was some problem with the permissions of the file to which callBackURL was directing. Once again thank you and as I am building something out of trello’s API I will be needing your help in future for sure. Cheers!