Inserts - Create new content

The following will insert information relating to the parameters that are passed to the API.
To use the API for getting contractor information call the following link:
https://samepage.com.au/api/contractor
With the required POST variables and any additional variables you require.
For any API call the following variables must be posted:
Variable Info
accessKey The access key can be obtained through the Admin page in the section at the top of the right column called "API Access Key".
method Method specifies what the API should be aiming to achieve with the posted data. The three options are:
  1. get
  2. insert
  3. update
In this case use insert for anything mentioned below.
type The type parameter is a further definition of what the API should be aiming to achieve with the posted data.
These will be outlined in more detail below, as each type has it's own list of variables that can be set .
format The format parameter tells the API how you want the data returned. The default return value is json if this parameter is not set.
  • json
  • php
NOTE: The returned php is a sanatized string

To return everything for a particular GET simply pass it no additional parameters (accessKey, method and type are the only required parameters).
All returned data is order as follows:
  • head =>
    • status - This will be a 1 if successful, 0 if an error has occurred, 2 if a warning occurred.
    • error_number - This will be a numeric error value and is only set if status is not 1.
    • error_message - This will be a String outlining what went wrong and is only set if status is not 1.
  • body - This holds the id for the item created.
NOTE: Be aware that all variables are case-sensitive.

Contact

Insert a new contact
Vars Type Req? Notes
email String Yes The contact's email.
fname String Yes The contact's first name.
lname String Yes The contact's last name.
phone String No The contact's phone number.
organisation String No The organisation that the contact is associated with.
role String No The role in the organisation that the contact is associated with e.g. Assistant

Contact Property Information

Insert new generic property contact information.
Vars Type Req? Notes
address String Yes The address must be in the following format:
{Street Number} {Street Name} {Street Type}, {Suburb}, {State} {Post Code} [{Country}]
Where Country is optional.
postal String No The postal address this must be in the same structure as the address.
invoiceFreq String No The invoice frequency for the property, this value should be set too any of the following
  • day
  • week
  • fortnight
  • month
  • FOM
NOTE: FOM = First of Month. All values are case sensitive.

Employee

Insert a new employee
Vars Type Req? Notes
email String Yes The employees email address.
name String Yes The employees name.
startDate datetime Yes The starting date of the employee.
endDate datetime Yes The day the employee is leaving, if this is unknown set it to '9999-12-31 23:59:59'.
team String No The employee's team.
affiliation String No Employee's affiliation to the company.
role String No Employee's role within their team.
confirmed String No
  • 'true' - makes employee green in the roster.
  • 'false' - makes employee purple in the roster.
  • 'hol' - makes employee orange in the roster.
  • 'sick' - makes employee blue in the roster.
recPattern String No This is a special alphanumeric string, it is structured as:
[type]_[interval]_[day]_[interval2]_[days]#extra
See Recurring Patterns for more info.

Equipment

Insert a new equipment item
Vars Type Req? Notes
name String Yes The name of the equipment item to be added.

Item

Insert a new invoice
Vars Type Req? Notes
id String Yes The id for the property.
invoiceDate date Yes The date the invoice was created.
amount float Yes The amount the invoice is for.
dueDate date Yes The date the invoice is due.
owing float Yes The amount still owing on the invoice.
username String Yes The username of the employee that is uploading the file. They must be employed by the company or the invoice will fail to upload/save.
service String No The service the invoice is for. If entered the invoice will only show on the related services page, if no service is entered the invoice is displayed across all services.
filename String No The filename for the invoice file being uploaded.
file Base64 String No This is required if a filename is specified. The String should be in base64 so it can be correctly decoded and saved as a file on the server.

Format Code
php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://samepage.com.au/api/contractors");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$file = "invoice.pdf";
$handler = fopen($file, "r");
if (filesize($file) > 0)
$content = fread($handler, filesize($file));
fclose($handler);
$pdf = base64_encode($content);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
"accessKey" => $myApiKey,
"format" => "php",
"method" => "insert",
"type" => "invoice",
"id" => $propertyId,
"invoiceDate" => "01-10-2013",
"amount" => "514.03",
"dueDate" => "15-10-2013",
"owing" => "202.01",
"username" => $username,
"service" => "Gardening",
"filename" => $filename,
"file" => $pdf
)));
$server_output = curl_exec($ch);
echo "<pre>";
print_r(unserialize($server_output));
echo "</pre>";
curl_close($ch);

