Parse a json array in PHP to get the required values - api

I am using a API provided by this website
http://pnrapi.alagu.net/
By using this API, we can get PNR status of our indian railways.
I am using CURL to make a call and get the page content which is something like this, in an array format:
Array ( [url] => http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 [content_type] => application/json;charset=utf-8 [http_code] => 200 [header_size] => 185 [request_size] => 130 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.906 [namelookup_time] => 0 [connect_time] => 0.312 [pretransfer_time] => 0.312 [size_upload] => 0 [size_download] => 548 [speed_download] => 188 [speed_upload] => 0 [download_content_length] => 548 [upload_content_length] => 0 [starttransfer_time] => 2.906 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 50.57.204.234 [primary_port] => 80 [local_ip] => 192.168.1.10 [local_port] => 60105 [redirect_url] => [errno] => 0 [errmsg] => [content] => {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
but when I go to the URL http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 , it gives me output as shown below:
{"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}}
Now, it seems that output on my web page with curl have got some extra text which is in the start as you can see both the outputs above.
Well, my question is, how can I get the values from above array.
I am talking about the array output which I'm getting on my page using CURL, which looks like this:
Array (
[url] => http://pnrapi.alagu.net/api/v1.0/pnr/4563869832
[content_type] => application/json;charset=utf-8
[http_code] => 200
[header_size] => 185
[request_size] => 130
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.906
[namelookup_time] => 0
[connect_time] => 0.312
[pretransfer_time] => 0.312
[size_upload] => 0
[size_download] => 548
[speed_download] => 188
[speed_upload] => 0
[download_content_length] => 548
[upload_content_length] => 0
[starttransfer_time] => 2.906
[redirect_time] => 0
[certinfo] => Array ( )
[primary_ip] => 50.57.204.234
[primary_port] => 80
[local_ip] => 192.168.1.10
[local_port] => 60105
[redirect_url] =>
[errno] => 0
[errmsg] => [content] => {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
Code in my PHP page is:
<?php
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
$pnr = get_web_page('http://pnrapi.alagu.net/api/v1.0/pnr/4563869832');
echo "<code>";
print_r($pnr);
echo "</code>";
?>
I only need the values under "content" which are train number, train name, travel date etc.
So, what would be best way to extract this information into each variable?
Like I want it like this:
$train_no = [some code];
$train_name = [some_code];
and so on...
Thanks in advance.
I tried this:
echo $pnr['content'];
and the output I got is:
{"status":"OK",
"data":"train_number":"16178",
"chart_prepared":false,
"pnr_number":"4563869832",
"train_name":"ROCKFORT EXPRES",
"travel_date":{"timestamp":1369506600,"date":"26-5-2013"},
"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},
"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},
"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}}
Now can any one give me an idea about how can I fetch unique values from above array?

I'm not sure where the JSON string is. But let's say it's the $pnr variable.
$json = json_decode($pnr, true);
$train_no = $json["data"]["train_number"];
$train_name = $json["data"]["train_name"];
Updated:
If you don't need all the other things you can do something like the following:
$npr = file_get_contents(url);
and then run the code above.

You're looking through the header, where you should be looking at the content. Return $content instead in your function and then you can parse out the response:
function get_web_page( $url ) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = json_decode( curl_exec( $ch ) );
curl_close( $ch );
return array(
'train_no' => $content->data->train_number,
'train_name' => $content->data->train_name,
);
}
$pnr = get_web_page('http://pnrapi.alagu.net/api/v1.0/pnr/4563869832');
echo "<pre>" . print_r($pnr, true) . "</pre>";

Related

Issue with post API curl library codeigniter 3

I use this library:
https://github.com/php-curl-class/php-curl-class
Base on documentation I write function for post order:
public function create_order()
{
$curl = new Curl();
$curl->setHeader('CustomerId', 'xxxxxxx');
$curl->setHeader('UserName', 'xxxxxxxxxx');
$curl->setHeader('ActionApiKey', 'xxxxxxxxxxxxxxx');
$order = array(
"createEmpty" => false,
"header" => array(
"comment" => "string",
"country" => "Polska",
"currency" => "PLN",
"isFileRequired" => true,
"actionCustomerId" => "81790",
"payer" => "EndCustomer",
"paymentType" => "CashOnDelivery",
"partnerOrderId" => "81790",
"deliveryAddresType" => "EndCustomer",
"cashOnDeliveryType" => "FullRate",
"cashOnDelivery" => 155,
"deliveryCompanyName" => "TEST API ORDER DO NOT SHIP",
"deliveryCity" => "Poznań",
"deliveryPhone" => "xxxxxxx",
"deliveryStreet" => "xxxxxxxxxx",
"deliveryZipCode" => "xxxxxxx"
),
"items" => array(
array(
"actionProductId" => "MULLOGKAM0087",
"quantity" => 1,
"price" => 122,
"backOrderType" => "BackOrder"
)
)
);
$curl->setHeader('Content-Type', 'application/json');
$curl->post('xxxxxxxxxxxxxxxxxxxxx/v2/Order', json_encode($order));
if ($curl->error) {
echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
} else {
echo 'Respone: ' . $curl->response;
}
}
After run controller, I get white page (I not get any error) but order not created. I test in Insomia API client and with this headers and data order created sucess.
Im not sure I correct post headers also with order data ?

Shopware - How to get products using App Credentials?

I created App in Shopware and able to get apiKey, secretKey, shopUrl and shopId. I want to get all my products using these credentials.
This is my code
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "http://shopware.example.com/store-api/product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json",
"sw-access-key: SW234C1LVA010CWHDD34WK1TMW"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response, true);
print_r($data);
}
and I am getting error like this
Array
(
[errors] => Array
(
[0] => Array
(
[status] => 412
[code] => FRAMEWORK__ROUTING_SALES_CHANNEL_NOT_FOUND
[title] => Precondition Failed
[detail] => No matching sales channel found.
[meta] => Array
(
[parameters] => Array
(
)
)
)
)
)
When I using API key from settings page API I am able to get products.
But how to use App credentials (App key, secret key, shop URL) and get products
You should have gotten the API key during App registration:
https://developer.shopware.com/docs/guides/plugins/apps/app-base-guide#confirmation-request
Did you try that one? If it does not work for the store API you might want to use the admin API.

Add Tracking API in Paypal - Authorization failed

I am trying to add tracking number and order status in my sandbox account through tracking API but getting "Authorization failed due to insufficient permissions" error. Anyone have any idea why this error happens? Below are my codes and response from paypal -
API request
$clientId = 'my client id';
$secretKey = 'my secret key';
$token = $this->getAccessToken($clientId, $secretKey);
$transaction = $this->_objectManager->create('\Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory')->create()->addOrderIdFilter($currentOrder->getId())->getFirstItem();
$transactionId = $transaction->getData('txn_id');
$postfields = [
'trackers' =>
[
0 =>
[
'transaction_id' => $transactionId,
'tracking_number' => $currentOrderTrackingNumber,
'status' => 'SHIPPED',
'carrier' => 'OTHER',
'carrier_name_other' => 'SCS Logistics'
]
]
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($postfields),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer " . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
Response from paypal
Array
(
[tracker_identifiers] => Array
(
)
[errors] => Array
(
[0] => Array
(
[name] => NOT_AUTHORIZED
[message] => Authorization failed due to insufficient permissions
[details] => Array
(
[0] => Array
(
[field] => /trackers/1/transaction_id
[value] => 42L93730906985049
[location] => body
[issue] => USER_NOT_AUTHORIZED
[description] => You are not authorized to add or modify tracking number for this transaction
)
)
[links] => Array
(
)
)
)
[links] => Array
(
[0] => Array
(
[href] => https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch
[rel] => self
[method] => POST
[encType] => application/json
)
)
)
I already contacted support and they added required permission but it's not working. Please if anyone have any idea about it help me. Thanks in advance.

Xero PHP API, getting an error

Steps I am following.
I am sending the authenticate parameter as 1 to public.php file and recieving the oauth_token and oauth_token_secret.
http://localhost/XeroOAuth-PHP-master/public.php?authenticate=1
Here at this stage session is generated as below
Array
(
[oauth] => Array
(
[oauth_token] => XXX
[oauth_token_secret] => XXX
[oauth_callback_confirmed] => true
)
)
Next step, I am calling this url http://localhost/XeroOAuth-PHP-master/public.php?oauth_verifier=1&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC
At this stage it throws below error, which says permission_denied.
Error: oauth_problem=permission_denied&oauth_problem_advice=The%20consumer%20was%20denied%20access%20to%20this%20resource.
Below is the entire Error format I receive in the page.
XeroOAuth Object
(
[_xero_defaults] => Array
(
[xero_url] => https://api.xero.com/
[site] => https://api.xero.com
[authorize_url] => https://api.xero.com/oauth/Authorize
[signature_method] => HMAC-SHA1
)
[_xero_consumer_options] => Array
(
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[authorize_path] => oauth/Authorize
)
[_action] =>
[_nonce_chars] =>
[params] => Array
(
)
[headers] => Array
(
[Accept] => application/xml
[Content-Length] => 0
[Expect] =>
)
[auto_fixed_time] =>
[buffer] =>
[request_params] => Array
(
)
[_xero_curl_options] => Array
(
[curl_connecttimeout] => 30
[curl_timeout] => 20
[curl_ssl_verifypeer] => 2
[curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
[curl_followlocation] =>
[curl_ssl_verifyhost] => 2
[curl_proxy] =>
[curl_proxyuserpwd] =>
[curl_encoding] =>
[curl_verbose] => 1
)
[config] => Array
(
[xero_url] => https://api.xero.com/
[site] => https://api.xero.com
[authorize_url] => https://api.xero.com/oauth/Authorize
[signature_method] => HMAC-SHA1
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[authorize_path] => oauth/Authorize
[curl_connecttimeout] => 30
[curl_timeout] => 20
[curl_ssl_verifypeer] => 2
[curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
[curl_followlocation] =>
[curl_ssl_verifyhost] => 2
[curl_proxy] =>
[curl_proxyuserpwd] =>
[curl_encoding] =>
[curl_verbose] => 1
[application_type] => Public
[oauth_callback] => localhost
[user_agent] => Xero-OAuth-PHP Public
[consumer_key] => XXX
[shared_secret] => XXX
[core_version] => 2.0
[payroll_version] => 1.0
[file_version] => 1.0
[access_token] => XXX
[access_token_secret] => XXX
[host] => https://api.xero.com/oauth/
[multipart] =>
)
[method] => GET
[url] => https://api.xero.com/oauth/AccessToken
[sign] => Array
(
[parameters] => Array
(
[oauth_consumer_key] => YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7
[oauth_nonce] => Ubrb
[oauth_signature_method] => HMAC-SHA1
[oauth_timestamp] => 1504002299
[oauth_token] => 3CHDO7HFISTMVJXDX7IIPMRJUZH2FC
[oauth_verifier] => 1
[oauth_version] => 1.0
[oauth_signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y=
)
[signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D
[signed_url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
[header] => OAuth oauth_consumer_key="YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7", oauth_nonce="Ubrb", oauth_signature="o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1504002299", oauth_token="3CHDO7HFISTMVJXDX7IIPMRJUZH2FC", oauth_verifier="1", oauth_version="1.0"
[sbs] => GET&https%3A%2F%2Fapi.xero.com%2Foauth%2FAccessToken&oauth_consumer_key%3DYDOVURHNHW7RIHJ384ZYJ7TMVQT8W7%26oauth_nonce%3DUbrb%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1504002299%26oauth_token%3D3CHDO7HFISTMVJXDX7IIPMRJUZH2FC%26oauth_verifier%3D1%26oauth_version%3D1.0
)
[format] => xml
[response] => Array
(
[headers] => Array
(
[cache_control] => private
[content_type] => text/html; charset=utf-8
[date] => Tue, 29 Aug 2017 10:25:01 GMT
[strict_transport_security] => max-age=31536000
[www_authenticate] => OAuth Realm="10.144.115.64"
[content_length] => 115
[connection] => keep-alive
)
[code] => 401
[response] => oauth_problem=permission_denied&oauth_problem_advice=The%20consumer%20was%20denied%20access%20to%20this%20resource.
[info] => Array
(
[url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
[content_type] => text/html; charset=utf-8
[http_code] => 401
[header_size] => 267
[request_size] => 418
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.438
[namelookup_time] => 0
[connect_time] => 0.328
[pretransfer_time] => 1.016
[size_upload] => 0
[size_download] => 115
[speed_download] => 79
[speed_upload] => 0
[download_content_length] => 115
[upload_content_length] => -1
[starttransfer_time] => 1.438
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 54.209.35.242
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.1.35
[local_port] => 60675
[request_header] => GET /oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0 HTTP/1.1
Host: api.xero.com
User-Agent: Xero-OAuth-PHP Public
Accept-Encoding: deflate, gzip
Accept: application/xml
Content-Length: 0
)
[format] => xml
)
)
This error is returned if you try to swap a request token for an access token when the access token hasn't yet been authorised for an organisation.
There should be a step in the flow of your application which redirects the user to https://api.xero.com/oauth/Authorize?oauth_token=[OAUTH_TOKEN_HERE] - once the Xero user has selected the organisation they're giving access to and given the ok, your second call should work.

Prestashop filter date_add in webservice

i'm new, and i've a problem with webservice.
when i try to retrieve customers filtering by date_add i get this error:
<message><![CDATA[This filter does not exist. Did you mean: "deleted"? The full list is: "id", "id_default_group", "id_lang", "newsletter_date_add", "ip_registration_newsletter", "last_passwd_gen", "secure_key", "deleted", "passwd", "lastname", "firstname", "email", "id_gender", "birthday", "newsletter", "optin", "website", "company", "siret", "ape", "outstanding_allow_amount", "show_public_prices", "id_risk", "max_payment_days", "active", "note", "is_guest", "id_shop", "id_shop_group"]]></message>
this is my code:
$yesterday = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Qui imposto le opzion dell'array per il Webservice: in questo caso i clienti e setto che il formato è json
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$yesterday.']&date=1',
'display' => 'full',
'output_format' => 'JSON'
);
// faccio la chiamata
$xml = $webService->get($opt);
I'm stuck, I do not know what to do !!! any help is appreciated
Looking at the Customer class webservice parameters, there is no date_add:
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
If you have access to the server installation, you could add the date_add field to the webserviceParameters.
Or the function getWebserviceObjectList to change the behavour.
If you don't have access to the server installation, you can use the sort to get the latest customers until you reach the one you already have. You can use with limit to use in a foreach or while loop.
EDIT After some testing and inspecting what was going on:
First, it's we don't need to add the field date_add to the $webserviceParameters.
The request should be:
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$finish.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
If you only add one date to the filter it will try to match only that date.
Then you need to change the PSWebServiceLibrary.php in line 284 and add the field 'date':
$params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop', 'date');
Now it should work. I tested myself.
EDIT 2:
This is my full test, after changing the the line i mentioned in PSWebserviceLibrary.php, this retrieves my customers with date_add in the interval date.
<?php
require_once( 'PSWebServiceLibrary.php' );
echo 'starting<br />'.PHP_EOL;
try {
// creating web service access
$webService = new PrestaShopWebservice(MY_BASE_URL, WS_KEY, true);
$yesterday = date("Y-m-d", time() - 60 * 60 * 24);
$begin = date("Y-m-d", time() - 60 * 60 * 24 * 30);
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$yesterday.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
//Retrieving the XML data
$xml = $webService->get($opt);
}
catch (PrestaShopWebserviceException $ex) {
// Shows a message related to the error
echo 'Other error: <br />' . $ex->getMessage();
}
?>
first of all: thanks
I modified as your indication, but the result does not change, still gives me the same error.
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
/** inizio modifica aggiunta per il webservice */
'date_add' => array(),
/** fine della modifica */
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
I can not understand