As part of a PHP webapp I have MySQL contacts table. It is integrated throughout the app, allowing you add a contact, edit a contact or add a contact as a relation to another table. However, currently it is self-contained. The company would like it to sync with Exchange, so that contacts added to Exchange will show up on the webapp and contacts added on the webapp will show up through Exchange.
So I have two problems: 1) communicating with Exchange 2) syncing with Exchange.
As far as the basic communication goes, it looks like this library will be able to manage it https://github.com/jamesiarmes/php-ews. However, I am quite lost as to how to manage syncing and don't where to start.
The build-in way to sync items is via function called SyncFolderItems. Basically to Exchange everything, including contacts is a folder, so you'll just pass CONTACTS as DistinguishedFolderId in your sync request.
The sync works by donloading all the items for given account in batches of max 512 elements and after each batch it gives you SyncState as a refernce point for Exchange to know where you left off. So it gives you ability to do incremental sync.
Now, that's one way of course, meaning Exchange -> Your DB. The other way it aeound you should preform atomic updates/request - the moment you change/add/delete item form your db you should issue adequate request to Exchange server to keep data in sync, elese it'll be overwritten on your next SyncFolderItems.
You can read up more on SyncFolderItems # MSDN
If you'd like to see example of SyncFolderItems you can take a look # python version of EWSWrapper, it's been added in recently. Although it's python, you can still get the basic idea how to construct the request / handle response.
Hope this helps :)
I am aware that this topic is pretty old. However, for future reference find a solution below. It is using the above-mentioned library php-ews.
I have also just added this to the official php-ews wiki: https://github.com/jamesiarmes/php-ews/wiki/Calendar:-Synchronization
// Define EWS
$ews = new ExchangeWebServices($host, $username, $password, $version);
// fill with string from last sync
$sync_state = null;
$request = new EWSType_SyncFolderItemsType;
$request->SyncState = $sync_state;
$request->MaxChangesReturned = 512;
$request->ItemShape = new EWSType_ItemResponseShapeType;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->SyncFolderId = new EWSType_NonEmptyArrayOfBaseFolderIdsType;
$request->SyncFolderId->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType;
$request->SyncFolderId->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$response = $ews->SyncFolderItems($request);
$sync_state = $response->ResponseMessages->SyncFolderItemsResponseMessage->SyncState;
$changes = $response->ResponseMessages->SyncFolderItemsResponseMessage->Changes;
// created events
if(property_exists($changes, 'Create')) {
foreach($changes->Create as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// updated events
if(property_exists($changes, 'Update')) {
foreach($changes->Update as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// deleted events
if(property_exists($changes, 'Delete')) {
foreach($changes->Delete as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
Related
A number of Xero accounts API samples have PHP variables which start with {
Example:
$invoices = {invoices:[{type: Invoice.TypeEnum.ACCREC, contact:{contactID:"00000000-0000-0000-000-000000000000"}, lineItems:[{ description:"Acme Tires", quantity:2.0, unitAmount:20.0, accountCode:"000", taxType:"NONE", lineAmount:40.0}], date:"2019-03-11", dueDate:"2018-12-10", reference:"Website Design", status: Invoice.StatusEnum.DRAFT}]};
I am struggling to understand how this can work. I am trying to use the API to create multiple invoices in the same call, I can do it fine in Postman so I know my code is OK.
I have tried following:
creating-an-invoice-using-oauth2-in-xero
Using the documents
But for some reason I just can't find a way to make it work.
All our SDKs and documentation is generated from our OpenAPI specs. Generating runnable code in our docs is our long term goal. In the interim, we needed to offer "some" generated docs, but the JSON payloads are not meant to be used.
We have created a sample app that demonstrates different endpoints and displays the code used to make the call.
https://github.com/XeroAPI/xero-php-oauth2-app
Here is the code you'll need to create an invoices
$result = $apiInstance->getContacts($xeroTenantId);
$contactId = $result->getContacts()[0]->getContactId();
$contact = new XeroAPI\XeroPHP\Models\Accounting\Contact;
$contact->setContactId($contactId);
$arr_invoices = [];
$invoice_1 = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
$invoice_1->setReference('Ref-456')
->setDueDate(new DateTime('2019-12-10'))
->setContact($contact)
->setLineItems($lineitems)
->setStatus(XeroAPI\XeroPHP\Models\Accounting\Invoice::STATUS_AUTHORISED)
->setType(XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCPAY)
->setLineAmountTypes(\XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE);
array_push($arr_invoices, $invoice_1);
$invoice_2 = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
$invoice_2->setReference('Ref-123')
->setDueDate(new DateTime('2019-12-02'))
->setContact($contact)
->setLineItems($lineitems)
->setStatus(XeroAPI\XeroPHP\Models\Accounting\Invoice::STATUS_AUTHORISED)
->setType(XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCPAY)
->setLineAmountTypes(\XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE);
array_push($arr_invoices, $invoice_2);
$invoices = new XeroAPI\XeroPHP\Models\Accounting\Invoices;
$invoices->setInvoices($arr_invoices);
$result = $apiInstance->createInvoices($xeroTenantId,$invoices);
I am trying to integrate First Data e4 Gateway using PHP. I downloaded the VinceG/php-first-data-api PHP First Data Service API class. The code comes with some examples.
I have my Terminal ID (API_LOGIN) and Password (32 character string).
What confuses me is that when I use one of the examples, I don't know how to tell the class that I want to use the demo url, not the production url.
The class comes with two constants:
const LIVE_API_URL = 'https://api.globalgatewaye4.firstdata.com/transaction/';
const TEST_API_URL = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/';
In the First Data console, when I generated my password, it said to use the v12 api, /transaction/v12, so I changed the protected $apiVersion = 'v12';
All I want to do is write my first development transaction using First Data e4. I have yet to get any kind of response. Obviously I need a lot of hand holding to get started.
When I set up a website to use BalancedPayments, they have a support forum that's pretty good, and I was able to get that running fairly quickly. First Data has a lot of documentation, but for some reason not much of it has good PHP examples.
My hope is that some expert has already mastered the VinceG/php-first-data-api, and can help me write one script that works.
Here's the pre-auth code I'm using, that invokes the FirstData class:
// Pre Auth Transaction Type
define("API_LOGIN", "B123456-01");
define("API_KEY", "xxxxxxxxxxyyyyyyyyyyyyzzzzzzzzzz");
$data = array();
$data['type'] = "00";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vance";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33333";
$data['cvv'] = "123";
$data['address'] = "1111 OCEAN BLVD MIAMI FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
// Charge
$firstData->setTransactionType(FirstData::TRAN_PREAUTH);
$firstData->setCreditCardType($data['type'])
->setCreditCardNumber($data['number'])
->setCreditCardName($data['name'])
->setCreditCardExpiration($data['exp'])
->setAmount($data['amount'])
->setReferenceNumber($orderId);
if($data['zip']) {
$firstData->setCreditCardZipCode($data['zip']);
}
if($data['cvv']) {
$firstData->setCreditCardVerification($data['cvv']);
}
if($data['address']) {
$firstData->setCreditCardAddress($data['address']);
}
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
My number one problem was that I had not created (applied for, with instant approval) a
demo account on First Data. I didn't realize this was a separate thing on First Data. On Balanced Payments, for instance, you have one account, and you can run your script on a test url with test values.
From the Administration panel, click "Terminals", then your Gateway number on the ECOMM row (will look something like AH1234-03), then you have to click "Generate" on password save it to your personal notes), then click UPDATE.
Now replace your parameter values in your test scripts. I use a variable assignment block that looks something like this:
define("API_LOGIN", "AH1234-05"); //fake
define("API_KEY", "44p7797xxx790098z1z2n6f270ys1z0x"); //fake
$data = array();
$data['type'] = "03";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vancce";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33320";
$data['cvv'] = "123";
$data['address'] = "1234 N OCEAN BLVD MIAMI BEACH FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
at the end of the VinceG test scripts, I output my gateway response with a print_r, like this:
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
echo "<pre>";
print_r($firstData);
Hi guys :) I am trying to take all meeting from resource meeting box, but when i try to take subject like this $subject = $event->Subject it displays name by whom meeting was created. $request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = "mail#domain.com" This is code how i select resource meeting box.
I want to take meeting subject by other way and i will be glad if you will help me :)
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate ='2014-03-28T15:00:00+04:00';// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00 "Y-m-d\TH:i:sO"
$request->CalendarView->EndDate = '2015-03-28T15:00:00+04:00';// an ISO8601 date later than the above "Y-m-d\TH:i:sO"
// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = "meetingroom#gcfund.ge";
// Send request
$response = $ews->FindItem($request);
// Loop through each item if event(s) were found in the timeframe specified
if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
$events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
// $db_selected = mysql_select_db('meeting_room',$con);
// $res=mysql_query("SELECT ID FROM meeting");
// while($row = mysql_fetch_array($res)){
// echo $row['ID'];
// echo "<br>";
// }
foreach ($events as $event){
$id = $event->ItemId->Id;
$change_key = $event->ItemId->ChangeKey;
$start = $event->Start;
$end = $event->End;
$subject = $event->Subject;
$location = $event->Location;
This subject displays by whom meeting was created. I want this info too but i want Subject too.. Please Help :)
This is an issue with Exchange (not your code, or the PHP library, or EWS)
Several blogs, such as this one: http://www.slipstick.com/exchange/cmdlets/meeting-organizers-name-appears-in-subject-line/ indicate that you can perform some PowerShell commands to change the Exchange server configuration. Note that if you change the configuration, it will apply for all new meetings/appointments added after the configuration change (existing meetings/appointments will stay as-is).
If you don't have PowerShell access to the Exchange server but do have administrator access via another system, you might be able to achieve the same configuration change through the interface for that system. For example, on a Parallels hosted exchange system, login to Parallels as administrator, go to Exchange, go to Resource mailboxes, edit the room resource, and untick the "Add organizer to subject" checkbox under the "Resource scheduling" tab. As far as I can tell, this just performs the same PowerShell action behind the scenes.
There may be similar options in other systems (e.g. Office 365) though I haven't looked into that.
Having said all that, I have found that making this configuration change didn't help in my case: I created a new meeting against a room resource, however the subject ended up as "" (empty string) instead of the correct subject or the organiser's name. In any case, give the configuration change a try, as other people have apparently had success with it.
I have been searching for days for a working example! The Netsuite documentation is really poor. I don't know what exactly are the config parameters or where I can get them.
I'm recreating the get_customer example.
My code:
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = "21";
$request->baseRef->type = "customer";
$getResponse = $service->get($request);
if (!$getResponse->readResponse->status->isSuccess) {
echo "GET ERROR";
} else {
$customer = $getResponse->readResponse->record;
echo "GET SUCCESS, customer:";
echo "\nCompany name: ". $customer->companyName;
echo "\nInternal Id: ". $customer->internalId;
echo "\nEmail: ". $customer->email;
}
?>
This is the thrown error:
Webservice host must be specified in NSPHPClient->__construct()
How can I fix this?
To be clear, there should be a file in the same directory as NetSuiteService.php called NSconfig.php. You don't need to include this file in your script; it gets called from NSPHPClient.php. The default NSconfig.php looks like this:
$nsendpoint = "2013_2";
$nshost = "https://webservices.netsuite.com";
$nsemail = "jDoe#netsuite.com";
$nspassword = "mySecretPwd";
$nsrole = "3";
$nsaccount = "MYACCT1";
The nsendpoint and nshost should stay as they are.
The tricky part is getting the correct settings for the other variables. First off, you need to Set up Web Services (http://www.netsuite.com/portal/partners/integration/download/SuiteTalkWebServicesPlatformGuide_2012.2.pdf Starting at page 34), then you need to create a Web Services Role (page 44), and make sure that Role has the necessary permissions. Assign that Role to a user that also has the appropriate permissions, then...
nsemail = the email of the user with the web services role
nspassword = the password of the nsemail user
nsrole = the internal role id of the web services role
nsaccount = your netsuite account number (most likely six digits)
(for info on seeing your internal role ids, see page 20 of the PDF above.)
Make sure that you have included the NSconfig.php file. Also you need to modify this file with your account credentials
I am trying to use the Zend_Gdata_Calendar library to create a new event on the Google Calendar API and am struggling to work out how to set the visibility - has anyone any ideas how to actually do it?
The construct of my class has
$this->calendar_client = Zend_Gdata_ClientLogin::getHttpClient($this->user_name, $this->password, Zend_Gdata_Calendar::AUTH_SERVICE_NAME);
Where the user_name and pass_word are the login details for an account which is able to write to the calendar. The following works
$gdataCal = new Zend_Gdata_Calendar($this->calendar_client);
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$newEvent->where = array($gdataCal->newWhere($where));
$newEvent->content = $gdataCal->newContent($content);
$newEvent->visibility = 'private';
$when = $gdataCal->newWhen();
$when->startTime = $start_time;
$when->endTime = $end_time;
$newEvent->when = array($when);
$createdEvent = $gdataCal->insertEvent($newEvent,"https://www.google.com/calendar/feeds/{$email}/private/full");
($title, $where, and $content are text strings passed into the function)
However the visibility doesn't seam to get used.
I have tried the visibility shown above and also each of the following,
$newEvent->setVisibility($gdataCal->newVisibility('private'));
$newEvent->setVisibility($gdataCal->newVisibility(true));
$newEvent->setVisibility($gdataCal->newVisibility(false));
And while these all work (i.e. an event is created at the correct time) the private flag is never set!
Answering my own question you need to use a URI for it!
$newEvent->visibility = $gdataCal->newVisibility("http://schemas.google.com/g/2005#event.public");
$newEvent->visibility = $gdataCal->newVisibility("http://schemas.google.com/g/2005#event.private");