[SOLVED] Using cURL in Php to call subscribe to functions on particle API

I have been trying to use the cloud API, i have followed the documentations and got the header to work, but when whole trying to do the body, I have been having trouble with it.

This is what i have been trying to follow

This method worked for me while using curl on terminal, but not im trying to attempt the same thing using php.

$ curl https://api.particle.io/v1/devices/events \
       -d "name=myevent" \
       -d "data=Hello World" \
       -d "private=true" \
       -d "ttl=60" \
       -d "access_token=1234"

This is my code on php

                    $header = array(
                    "Authorization:Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                $body = array(
                    "name: turnpm",
                    "data: led-on",
                    "private: false",
                    "access_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

                $ch= curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, TRUE);
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                $output = curl_exec($ch);
                echo $output;

This is my particle code

    void setup() {
      Particle.subscribe("turnpm", myHandler);

    void myHandler(const char *event, const char *data)

    ########## code ###########


The result that i get from all that

{"ok":false,"error":"event name is required"}

I’m suspecting the body not being sent correctly. The name, or the data arent being found within the API. i’m not sure what to do at this point I have checked my syntax in the php and everything seems to be in order. help would be really appreciated.


Fixed with changing

curl_setopt($ch, CURLOPT_POSTFIELDS, $body);


curl_setopt($ch, CURLOPT_POSTFIELDS, "name=turnpm&data=led-off&....");