API New property import
From Jomres v4 manual
Contents |
Introduction
New in v4.2.1 of Jomres is a property maker class. This is intended for use by the API plugin to enable importing of propertys, and the corresponding functionality is found in 0.9.6 of the API plugin.
A copy of the code I've been using to test the API handling can be found here : http://forum.jomres.net/index.php?topic=2444.0.
Why?
Why are we using the API instead of a standard Jomres plugin?
It's functionality that the API needs, and if I were to create a plugin to do the same thing, then we'd have more code doing the same thing. 2X code = 2X the potential for bugs and 2X the work required to fix them. Additionally, if I want to add new features to the functionality then that's more work again.
How do I use it?
Firstly I'm going to assume that you've got some understanding of php. This document isn't intended for users with no php coding experience. Instead, it's a pointer for those developers who need guidance on how to use the API's functionality.
Ok, You've viewed the post linked above and downloaded the attached zip file. In that zip there are a number of files, the one we're interested in is query_site_property_newproperty_tocmsuser.php (see Appendix 1).
This is a working example of some code that calls a remote Jomres server and creates a new property. The details of the property are hard coded in this example. If you want to import many properties it's more likely that you'll need to read from a CSV file (see Appendix 2 for related links).
An example of a script that does the import from a CSV file follows. Note that in this example I've used a ^ symbol as a seperator instead as it's very rarely used in content and reduces the risk of commas (,) in content breaking the fields unintentionally.
<?php require('config.php'); require('communicate.class.php'); $config=getConfig(); $secret = 'KhPMJtBtwtvvtxhr'; $row = 0; // I've added the following to make manipulating the data a little easier. $data_cms_user_id = 0; $data_roomClass = 1; $data_property_name = 2; $data_property_street = 3; $data_property_town = 4; $data_property_region = 5; $data_property_country = 6; $data_property_postcode = 7; $data_property_tel = 8; $data_property_fax = 9; $data_property_email = 10; $data_property_mappinglink = 11; $data_property_description = 12; $data_property_checkin_times = 13; $data_property_area_activities = 14; $data_property_driving_directions = 15; $data_property_airports = 16; $data_property_othertransport = 17; $data_property_policies_disclaimers = 18; $data_propertyType = 19; $data_stars = 20; $data_features_list = 21; $data_rate_per_night = 22; $data_mrpsrp = 23; { $comm = new jomres_communication(); $comm->setAPIkey($config['apiKEY']); $comm->setRemoteServer($config['jomres_server']); $comm->enableDebugging(); $comm->addField('cms_user_id',$data[$data_cms_user_id ]); $comm->addField('roomClass',$data[$data_roomClass ]); $comm->addField('property_name',$data[$data_property_name ]); $comm->addField('property_street',$data[$data_property_street ]); $comm->addField('property_town',$data[$data_property_town ]); $comm->addField('property_region',$data[$data_property_region ]); $comm->addField('property_country',$data[$data_property_country ]); // Must be the two char code, eg GB $comm->addField('property_postcode',$data[$data_property_postcode ]); $comm->addField('property_tel',$data[$data_property_tel ]); $comm->addField('property_fax',$data[$data_property_fax ]); $comm->addField('property_email',$data[$data_property_email ]); $comm->addField('property_mappinglink',$data[$data_property_mappinglink ]); $comm->addField('property_description',$data[$data_property_description ]); $comm->addField('property_checkin_times',$data[$data_property_checkin_times ]); $comm->addField('property_area_activities',$data[$data_property_area_activities ]); $comm->addField('property_driving_directions',$data[$data_property_driving_directions ]); $comm->addField('property_airports',$data[$data_property_airports ]); $comm->addField('property_othertransport',$data[$data_property_othertransport ]); $comm->addField('property_policies_disclaimers',$data[$data_property_policies_disclaimers ]); $comm->addField('propertyType',$data[$data_propertyType ]); $comm->addField('stars',$data[$data_stars ]); $comm->addField('features_list',$data[$data_features_list ]); $comm->addField('rate_per_night',$data[$data_rate_per_night ]); $comm->addField('mrpsrp',$data[$data_mrpsrp ]); $comm->addField('query','set.site.property.newproperty.tocmsuser'); $comm->sendQuery(); $result=$comm->getResponse(); $results[]=$result; } ?>
The mycsvfile.csv file contains the following:
62^1^New Import Property 1^Import street^Import town^Import region^Import country'^Import postcode^Import tel^Import fax^Import email^Import mapping^Import description^Import checkin^Import activities^Import driving^Import airports^Import othertransport^Import policies^1^4^6,7^101.55^MRP 62^1^New Import Property 2^Import street^Import town^Import region^Import country'^Import postcode^Import tel^Import fax^Import email^Import mapping^Import description^Import checkin^Import activities^Import driving^Import airports^Import othertransport^Import policies^1^4^6,7^101.55^MRP
Notes
Before you send requests to the remote Jomres server, you'll need to collect some information and include it in your csv or code.
- The CMS user's id. In Joomla for example the admin user's id is typically 62. In Jomres standalone it would probably be 1.
- The remote Jomres server's "secret" key. In Joomla this is in configuration.php (eg. var $secret = 'KhPMJtBtwtvvtxhr';) and in Jomres Standalone it's in jomres_standalone_config.php (eg. $showtime->secret = "850m1j77m2scxb8z345hn6vt5";).
- The property type id. Eg Hotel, Villa, Cottage etc. You can find these in the administrator area of your site -> global propertys types.
- The roomClass id. The importer offers the ability to create a basic tariff during the import phase but to do that it needs to know the default room type. You can get a room/property type by going into the administrator area and viewing the "room types" menu option. Here you'll see a list of room types, hover over the edit icon for a room type and in the url you'll see something like "&task=editGlobalroomTypes&rmTypeUid=1". You want the rmTypeUid number.
Appendix 1
// Change config.php require('config.php'); // The communications class file require('communicate.class.php'); // Get our configuration $config=getConfig(); $comm = new jomres_communication(); $count = " 3 "; $comm->setAPIkey($config['apiKEY']); $comm->setRemoteServer($config['jomres_server']); // Set this if you want to echo the responses and/or any errors $comm->enableDebugging(); // This is a "site" query (ie. it's not specific to either an existing property or user) (ok, the user already exists, but I don't believe that adding a property should be a user function) $comm->addField('cms_user_id',62); $comm->addField('roomClass',1); $comm->addField('property_name','New Remote Property'.$count); $comm->addField('property_street','Remote street'.$count); $comm->addField('property_town','Remote town'.$count); $comm->addField('property_region','Remote region'.$count); $comm->addField('property_country','Remote country'.$count); // Must be the two char code, eg GB $comm->addField('property_postcode','Remote postcode'.$count); $comm->addField('property_tel','Remote tel'.$count); $comm->addField('property_fax','Remote fax'.$count); $comm->addField('property_email','Remote email'.$count); $comm->addField('property_mappinglink','Remote mapping'.$count); $comm->addField('property_description','Remote description'.$count); $comm->addField('property_checkin_times','Remote checkin'.$count); $comm->addField('property_area_activities','Remote activities'.$count); $comm->addField('property_driving_directions','Remote driving'.$count); $comm->addField('property_airports','Remote airports'.$count); $comm->addField('property_othertransport','Remote othertransport'.$count); $comm->addField('property_policies_disclaimers','Remote policies'.$count); $comm->addField('propertyType',1); $comm->addField('stars',4); $comm->addField('features_list','6,7'); $comm->addField('rate_per_night',101.55); $comm->addField('mrpsrp',"MRP"); // the 'query' field must always be present, because that tells the Jomres API what sort of request we're sending $comm->addField('query','set.site.property.newproperty.tocmsuser'); $comm->sendQuery(); $result=$comm->getResponse(); //if ($comm->init_success) //echo "It worked<br/>"; //else //echo "It didn't work<br/>"; //echo "Remote enquiry result :<br/>".$result. "<br/>END<br/>"; // Echo the debugging information $comm->debugging($result);
Appendix 2
Here are a couple of pages I found that refer to reading CSVs from files, if you're in need of a quick reminder on how it's done :
GuyFromChennai Read data from a CSV file in PHP
The UK Web Design company : Reading a Delimited File using PHP

