mam problem z uruchomieniem skryptu php który łączy się z moim CRM (Zoho CRM) i pobiera dane (kilka rekordów) w formacie XML. Następnie chodzi o "wsadzenie" tych rekordów do bazy mysql.
Jak narazie jedyn co midziała to tego typu zapytanie:
https://crm.zoho.com/crm/private/xml/Leads/...mp;scope=crmapi
i zwraca mi coś takiego w postaci xml:
This XML file does not appear to have any style information associated with it. The document tree is shown below. <response uri="/crm/private/xml/Leads/getMyRecords"> <result> <Leads> <row no="1"> <FL val="LEADID">624745000000615068</FL> <FL val="SMOWNERID">624745000000053003</FL> <FL val="Lead Owner"> <![CDATA[ Moje Imię ]]> </FL> <FL val="Company"> <![CDATA[ Peplos Wine Restaurant ]]> </FL> <FL val="FirstName"> <![CDATA[ Grzegorz ]]> </FL> <FL val="Last Name"> <![CDATA[ Kowalski ]]> </FL>> <FL val="Created Time"> <![CDATA[ 2014-02-28 12:41:17 ]]> </FL> </row> </Leads> </result> </response>
Plik php który miał by przetowrzyć to o co mi chodzi już niestety nie dziąła. Nie wiem dlaczego. Wydaje mi się że ten skrypt php wogóle nie pobiera danych z mojego CRM. Jak sprawdzić zanim włoże dane do mysql czy coś zostało pobrane? print_r


Plik php wyglada tak:
<?php /* NOTE: Define your mysql database parameters in moduleDependant class */ /* Constant Declarations */ /* user related parameter */ /* create a object */ $utilObj = new Utilities(); /* set parameters */ $parameter = ""; $parameter = $utilObj->setParameter("scope", SCOPE, $parameter); $parameter = $utilObj->setParameter("authtoken", AUTHTOKEN, $parameter); $parameter = $utilObj->setParameter("selectColumns", "Leads(LEADID,First Name,Last Name,Company)", $parameter); /* Call API */ $response = $utilObj->sendCurlRequest(TARGETURL, $parameter); $utilObj->parseXMLandInsertInDB($response); class Utilities { public function setParameter($key, $value, $parameter) { $parameter = $key . '=' . $value; } else { $parameter .= '&' . $key . '=' . $value; } return $parameter; } public function parseXMLandInsertInDB($xmldata) { $xmlString = <<<XML $xmldata XML; $xml = simplexml_load_string($xmlString); $modeuleDependantObj = new moduleDependant(); $output = $modeuleDependantObj->insertInDB($xml); } } public function sendCurlRequest($url, $parameter) { try { /* initialize curl handle */ $ch = curl_init(); /* set url to send post request */ curl_setopt($ch, CURLOPT_URL, $url); /* allow redirects */ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); /* return a response into a variable */ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); /* times out after 30s */ curl_setopt($ch, CURLOPT_TIMEOUT, 30); /* set POST method */ curl_setopt($ch, CURLOPT_POST, 1); /* add POST fields parameters */ curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter); /* execute the cURL */ $result = curl_exec($ch); curl_close($ch); return $result; } catch (Exception $exception) { } } } class moduleDependant { /* Define your mysql database parameters */ private $host = "localhost"; private $username = "root"; private $password = ""; public function insertInDB($xml) { /* $records[row value][field value] */ for ($i = 0; $i < $numberOfRecords; $i++) { for ($j = 0; $j < $numberOfValues; $j++) { switch ((string) $xml->result->Leads->row[$i]->FL[$j]['val']) { /* Get attributes as element indices */ case 'LEADID': $records[$i]['LEADID'] = (string) $xml->result->Leads->row[$i]->FL[$j]; break; case 'First Name': $records[$i]['First Name'] = (string) $xml->result->Leads->row[$i]->FL[$j]; break; case 'Last Name': $records[$i]['Last Name'] = (string) $xml->result->Leads->row[$i]->FL[$j]; break; case 'Company': $records[$i]['Company'] = (string) $xml->result->Leads->row[$i]->FL[$j]; break; } } } /* Inserting in database */ $query = "Insert into crm.leads (id, firstname, lastname, company) value "; if ($k == 0) { $query .= "('" . $records[$k]['LEADID'] . "','" . $records[$k]['First Name'] . "','" . $records[$k]['Last Name'] . "','" . $records[$k]['Company'] . "')"; } if ($k > 0) { $query .= ", ('" . $records[$k]['LEADID'] . "','" . $records[$k]['First Name'] . "','" . $records[$k]['Last Name'] . "','" . $records[$k]['Company'] . "')"; } } /* Table structure of inserted data, you can check inserted data by uncommenting a below section */ /* $insertedTable = "<table cellspacing=0 cellpadding='4px' border=1>"; $insertedTable .= "<tr><td>Lead ID</td><td>First Name</td><td>Last Name</td><td>Company</td></tr>"; for ($k = 0; $k < count($records); $k++) { $insertedTable .= "<tr><td>" . $records[$k]['LEADID'] . "</td><td>" . $records[$k]['First Name'] . "</td><td>" . $records[$k]['Last Name'] . "</td><td>" . $records[$k]['Company'] . "</td></tr>"; } $insertedTable .= "</table>"; echo $insertedTable; */ } else { } } } ?>
Update...
Jak narazie to moge powiedzić że:
1) echo "Params: " . $parameter; zwraca paramery:
Params: scope=crmapi&authtoken=mojtokenautoruzacujnu&selectColumns=Leads(LEADID,First Name,Last Name,Company)
wiec ta część jast ok
2) pierwszy sposób który mi pozwala pobrać dane z CRM to metoda GET, natomiast użyte w skrypcie php curl to metoda POST. Raczej wątpie że to jest przyczyną bo skryp żywcem wzięty ze strony Zoho CRM....no ale może tu jest przyczyna?

public function sendCurlRequest($url, $parameter) { try { /* initialize curl handle */ $ch = curl_init(); /* set url to send post request */ curl_setopt($ch, CURLOPT_URL, $url); /* allow redirects */ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); /* return a response into a variable */ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); /* times out after 30s */ curl_setopt($ch, CURLOPT_TIMEOUT, 30); /* set POST method */ curl_setopt($ch, CURLOPT_POST, 1); /* add POST fields parameters */ curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter); /* execute the cURL */ $result = curl_exec($ch); curl_close($ch); return $result; }
nie potrafię togo przerobić na curl metodą GET. Jak ktoś jest chętny to pomocy to sprawdzę. Moze tu jest przyczyna.
Dzieki.