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');
Related
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
Updated to show new code / new error # 10/12/2020 11:30
I need to copy invoices from my website to xero using their API. I managed to get this working using the OAuth 1 but now need to update to OAuth2.0.
I've installed xero-php-oauth2-starter which connects and works fine with the examples. e.g. if I click the example "Create one Contact" link, the demo contact is created in xero.
As such, I know the link is working.
I've been looking around trying to find an example of how to create an invoice using the API but am finding it incredibly hard to work out.
Below is what I currently have in my xero api folder:
<?php
ini_set('display_errors', 'On');
require __DIR__ . '/vendor/autoload.php';
require_once('storage.php');
// Use this class to deserialize error caught
use XeroAPI\XeroPHP\AccountingObjectSerializer;
// Storage Classe uses sessions for storing token > extend to your DB of choice
$storage = new StorageClass();
$xeroTenantId = (string)$storage->getSession()['tenant_id'];
if ($storage->getHasExpired()) {
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'REMOVED',
'clientSecret' => 'REMOVED',
'redirectUri' => 'https://REMOVED/callback.php',
'urlAuthorize' => 'https://login.xero.com/identity/connect/authorize',
'urlAccessToken' => 'https://identity.xero.com/connect/token',
'urlResourceOwnerDetails' => 'https://api.xero.com/api.xro/2.0/Organisation'
]);
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $storage->getRefreshToken()
]);
// Save my token, expiration and refresh token
$storage->setToken(
$newAccessToken->getToken(),
$newAccessToken->getExpires(),
$xeroTenantId,
$newAccessToken->getRefreshToken(),
$newAccessToken->getValues()["id_token"] );
}
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( (string)$storage->getSession()['token'] );
$apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
new GuzzleHttp\Client(),
$config
);
$invoices = '{"invoices":[{
"type":"Invoice.TypeEnum.ACCREC",
"contact":{"contactID":"97af3783-0f32-42be-a06d-8c586c8aa8ec"},
"lineItems":[{
"description":"Acme Tires",
"quantity":2,
"unitAmount":20,
"accountCode":"000",
"taxType":"NONE",
"lineAmount":40
}],
"date":"2019-03-11",
"dueDate":"2018-12-10",
"reference":"Website Design",
"status":"Invoice.StatusEnum.DRAFT"
}]}';
foreach ($import as $invoice) {
//create contact
$xcontact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
$xcontact->setName($contactname);
//create line item
$lineItems = array();
foreach ($invoice['invoiceLineItems'] as $line) {
$newLine = new XeroAPI\XeroPHP\Models\Accounting\LineItem();
$newLine->setDescription($invoice['message']."\n".$line['description']);
$newLine->setQuantity($line['quantity']);
$newLine->setUnitAmount($line['amount']);
$newLine->setAccountCode('200');
$lineItems[] = $newLine;
}
$xinvoice = new XeroAPI\XeroPHP\Models\Accounting\Invoice();
$xinvoice->setType("ACCREC");
$xinvoice->setStatus("AUTHORISED");
$xinvoice->setDate($invoice['invoiceDate']);
$xinvoice->setDueDate($invoice['dueDate']);
$xinvoice->setLineAmountTypes("NoTax");
$xinvoice->setContact($xcontact);
$xinvoice->setLineItems($lineItems);
$xinvoice->setInvoiceNumber("INV-0".$invoice['invoiceNumber']);
$xinvoices['Invoices'][] = $xinvoice;
}
$apiResponse = $apiInstance->createInvoices($xeroTenantId,$xinvoices);
$summarize_errors = false; // bool | If false return 200 OK and mix of successfully created objects and any with validation errors
$unitdp = 4; // int | e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts
?>
gives
Fatal error: Uncaught InvalidArgumentException: Missing the required parameter $invoices when calling createInvoices
which I can't seem to find any details on.
I've created the product "Acme Tires" in xero just incase that was causing the issue (I remember in auth 1 that it wouldn't work if the product wasn't listed first).
Any help would be greatly appreciated.
With the new PHP SDK you need to pass an array of Invoice objects.
The following creates Invoices based on the contents of a pre-existing array ($import).
You'll see that you need to place the line items into an array, and then insert that into the invoice object. The invoice itself is then inserted into an array which is passed to the API.
<?php
foreach ($import as $invoice) {
//create contact
$xcontact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
$xcontact->setName($contactname);
//create line item
$lineItems = array();
foreach ($invoice['invoiceLineItems'] as $line) {
$newLine = new XeroAPI\XeroPHP\Models\Accounting\LineItem();
$newLine->setDescription($invoice['message']."\n".$line['description']);
$newLine->setQuantity($line['quantity']);
$newLine->setUnitAmount($line['amount']);
$newLine->setAccountCode('200');
$lineItems[] = $newLine;
}
$xinvoice = new XeroAPI\XeroPHP\Models\Accounting\Invoice();
$xinvoice->setType("ACCREC");
$xinvoice->setStatus("AUTHORISED");
$xinvoice->setDate($invoice['invoiceDate']);
$xinvoice->setDueDate($invoice['dueDate']);
$xinvoice->setLineAmountTypes("NoTax");
$xinvoice->setContact($xcontact);
$xinvoice->setLineItems($lineItems);
$xinvoice->setInvoiceNumber("INV-0".$invoice['invoiceNumber']);
$xinvoices['Invoices'][] = $xinvoice;
}
$apiResponse = $apiInstance->createInvoices($xeroTenantId,$xinvoices);
?>
Update:
$apiInstance will have been created earlier eg.
$apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
new GuzzleHttp\Client(),
$config
);
$import was an array in the original script that contained the raw data I wanted to import. You would need to replace this with your own data.
Update 2:
To use your original data, you'll need to remove the
foreach ($import as $invoice) {
loop.
and replace the references to $invoice with your own data.
For example:
//create contact
$xcontact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
$xcontact->setName($contactname);
Would become:
//create contact
$xcontact = new XeroAPI\XeroPHP\Models\Accounting\Contact();
$xcontact->setContactId("97af3783-0f32-42be-a06d-8c586c8aa8ec");
I am using the GoCardless Documentation here to try list all subscriptions for a customer.
I have followed the instructions as you can see below, however nothing at all is displaying when I run this script - does anyone know what I may have done wrong?
require 'vendor/autoload.php';
$client = new \GoCardlessPro\Client(array(
'access_token' => 'XXXXXx',
'environment' => \GoCardlessPro\Environment::LIVE
));
$client->subscriptions()->list([
"params" => ["customer" => "CU000R3B8512345"]
]);
Calling a method on its own doesn’t do anything. It’ll execute the given method, but it’s not going to print anything to your browser screen on its own.
As RiggsFolly says (and is documented in GoCardless’s API documentation), calling $client->subscriptions()->list() will return a cursor-paginated response object. So you need to do something with this result. What that is, I don’t know as it’s your application’s business logic and only you know that.
<?php
use GoCardlessPro\Client;
use GoCardlessPro\Environment;
require '../vendor/autoload.php';
$client = new Client(array(
'access_token' => 'your-access-token-here',
'environment' => Environment::SANDBOX,
));
// Assign results to a $results variable
$results = $client->subscriptions()->list([
'params' => ['customer' => 'CU000R3B8512345'],
]);
foreach ($results->records as $record) {
// $record is a variable holding an individual subscription record
}
Pagination with Gocardless:
function AllCustomers($client)
{
$list = $client->customers()->list(['params'=>['limit'=>100]]);
$after = $list->after;
// DO THINGS
print_r($customers);
while ($after!="")
{
$customers = $list->records;
// DO THINGS
print_r($customers);
// NEXT
$list = $client->customers()->list(['params'=>['after'=>$after,'limit'=>100]]);
$after = $list->after;
}
}
I am using the upper mentioned library (Google Cloud Vision Client Library v1) in PHP to assign labels to images... so far so good. It all works, except it returns fewer results than on the google test page... as far as I understand it has to do with a "max_results" parameter which defaults to 10, but I am not able to find where/how to set it manually...
There was a similar question here on Python and there it was as simple as passing it as a parameter - I have tried many options to do this in PHP, but apparently I am doing something wrong...
Here is a link to the documentation : https://googleapis.github.io/google-cloud-php/#/docs/cloud-vision/v0.19.3/vision/v1/imageannotatorclient?method=labelDetection
I am guessing I have to pass it to the "optionalArgs" parameter... but not exactly sure how to do this...
Here is more or less what my code is:
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
$this->client = new ImageAnnotatorClient();
$response = $this->client->labelDetection(...THE IMAGE...);
$labels = $response->getLabelAnnotations();
if ($labels) {
foreach ($labels as $label) {
// do something with $label->getDescription()
}
}
Anyone got an idea how to get more results in the $labels array?
New Method
Since the other answer I provided seems to be deprecated, I am going to provide a sample that uses the setMaxResults method on the Feature object.
$imageAnnotatorClient = new ImageAnnotatorClient();
$gcsImageUri = 'some/image.jpg';
$source = new ImageSource();
$source->setGcsImageUri($gcsImageUri);
$image = new Image();
$image->setSource($source);
$type = Feature_Type::FACE_DETECTION;
$featuresElement = new Feature();
$featuresElement->setType($type);
$featuresElement->setMaxResults(100); // SET MAX RESULTS HERE
$features = [$featuresElement];
$requestsElement = new AnnotateImageRequest();
$requestsElement->setImage($image);
$requestsElement->setFeatures($features);
$requests = [$requestsElement];
$imageAnnotatorClient->batchAnnotateImages($requests);
Deprecated Method
The maxResults value gets specified in the Image constructor
An example of this code can be found in the source code for the Image object.
$imageResource = fopen(__DIR__ . '/assets/family-photo.jpg', 'r');
$image = new Image($imageResource, [
'FACE_DETECTION',
'LOGO_DETECTION'
], [
'maxResults' => [
'FACE_DETECTION' => 1
],
'imageContext' => [
....
]
]
]);
OK, so for anybody who still may need this here is a working example
use Google\Cloud\Vision\Image;
use Google\Cloud\Vision\VisionClient;
$imageResource = fopen(__DIR__ .'/'. $fileIMG, 'r');
$thePic = new Image($imageResource, [
'LABEL_DETECTION',
'LOGO_DETECTION',
'TEXT_DETECTION'
], [
'maxResults' => [
'LABEL_DETECTION' => 20,
'LOGO_DETECTION' => 20,
'TEXT_DETECTION' => 20
],
'imageContext' => []
]);
$vision = new VisionClient();
$result = $vision->annotate($thePic);
$finalLabels = array();
// do the same for $results->text(), $results->logos()
if($result->labels()){
foreach ($result->labels() as $key => $annonObj) {
$tmp = $annonObj->info();
$finalLabels[] = $tmp['description'];
}
}
But... as it says in the official documentation
Please note this client will be deprecated in our next release. In order
to receive the latest features and updates, please take
the time to familiarize yourself with {#see Google\Cloud\Vision\V1\ImageAnnotatorClient}.
So I still need a way to do this using the ImageAnnotatorClient class... any ideas anyone?
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.