Rest API on PHP with curl

Give me please work example how to connet to the rest API

I tried it this way, but it doesn’t work

<?php // options $EMAIL = 'admin'; $PASSWORD = 'pass'; $cookie_file_path = "/tmp/cookies.txt"; $LOGINURL = "https:/192.168.0.1/rest/system/resource"; $agent = "Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)"; // begin script $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; // basic curl options for all requests curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); // set first URL curl_setopt($ch, CURLOPT_URL, $LOGINURL); // execute session to get cookies and required form inputs $content = curl_exec($ch); // grab the hidden inputs from the form required to login $fields = getFormFields($content); $fields['emailAddress'] = $EMAIL; $fields['acctPassword'] = $PASSWORD; // get x value that is used in the login url $x = ''; if (preg_match('/op\.asp\?x=(\d+)/i', $content, $match)) { $x = $match[1]; } // set postfields using what we extracted from the form $POSTFIELDS = http_build_query($fields); // change URL to login URL curl_setopt($ch, CURLOPT_URL, $LOGINURL); // set post options curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS); // perform login $result = curl_exec($ch); print $result; function getFormFields($data) { if (preg_match('/(

Examples can be found here:
https://help.mikrotik.com/docs/display/ROS/REST+API

You seem to be attempting to login by scraping some sort of form, which won’t work.