Item

Insert a new item
Vars Type Req? Notes
name String Yes The item's name.
price float Yes The item's cost.
fixedPrice String No 'true' if the price should not be multiplied by the amount of hours worked. Only used if the item is a service.

Job

Insert a new Job
Vars Type Req? Notes
address String Yes The address the job is for, the address must be in the following format:
{Street Number} {Street Name} {Street Type}, {Suburb}, {State} {Post Code} [{Country}]
Where Country is optional.
service String Yes The service for the job, this must be a valid service please see here for a list of valid services.
startDate datetime Yes The starting date of the job.
endDate datetime Yes The day the job is will no longer be undertaken, if this is unknown set it to '9999-12-31 23:59:59'.
hours float Yes The hours required to complete the job.
lat float Yes The job's latitudal position.
lng float Yes The job's longitudal position.
team String No The team name that will be completing the job.
notes String No This visit only notes for the job. These should not be entered if the job is going to reoccur.
seriesNotes String No Every visit notes for the job.
confirmDay String No A value of 'true' will turn the job green in the Calendar.
scope String No The scope of works for the job.
watchSymbol String No A value of 'true' will put a watch symbol on the job indicating it should be done at the specified time.
key int No The id for the key that goes with this job.
invoiceFrequency String No Correct values are:
  • day
  • week
  • fortnight
  • month
  • FOM

NOTE: FOM = First Of Month.
recPattern String No This is a special alphanumeric string, it is structured as:
[type]_[interval]_[day]_[interval2]_[days]#extra
See Recurring Patterns for more info.

Key

Insert a new key
Vars Type Req? Notes
keyName String Yes The description/name for the key.

Quote

Insert a new quote
Vars Type Req? Notes
address String Yes The address the job is for, the address must be in the following format:
{Street Number} {Street Name} {Street Type}, {Suburb}, {State} {Post Code} [{Country}]
Where Country is optional.
service String Yes The service must be a valid service, please see here for a list of valid services.
startDate datetime Yes This is the start date for the quote.
endDate datetime Yes This is the end date for the quote.
assignTo String No An employee's email address that should be assigned to complete the quote.
notes String No Any notes about/for the quote.
confirmed String No A value of 'true' will turn the quote green in the Calendar.
templateId int No The id for the pdf template to be used.

Role

Insert a new role
Vars Type Req? Notes
role String Yes The role's name.
priority int No The priority of the role, the lower the number the sooner it will be assigned to a team member.

Scope

Insert a new scope
Vars Type Req? Notes
scope String Yes The scope for the service.
service String Yes The service the scope is for, this must be a valid service. Please see here for a list of valid services.

Team

Insert a new team
Vars Type Req? Notes
team String Yes The team name.
subcontracted String No A value of 'true' is used if the team is a subcontractor.

Recurring Patterns

This is a special alphanumeric string, it is structured as:
[type]_[interval]_[day]_[interval2]_[days]#extra

