Create Jobs

From MyMobileWorkers API
Revision as of 18:38, 19 January 2016 by Ryanmt (Talk | contribs)

Jump to: navigation, search

Contents

Summary

The create job method accepts an array of jobs to be added to the system. A job can be created via two different methods - either as multi-part form data with a JSON file attached and the API key as a parameter, or as JSON content on it's own, with the API key supplied within the JSON.

The timeslot of a job can be inputted either as a timeslot (datetime) or separately as a job_date and a job_time separately. This caters for jobs which may have a listed day but not a specified time.

If the update_existing param is set then any existing jobs will be updated in the system. If set to false or not provided then any job where the job number is not unique will be rejected.

If validate_only is set the jobs will only be validated but not actually inserted. This can be used to check an entire dataset for errors before submitting.

When creating a job, the following formats are allowed date/time:

Multi Part Form Data

Create Job - Multi Part Form
URL https://base_url/api_path/version/jobs
Type POST
Params: api_key required
file required
update_existing optional (default = false)
validate_only optional (default = false)
Response JSON

JSON As Body

Create Job - JSON
URL https://base_url/api_path/version/jobs
Type POST
JSON
{key, validate_only(optional), update_existing(optional), jobs[]}
required
Response JSON

JSON Contents

The JSON is either passed in the post as the "file", or on its own as the "body".
Standard fields (for both JSON or multi-part):
Standard Fields
Field Expected Data Required
job_number varchar(45)
* must be unique
✓
external_id varchar(45)
address_1 varchar(45) ✓
address_2 varchar(45)
address_3 varchar(45)
address_4 varchar(45)
postcode varchar(45) ✓
contact_name varchar(45) ✓
contact_number_1 varchar(45) (7, 10 or 11 digits)
contact_number_2 varchar(45) (7, 10 or 11 digits)
contact_number_3 varchar(45) (7, 10 or 11 digits)
'timeslot' OR 'date'/'time' datetime(timeslot) OR date(yyyy-MM-dd)/time(HH:mm:ss)
special_instructions text
duration (minutes) integer
type
(type of job)
Workflow name. Note- Legacy customers can continue to use "repair", "gassafe" and "podc". New customers should use the exact case when referring to template names ✓
branch {"name":"<branchname>"}
*nested JSON object
mobile_user {"username":"<username>"}
*nested JSON object
route {"route_code":"<routecode>"}
*nested JSON object
priority {"priority_name":"prioritytext"}
*nested JSON object
weight float (in quotes)
customer {"name":"<customer name>"}
*nested JSON object
product
*If applicable
varchar(255)
task
*If applicable
varchar(255)
assets array of serial numbers - "assets":["123","456"]
Gas Safe (nested) object:
Standard Fields
Field Expected Data Required
owner_title varchar(45)
owner_name varchar(45) ✓
owner_address_1 varchar(45) ✓
owner_address_2 varchar(45)
owner_address_3 varchar(45)
owner_address_4 varchar(45)
owner_postcode varchar(45) ✓
owner_contact_number varchar(45) (7, 10 or 11 digits)
owner_email varchar(255)
customer_email varchar(255)
Fields exclusive to JSON body format:
Standard Fields
Field Expected Data Required
key string - company api key ✓
update_existing boolean
validate_only boolean

Example Input

Multi Part Form Data

{"jobs":[{
"job_number":"1813325",
"address_1":"16",
"address_2":"Willey Court",
"address_3":"Galley Hill,Stony Stratford",
"contact_name":"Joe Bloggs",
"contact_number_1":"0770999999",
"mobile_user":{"username":"Unassigned_Jobs_WCS"},
"postcode":"MK11 1NZ",
"special_instructions":"null",
"route":{"route_code":"BLACKPOOL AM"},
"timeslot":"2013-09-12 23:54:39",
"weight":"100",
"type":"gassafe",
"gas_safe_inspection":[{"owner_name":"Fred Bloggs","owner_address_1":"16","owner_postcode":"MK11 1NZ"}]
}]}

JSON As Body

{
   "key":"test",
   "validate_only":"true",
   "update_existing":"true",
   "jobs":[
      {
         "job_number":"sss05",
         "external_id":"hello",
         "address_1":"Rover Lane",
         "address_2":"Glasgow",
         "contact_name":"Joe Bloggs",
         "contact_number_1":"0770999999",
         "contact_number_2":"",
         "mobile_user":{
            "username":"_test32"
         },
         "postcode":"G71 8TS",
         "type":"podc",
         "weight":"100",
         "route":{
            "route_code":"BLACKPOOL AM"
         },
         "timeslot":"2013-09-15 17:54:39",
         "special_instructions":"Door bell is faulty so knock on the door",
         "repair_description":"Replace U Bend",
         "assets":[
            "serialNo456",
            "serialNo789"
         ],
         "gas_safe_inspection":[
            {
               "owner_name":"leej",
               "owner_address_1":"exampleAddress",
               "owner_postcode":"examplePostcode"
            }
         ]
      }
   ]
}

Example Curl Requests

Multi Part Form Data

curl -F validate_only=false -F update_existing=true -F api_key=lee_test -F file=@/Users/user/Desktop/webAPICurling/create_job.txt https://live.mymobileworkers.com:8181/api/1/jobs

JSON As Body

curl -X POST -H "Content-Type: application/json" -d '{"key":"test", "validate_only":"true", "update_existing":"true", "jobs":[{ "job_number":"sss05", "external_id":"hello", "address_1":"Rover Lane", "address_2":"Glasgow", "contact_name":"Joe Bloggs", "contact_number_1":"0770999999", "contact_number_2":"", "mobile_user":{"username":"Darren_test32"}, "postcode":"G71 8TS","type":"podc", "timeslot":"2013-09-15 17:54:39", "special_instructions":"Door bell is faulty so knock on the door", "repair_description":"Replace U Bend", "assets":["serialNo456","serialNo789"] }]}' https://live.mymobileworkers.com:8181/api/1/jobs

Responses

Example JSON

{
	"successful":
	[
		{"job_number":"A0103"},
		{"job_number":"A0245"}
	],
	"failed":
	[
		{
			"job_number":"A0384",
			"errors": 
			[
				{
					"error_code":"WAJ003",
					"error_msg":"Job number already exists."
				}
			]
		}
	]
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox