pritaeas ,
Using cUrl it is done and running but returning null instead of giving proper output as per given link http://tripletex.no/resources/api/tripletex-api.pdf. here is the code :
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"dir="ltr"lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
//RESPONSE:
$header = "Server: Apache-Coyote/1.1;";
$header .= "X-Powered-By: Servlet 2.4;JBoss-4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)/Tomcat-5.5";
$header .="DSet-Cookie: JSESSIONID=09E2172BB69BA99F9CBA3A9C0F2A025; Path=/;";
$header .="Set-Cookie: JSESSIONID=F81885A42D1CC3876039EAB8C441C5B3; Path=/;";
$header .="Content-Type: text/plain;charset=utf-8";
$header .= "Content-Length: 29";
$header .= "Date: Wed, 21 Jul 2010 06:59:38 GMT";
## lets setup the target API url
// $url = 'https://tripletex.no/JSON-RPC';
## define the cookie directory wher the cookie recieved will be stored
// $cookie_bin = 'cookie/cookie.txt'; // as described in step 1
## lets initialize the curl.. if this method does not work you can use the commented option below.
$ch = curl_init($url);
## we might not need this for now
//curl_setopt($ch, CURLOPT_HEADER, 0);
## we define where to store and check for cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_bin);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_bin);
## we try this first
curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
## if the above does not work, uncomment below
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
## we need to witheld the paypal data for now.
//curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
## we notify the remote server of the content type and the lenght of the entire methodData string
array('Content-Type: application/json','Content-Length: ' . strlen($methodData)) );
## finally, we will use either var_dump or print_r to view the respnse of the remote server..
// var_dump(curl_exec($ch));
//var_dump(json_decode(curl_exec($ch)));
//print_r(json_decode(curl_exec($ch)));
/*++++++++++++++++++++ Login check starts*/
## lets setup the target API url
echo "login checking in tripletex";
$methodData = array('method'=>'Sync.login','params'=>array(7,'pwd','jason@test.no','pwd'),'id'=>1);
## now we use json_encode function
$methodData = json_encode($methodData);
$url = 'https://tripletex.no/JSON-RPC';
## define the cookie directory wher the cookie recieved will be stored
$cookie_bin = 'cookie/cookie.txt'; // as described in step 1
## lets initialize the curl.. if this method does not work you can use the commented option below.
$ch = curl_init($url);
## we might not need this for now
//curl_setopt($ch, CURLOPT_HEADER, 0);
## we define where to store and check for cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_bin);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_bin);
## we try this first
curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
## if the above does not work, uncomment below
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
## we need to witheld the paypal data for now.
//curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
## we notify the remote server of the content type and the lenght of the entire methodData string
array('Content-Type: application/json',
'Content-Length: ' . strlen($methodData)) );
## finally, we will use either var_dump or print_r to view the respnse of the remote server..
var_dump(json_decode(curl_exec($ch)));
/*+++++++++++++++++ Login check ends*/
//$methodData = array('method'=>'Sync.login','params'=>array(7,'pwd','jason@test.no','pwd'),'id'=>1);
//array_push($methodData,'inventory'=>'100','sold'=>'50','receipt'=>'45597798','t_id'=>'1235488');
$ch = curl_init('https://tripletex.no/resources/examples/order_import_example.csv');
$csv_data = array('method'=>'Project.importOrdersTripletexCSV','params'=>array('encoding','amountsIncVat','ignoreFirstRow'),'id'=>1);
$csv_data = json_encode($csv_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'https://tripletex.no/JSON-RPC');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json','Content-Length: ' . strlen($csv_data)) );
/* $data = array
(
'ignore-robots' => 'false',
'language' => 'english',
'crawl-delay' => '0',
'depth' => '3',
'root' => array('url' => 'http://bartleby.com/')
);*/
curl_setopt($ch, CURLOPT_POSTFIELDS, $csv_data);
$result=curl_exec($ch);
//var_dump($result);
?>
<?php
//SECOND METHOD
//CreateInvoice API
$url = 'https://tripletex.no/JSON-RPC';
$cookie_bin = 'cookie/cookie.txt';
## lets initialize the curl.. if this method does not work you can use the commented option below.
// $ch = curl_init($url);
## we might not need this for now
//curl_setopt($ch, CURLOPT_HEADER, 0);
## we define where to store and check for cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_bin);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_bin);
$methodData = array('method'=>'Sync.login','params'=>array(7,'pwd','jason@test.no','pwd'),'id'=>1);
## now we use json_encode function
$methodData = json_encode($methodData);
//$csv_data = array('method'=>'Project.importOrdersTripletexCSV','params'=>array('encoding','amountsIncVat','ignoreFirstRow'),'id'=>1);
//$csv_data = json_encode($csv_data);
$response = PPHttpPost($url,$methodData,$header);
echo "<br /><br />Response: <br />";
//print_r($response);
//parse the response
$response_ar = explode("&", $response);
$p_response = parseAPIResponse($response_ar);
echo "<br /><br /><br />";
//for now
//print_r($p_response);
function parseAPIResponse($response){
$parsed_response = array();
foreach ($response as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$parsed_response[$tmpAr[0]] = $tmpAr[1];
}
}
return $parsed_response;
}
/*function requestPayKey(){
//request token string:
$reqstr = "requestEnvelope.errorLanguage=en_US&invoice.merchantEmail=caples69%40hotmail.com&invoice.payerEmail=caples23%40hotmail.com&invoice.currencyCode=USD&invoice.items(0).name=Banana+Leaf+--+001&invoice.items(0).description=Banana+Leaf&invoice.items(0).quantity=1&invoice.items(0).unitPrice=1&invoice.items(0).taxName=Tax1&invoice.items(0).taxRate=10.25&invoice.paymentTerms=Net15";
return $reqstr;
}*/
function PPHttpPost($my_endpoint, $headers,$csvdatum){
// setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $my_endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json','Content-Length: ' . strlen($methodData)) );
//curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response, use for testing
// turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
// setting the NVP $my_api_str as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS,$csvdatum);
// getting response from server
$httpResponse = curl_exec($ch);
if(!$httpResponse)
{
$response = "$API_method failed: ".curl_error($ch)."(".curl_errno($ch).")";
return $response;
}
return $httpResponse;
}
?>
</body>
</html>
I checked it out with this link http://jsonlint.com/ whether returning json or not.