Try experimenting with the following code to generate recurring patterns:
HTML:
<div class='dhx_form_repeat' id='repeatForm' style='height:140px;width:95%;margin-left:2%;margin-top:8px;margin-bottom:5px;'>
<form>
<div class='dhx_repeat_left'>
<label>
<input class='dhx_repeat_radio' type='radio' name='repeat' value='day' />Daily
</label><br />
<label>
<input class='dhx_repeat_radio' type='radio' name='repeat' value='week'/>Weekly
</label><br />
<label>
<input class='dhx_repeat_radio' type='radio' name='repeat' value='month' checked />Monthly
</label><br />
<label>
<input class='dhx_repeat_radio' type='radio' name='repeat' value='year' />Yearly
</label><br />
<label>
<input class='dhx_repeat_radio' type='radio' name='repeat' value='seasonal' />Seasonal
</label>
</div>
<div class='dhx_repeat_divider' id='leftDivider'></div>
<div class='dhx_repeat_center'>
<div style='display:none;' id='dhx_repeat_day'>
<label>
<input class='dhx_repeat_radio' type='radio' name='day_type' value='d'/>Every
</label>
<input class='dhx_repeat_text' type='text' name='day_count' value='1' />day
<br />
<label>
<input class='dhx_repeat_radio' type='radio' name='day_type' checked value='w'/>Every workday
</label>
</div>
<div style='display:none;' id='dhx_repeat_week'>
Repeat every<input class='dhx_repeat_text' type='text' name='week_count' value='1' />week next days:<br />
<table class='dhx_repeat_days'>
<tr>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='1' />Monday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='4' />Thursday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='2' />Tuesday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='5' />Friday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='3' />Wednesday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='6' />Saturday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week_day' value='0' />Sunday
</label><br /><br />
</td>
</tr>
</table>
</div>
<div id='dhx_repeat_month'>
<label>
<input class='dhx_repeat_radio' type='radio' name='month_type' value='d'/>Repeat every
</label>
<input class='dhx_repeat_text' type='text' name='month_day' value='1' />day of every
<input class='dhx_repeat_text' type='text' name='month_count' value='1' />month<br />
<label>
<input class='dhx_repeat_radio' type='radio' name='month_type' checked value='w'/>On every
</label>
<input class='dhx_repeat_text' type='text' name='month_week2' value='1' />
<select name='month_day2'>
<option value='1' selected >Monday
<option value='2'>Tuesday
<option value='3'>Wednesday
<option value='4'>Thursday
<option value='5'>Friday
<option value='6'>Saturday
<option value='0'>Sunday
</select>
of every<input class='dhx_repeat_text' type='text' name='month_count2' value='1' />month<br />
</div>
<div style='display:none;' id='dhx_repeat_year'>
<label>
<input class='dhx_repeat_radio' type='radio' name='year_type' value='d'/>Every
</label>
<input class='dhx_repeat_text' type='text' name='year_day' value='1' />day of
<select name='year_month'>
<option value='0' selected >January
<option value='1'>February
<option value='2'>March
<option value='3'>April
<option value='4'>May
<option value='5'>June
<option value='6'>July
<option value='7'>August
<option value='8'>September
<option value='9'>October
<option value='10'>November
<option value='11'>December
</select>
month<br />
<label>
<input class='dhx_repeat_radio' type='radio' name='year_type' checked value='w'/>On
</label>
<input class='dhx_repeat_text' type='text' name='year_week2' value='1' />
<select name='year_day2'>
<option value='1' selected >Monday
<option value='2'>Tuesday
<option value='3'>Wednesday
<option value='4'>Thursday
<option value='5'>Friday
<option value='6'>Saturday
<option value='7'>Sunday
</select>
of
<select name='year_month2'>
<option value='0' selected >January
<option value='1'>February
<option value='2'>March
<option value='3'>April
<option value='4'>May
<option value='5'>June
<option value='6'>July
<option value='7'>August
<option value='8'>September
<option value='9'>October
<option value='10'>November
<option value='11'>December
</select><br />
</div>
<div style='display:none;' id='dhx_repeat_seasonal'>
Repeat every<input class='dhx_repeat_text' type='text' name='week2_count' value='1' />week on days:<br />
<table class='dhx_repeat_days'>
<tr>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='1' />Monday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='4' />Thursday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='2' />Tuesday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='5' />Friday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='3' />Wednesday
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='6' />Saturday
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='week2_day' value='0' />Sunday
</label><br /><br />
</td>
</tr>
</table><br />
During the months:<br />
<table class='dhx_repeat_days'>
<tr>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='0' />January
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='4' />May
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='8' />September
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='1' />February
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='5' />June
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='9' />October
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='2' />March
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='6' />July
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='10' />November
</label>
</td>
<td>
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='3' />April
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='7' />August
</label><br />
<label>
<input class='dhx_repeat_checkbox' type='checkbox' name='month3_day' value='11' />December
</label>
</td>
</tr>
</table>
</div>
</div>
<div class='dhx_repeat_divider' id='rightDivider'></div>
<div class='dhx_repeat_right' style='width:140px;margin-top:-5px;'>
<label>
<input class='dhx_repeat_radio' type='radio' name='end' checked/>No end date
</label><br />
<label>
<input class='dhx_repeat_radio' type='radio' name='end' />End after
</label>
<input class='dhx_repeat_text' type='text' name='occurences_count' value='1' />occurrences<br />
<label>
<input class='dhx_repeat_radio' type='radio' name='end' />End by
</label>
<input class='dhx_repeat_date' style='width:90%;' type='text' name='date_of_end' value='
scheduler.config.repeat_date_of_end
' /><br />
</div>
</form>
</div>
<div style='clear:both'> </div>
Select All

