Difference between revisions of "Create Jobs"
(→JSON As Body) |
(→JSON Contents) |
||
| Line 114: | Line 114: | ||
! route (13.7) | ! route (13.7) | ||
| {"route_code":"<routecode>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| | | {"route_code":"<routecode>"} <br /><span style="font-size:80%; font-weight:normal">*nested JSON object</span>|| | ||
| + | |- | ||
| + | ! weight (13.7) | ||
| + | | float || | ||
|- | |- | ||
! customer | ! customer | ||
Revision as of 15:33, 14 November 2013
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.
Multi Part Form Data
| Create Job - Multi Part Form | ||
|---|---|---|
| URL | http://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 | http://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 | ||
|---|---|---|---|
| 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) | ||
| 'timeslot' OR 'date'/'time' | datetime(timeslot) OR date(yyyy-MM-dd)/time(HH:mm:ss) | ✓ | |
| special_instructions | text | ||
| type (type of job) |
"repair","podc","gassafe" | ✓ | |
| mobile_user | {"username":"<username>"} *nested JSON object |
||
| route (13.7) | {"route_code":"<routecode>"} *nested JSON object |
||
| weight (13.7) | float | ||
| customer | {"name":"<customer name>"} *nested JSON object |
||
| product *Repair Only |
varchar(255) | ||
| fault *Repair Only |
varchar(255) | ||
| assets | array of serial numbers - "assets":["123","456"] | ||
| 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) | |
| Standard Fields | ||
|---|---|---|
| Field | Expected Data | Required |
| key | string - company api key | ✓ |
| updating_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", "timeslot":"2013-09-12 23:54:39", "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, "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 http://live.mymobileworkers.com:8080/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"] }]}' http://live.mymobileworkers.com:8080/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." } ] } ] }