Prestashop WebService API - Update order status - php

I have been trying for a long time to update the status of an order from php with the prestashop webService library.
First I have tried to download the order, modify the "current_state" attribute and upload it via edit, without positive result, I always get the error message "other error"
Now I have seen that you can add an entry in "order_histories" but I am also unable to make it work:
$estadoID = (int)$_POST['estadosSelect'];
$idPedido = $_GET['id'];
$tienda = $_GET['tienda'];
$webService = $this->webServiceTienda($tienda);
try{
$opt = [
'resource' => 'order_histories?schema=blank'
];
$xml = $webService->get($opt);
$resources = $xml->children()->children();
var_dump( $resources );
$resources->id_order = $idPedido;
$resources->id_employee = 0;
$resources->id_order_state = $estadoID;
var_dump( $resources );
$opt = [
'resource' => 'order_histories',
'postXml' => $xml->asXML()
];
$createdXml = $webService->add($opt);
var_dump( $createdXml );
}catch (PrestaShopWebserviceException $e){
$this->controlErrores($e);
}
I keep getting the error code "other error", I have seen several examples, but I don't get it, any help is welcome: D
var_dumps

UPDATE: Debug info, i have 403 Forbidden, Access to this resource on the server is denied!
All options marked in prestashop backoffice, webservice
DEBUG
https://i.stack.imgur.com/1qKDd.png
UPDATE:
I have managed to update the order status in 1 of the four stores that I have connected, I use the same code and three of them are in the same version of prestashop, 1.7.6.9.
I get the error code 403, the webservice permissions are in the 4 stores the same.
Any ideas?
Thanks

Related

BigQuery: error to fetch query results from PHP

