Create Job Items

From MyMobileWorkers API
Revision as of 11:35, 21 August 2013 by Darren.atherton (Talk | contribs)

Jump to: navigation, search

Contents

Summary

Job items can only be added to a PODC job. A job item 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.

This method is transactional. If one item fails validation, then no items will be created.

Returns a list of valid job items and a list of failed job items. Even if items are valid, they will not be created unless there are no failed items.

Multi Part Form Data

Create Job item
URL http://:base_url/:api_path/:version/jobs/job/items
Type POST
Params: api_key required
file required
job_number required
Response JSON

JSON As Body

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

JSON Contents

The JSON file is passed in the post as the "file"
Field Expected Data Required
name varchar(45) ✓
type "C","D"
* Collect/Deliver
✓
quantity int(4) ✓
notes varchar(45)
Fields exclusive to JSON body format:
Standard Fields
Field Expected Data Required
key string - company api key ✓
updating_existing boolean
validate_only boolean


Example Input

Multi Part Form Data

{"items":[{
"type":"C",
"expected_quantity":"4",
"other":"test",
"status":"COMPLETED",
"notes":"exampleNotes",
"name":"darrenItem245"
}]}

JSON As Body

{
   "key":"darrenwebapi",
   "job_number":"123",
   "items":[
      {
         "type":"C",
         "expected_quantity":"4",
         "other":"test",
         "status":"COMPLETED",
         "notes":"exampleNotes",
         "name":"darrenItem"
      }
   ]
}

Example Curl Requests

Multi Part Form Data

curl -F validate_only=false -F update_existing=true -F api_key=darrenwebapi -F job_number=123 -F file=@/Users/darrenatherton/Desktop/webAPICurling/create_job_item_stage.txt http://live.mymobileworkers.com:8080/api/1/jobs/job/items

JSON As Body

curl -X POST -H "Content-Type: application/json" -d '{"key":"darrenwebapi","job_number":"123","items":[{"type":"C","expected_quantity":"4","other":"test","status":"COMPLETED","notes":"exampleNotes","name":"darrenItem"}]}' http://live.mymobileworkers.com:8080/api/1/jobs/job/items

Responses

Example JSON

{
   "result":"failed",
   "failed":[
      {
         "item":{
            "name":"item2",
            "type":null,
            "notes":null,
         },
         "errors":[
            {
               "error_code":"JBI002",
               "error_message":"Job item type is null"
            }
         ]
      }
   ],
   "valid":[
      {
         "name":"item1",
         "type":"C",
         "notes":"notes",
 
      }
   ]
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox