Start a new topic
Answered

Push Data in PHP

Hello


Someone as an exemple to push data to lametric in PHP


The sample in JSON  is




curl -X POST \

-H "Accept: application/json" \

-H "X-Access-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \

-H "Cache-Control: no-cache" \

-d '{

    "frames": [

        {

            "index": 0,

            "goalData": {

                "start": 100,

                "current": 84,

                "end": 75,

                "unit": "Kg"

            },

            "icon": "i173"

        }

    ]

}' \

https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.xxxxxxxxxxxxxx



in red the data i want push


Tank's for your help


Cyril


Best Answer

This should do it:


<?php


$url = "LAMETRIC_ENDPOINT_URL";


$frames = array(

 "frames" => array(

 array(

 'index' => 0,

 'goalData' => array(

 'start' => 100,

 'current' => 84,

 'end' => 75,

 'unit' => 'Kg'

 )

)

 )

);


$curl = curl_init();


$headers = array(

"Accept: application/json",

"X-Access-Token: YOUR_ACCESS_TOKEN",

"Cache-Control: no-cache",

);


curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($frames));



$response = curl_exec($curl);

curl_close($curl);


?>


1 person has this question

I am asking to myself, how to do this in PHP? I try to do this with curl but I don't get it.

Answer

This should do it:


<?php


$url = "LAMETRIC_ENDPOINT_URL";


$frames = array(

 "frames" => array(

 array(

 'index' => 0,

 'goalData' => array(

 'start' => 100,

 'current' => 84,

 'end' => 75,

 'unit' => 'Kg'

 )

)

 )

);


$curl = curl_init();


$headers = array(

"Accept: application/json",

"X-Access-Token: YOUR_ACCESS_TOKEN",

"Cache-Control: no-cache",

);


curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($frames));



$response = curl_exec($curl);

curl_close($curl);


?>

Login or Signup to post a comment