I've changed some configurations on BigQuery and actually I can't fetch data anymore.
This is the flow:
$query = "select what i need to select";
$client = new Google_Client();
$client->setApplicationName('Google-BigQuery');
$client->useApplicationDefaultCredentials(); // running in app engine env
$client->addScope('https://www.googleapis.com/auth/bigquery');
$client->addScope('https://www.googleapis.com/auth/devstorage.read_write');
$bq = new Google_Service_Bigquery($client);
$job = new Google_Service_Bigquery_Job();
$config = new Google_Service_Bigquery_JobConfiguration();
$queryConfig = new Google_Service_Bigquery_JobConfigurationQuery();
$config->setQuery($queryConfig);
$job->setConfiguration($config);
$queryConfig->setQuery($query);
Then:
$job = $bq->jobs->insert($project, $job); // OK
$jr = $job->getJobReference(); // OK -> here i got jobid as $jr['jobId']
$queryResults = $bq->jobs->getQueryResults('my-project', 'job-id-from-jr'); // ERROR
If I run the query from BigQuery dashboard, it's work and I can get results.
Here I got a 404 error, "notfound", I've checked if the job id match with that on the dashboard, and it match.
{ "error": { "code": 404, "message": "Not found: Job my-project:job-id",
The only one difference is that on the job inside the dashboard is specified the location as
my-name:europe-west1.job-id
Can't find a way to specify directly the zone of execution, I've tried to add europe-west1 as a string before job-id, but got error about that (it can't be done).
There is a way to fix this? It's possible to specify the zone?
Thanks!
Ok, solved by passing an array as 3rd parameter
$arrLocation = array("location" => "europe-west1");
$queryResults = $bq->jobs->getQueryResults('my-project', 'job-id-from-jr', $arrLocation);

PHP + Web Services

I'm struggling to get a web service to work which we are using to integrate with a software package from Civica. Unfortunately they have sent us code in visual basic which we don't use here and I'm struggling to "translate" the visual basic into PHP.
So here's the code I have so far:
error_reporting(E_ALL);
$client = new SoapClient('https://xxx/cx/WebService/WSTokenService?
singleWsdl');
var_dump($client->__getFunctions());
The above works and I can see the functions. It's the next bit I can't get to work:
$request_param = array('Password' => 'xxx', 'UserName' => 'yyy');
try
{
$request = $client ->GetUserWSToken($request_param);
$result = $request ->GetUserWSTokenResult;
print_r($result);
}
catch (Exception $e)
{
echo "<P><P>Exception Error!";
echo $e->getMessage();
}
When I run the above code I get an error message "Exception Error!GetUserWSToken has service faults". I also get another error "Object reference not set to an instance of an object".
The visual basic code we've been sent by the package company to use is:
Dim tokenClient As New TokenService.WSTokenServiceClient
Dim tokenreq As New TokenService.SecurityTokenRequest
tokenreq.UserName = "usernamehere"
tokenreq.Password = "passwordhere"
Dim token = tokenClient.GetUserWSToken(tokenreq)
Does anyone know how to translate the visual basic above into what I need to do for PHP?

Issue With RETS Data Fetching Feed in PHP

I am using the PHRETS PHP library to fetch the RETS data from the rets API. I have and issue with getting the Data. It's giving me the Requested Class not found Error. Please help to solve this Error. My Code is:
date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('http://rets.navicamls.net/login.aspx')
->setUsername('xxx')
->setPassword('xxx')
->setRetsVersion('1.7.2');
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
if ($connect) {
echo "Connected!<br>";
}
else {
echo "Not Connected!<br>";
print_r($rets->Error());
exit;
}
//results consists of Property, class, and query
$results = $rets->Search(
"Property",
"A",
"*",
[
'QueryType' => 'DMQL2',
'Count' => 1, // count and records
'Format' => 'COMPACT-DECODED',
'Limit' => 10,
'StandardNames' => 0, // give system names
]
);
print_r($results); exit;
You need to first verify the name of the class in your search query is correct by looking up the metadata.
Use RETSMD.com and enter the RETS Server login url, username, and password.
Use the metadata functions in the PHRETS documentation on the main page
a. $system = $rets->GetSystemMetadata();
b. $classes = $rets->GetClassesMetadata('Property');

PHP SoapRequest: get response

I am trying to implement a soaprequest and making the call does seem to work. The only problem is: I don't know how to receive the response data. My code looks like this:
$auth = array(
'UsernameToken' => array(
'Username' => 'xxx',
'Password' => 'yyyy'
)
);
$header = new SoapHeader('xs','Security',$auth, 0);
$client->__setSoapHeaders($header);
$client->__setLocation('http://example.com/test.php');
$params = array(
...
'trace' => 1,
'cache_wsdl' => 0
);
try {
$response = $client->getSomeData($params);
}catch(Exception $e){
echo "Exception: ".$e->getMessage();
}
print_r($response);
This results in an empty page, because $response is empty. But the test.php file is called (I tried with a simple mail() command and it sends the mail every time I call the page with the soapclient).
So I guess the soap response is somehow sent to the test.php file - right? How do I get it? If I do not set the location, I get a nullpointerexception, so I have to do that. I tried
$client->__getLastResponse()
that's empty too.
What can I do, how do I get the soap response data? Any hints would be appreciated. Thank you!

PHP vTiger Issue creating tickets with vtwsclib

I am trying to figure out how to programmatically create a "HelpDesk" ticket in vTiger using its Web Services api. I am currently using the official vtwsclib v1.5 php library. The log in, appears to succeed and I can also successfully perform a doDescribe on the module, however doCreate returns 'false' no matter what I do. Sample below. Am I missing anything?
$url = 'http://vtiger.mydomain.com/';
$client = new Vtiger_WSClient($url);
$login = $client -> doLogin('systemuser', 'O8nFgnotrealkey');
if (!$login)
echo 'Login Failed';
else {
$module = "HelpDesk";
$record = $client -> doCreate($module, Array(
'assigned_user_id' => "21",
'parent_id' => "91",
'ticket_title' => "test",
'ticketstatus' => "Open"
));
if ($record) {
$recordid = $client -> getRecordId($record['id']);
}
}
Retruns:
$record: bool(false)
Found it:
Looks like if you leave 'assigned_user_id' blank, it will populate it with the correct 'assigned_user_id' for yourself. The 'assigned_user_id' can also be retrieved for your own account from the login response and it appears like this {module_id}x{user_id}. ie: "3x16".
All id's ('parent_id', 'assigned_user_id', 'related_to' etc etc etc) appear to be in a 'NxN' format.

Categories