CSS:
.dhx_repeat_right{margin-right:55px;}
div.dhx_form_repeat input.radio{margin:-4px 0 0 -4px!ie;}
div.dhx_form_repeat input.checkbox{margin:0 0 0 -4px!ie;}
.dhx_form_repeat,.dhx_form_repeat input{padding:0;margin:0;padding-left:5px;font-family:Tahoma,Verdana;font-size:11px;line-height:24px;}
.dhx_form_repeat{overflow:hidden;height:0;background-color:#FFF4B5;}
.dhx_cal_light_wide .dhx_form_repeat{background-color:transparent;}
.dhx_repeat_center,.dhx_repeat_left{height:115px;padding:10px 0 10px 10px;float:left;}
.dhx_repeat_left{width:95px;}.dhx_repeat_center{width:335px;margin-top:12px;}
.dhx_repeat_divider{float:left;height:115px;border-left:1px dotted #DCC43E;width:1px;}
.dhx_repeat_right{float:right;height:115px;width:160px;padding:10px 3px 10px 10px;margin-top:7px;}
input.dhx_repeat_text{height:16px;width:27px;margin:0 4px 0 4px;line-height:18px;padding:0 0 0 2px;}
.dhx_form_repeat select{height:20px;width:87px;padding:0 0 0 2px;margin:0 4px 0 4px;}
input.dhx_repeat_date{height:18px;width:80px;padding:0 0 0 2px;margin:0 4px 0 4px;background-repeat:no-repeat;background-position:64px 0;border:1px #7f9db9 solid;line-height:18px;}
input.dhx_repeat_radio{margin-right:4px;}
input.dhx_repeat_checkbox{margin:4px 4px 0 0;}
.dhx_repeat_days td{padding-right:5px;}
.dhx_repeat_days label{font-size:10px;}
.dhx_custom_button{width:90px;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;border-radius:4px;}
.dhx_custom_button_recurring{background-image:url(./imgs/but_repeat.gif);background-position:-5px 20px;width:20px;margin-right:10px;}
.dhx_cal_light_rec{width:640px;}
.dhx_cal_light_rec .dhx_cal_larea{width:632px;}
.dhx_cal_light_rec.dhx_cal_light_wide{width:816px;}
.dhx_cal_light_rec.dhx_cal_light_wide .dhx_cal_larea{width:808px;}
Select All

Using the variables from the code above the 5 parameters for a recPattern are then as follows:
[repeat]_
[day_count/week_count/month_count/month_count2/year_day/year_week2/week2_count]_
[month_day2/year_day2/month3_day]_
[month_week2/year_week2]_
[week_day/week2_day]#
extra
The extra component is:
  • 'no' - if no end date is selected. The end date should then be set to something ridiculous e.g. 00:00:00 31-12-9999
  • The number of occurrences that was entered to end after. eg '2'. In this case the endDate parameter is set to be equal to the start date.
  • If an end is specified then nothing is entered after the #, and the endDate should be set to be the same as the end date entered.
NOTES:
month_day sets the day component of the start date.
year_month2 sets the month component of the start date.
year_day and year_month set the day and month components of the start_date.
Any daily or yearly recurring pattern must have the first 2 parameters as 'day_1' or 'year_1' respectively then continue with the rest of the pattern.

Services List

For a constantly updated list use a 'get' query to the API with the type 'serviceList'. Otheriwse the following is a list of all the valid services:
  1. Air Conditioning
  2. Antennas
  3. Appliances
  4. Bins In
  5. Bins Out
  6. Blinds and Awnings
  7. Blowing
  8. Building Management
  9. Carpet Cleaning
  10. Construction
  11. Cleaning
  12. Doors and Windows
  13. Electricals
  14. Fencing
  15. Fire Safety
  16. Gardening
  17. Generators
  18. Glazing
  19. Gutter Cleaning
  20. Handyman Tasks
  21. Hard Landscaping
  22. Irrigation
  23. Lawn Mowing
  24. Lifts
  25. Locks
  26. Painting
  27. Paving
  28. Pest Control
  29. Plumbing
  30. Pool Cleaning
  31. Pool Repairs
  32. Pressure Washing
  33. Roofing and Guttering
  34. Rubbish Removal
  35. Sailmaking
  36. Security
  37. Signage
  38. Soft Landscaping
  39. Telecommunications
  40. Tennis Court Repairs
  41. Tiling
  42. Tools Maintenance
  43. Tree Lopping
  44. Waste Management
  45. Waterproofing