I have this code where i try to list all my articles in my webshop via API (documentation here http://api.textalk.se/webshop/)
I made similar script witch receives orders from the same API and it works perfect, but this i wont get to work.
Any ideas what i am doing wrong?
<?php
class TextalkApi
{
public function AdminLogin($username, $password) {
$url = 'https://shop.textalk.se/backend/jsonrpc/v1/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json-rpc'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"jsonrpc":"2.0", "id":1, "method":"Admin.login", "params":["' . $username . '","' . $password . '"]}');
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code != 200)
throw new Exception('Error : Admin Login Failed');
return $data['result'];
}
public function GetArts($admin_auth_token, $webshop_id) {
$url = 'https://shop.textalk.se/backend/jsonrpc/v1/?auth=' . $admin_auth_token . '&webshop=' . $webshop_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json-rpc'));
// this below i beleive dosen't work
curl_setopt($ch, CURLOPT_POSTFIELDS,
'{"jsonrpc":"2.0","method":"Article.list", {"limit": 5}],"id":1}');
// this above i beleive dosen't work
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code != 200)
throw new Exception('Error : Failed to get orders');
return $data['result'];
}
}
?>
In this POSTFIELD where i write "// this below i beleive dosen't work" i want to put this properly
Article.list(true, {"limit": 5})
see the documentation http://api.textalk.se/webshop/interface/TryIt/
In my other PHP file that looks like this i would like the result to output
<?php
require_once('the_file_with_the_class_TextalkApi.php');
$textalk = new TextalkApi();
//Working demo credentials
$admin_auth_token = $textalk->AdminLogin('pon85x@gmail.com', 'abc123');
$webshop_id = '77140';
$arts = $textalk->GetArts($admin_auth_token, $webshop_id);
echo '<pre>';print_r($arts);echo '</pre>';
var_dump($arts);
?>
But the result is NULL