REST API: Add Jobcodes

Last Updated: May 12, 2015

Description

Add one or more jobcodes to your company. We will handle batches of up to 50 jobcodes at a time. More than 50 jobcodes will result in a 413 - Request entity too large error.

Resource Information

HTTP Method POST
Endpoint https://rest.tsheets.com/api/v1/jobcodes
Authentication Token header required. See authentication section
Request format json object. Pass an array of jobcode objects as the value to a 'data' property (see example below).
Response format json
Response object Jobcode

Required Jobcode properties

name:
String. Name of the jobcode.

Optional Jobcode properties

For a full list of the properties that may be set on a jobcode, see the Jobcode object.

Status Codes

Each jobcode that is created will come back with a _status_code and _status_message that will indicate whether the jobcode was created successfully. If there was a problem creating a jobcode, there may also be an additional field, _status_extra, which will contain more details about the failure.

_status_code Meaning
200 OK. Jobcode was created successfully.
202 OK. Jobcode accepted but not created because a jobcode with the same parent_id, name and type already exists.
417 Expectation Failed. Something was wrong or missing with the properties supplied for this jobcode. See the _status_extra value for more detail.

Examples

Create two new jobcodes. One succeeds. The other fails because of a duplicate short_code on an existing jobcode.

## REQUEST
curl -H "Authorization: Bearer <Access-Token>" -X POST -i -H "Content-Type: application/json" -d @tsjobcode_create.json "https://rest.tsheets.com/api/v1/jobcodes"

## contents of the tsjobcode_create.json file are:
{
 "data":
  [
    {
     "name":"Customer1",
     "parent_id":"12788279",
     "short_code":"c1",
     "billable":"yes",
     "assigned_to_all":"yes",
     "billable_rate":"37.50"
    },
    {
     "name":"Customer2",
     "parent_id":"12788279",
     "short_code":"c1",
     "billable":"no",
     "assigned_to_all":"no",
     "billable_rate":"37.50"
    }
  ]
}



## RESPONSE
HTTP/1.1 200 OK
Content-Type: application/json

{
 "results": {
  "jobcodes": {
   "1": {
    "_status_code": 200,
    "_status_message": "Created",
    "id": 18059008,
    "parent_id": 17288279,
    "assigned_to_all": true,
    "billable": true,
    "active": true,
    "type": "regular",
    "has_children": false,
    "billable_rate": 37.5,
    "short_code": "c1",
    "name": "Customer1",
    "last_modified": "2013-07-22T19:19:28+00:00",
    "created": "2013-07-22T19:19:28+00:00",
    "required_customfields": [
 
    ],
    "filtered_customfielditems": ""
   },
   "2": {
    "_status_code": 417,
    "_status_message": "Expectation Failed",
    "_status_extra": "Oops! That Short Code is already in use",
    "name": "Customer2"
   }
  }
 },
 "supplemental_data": {
  "jobcodes": {
   "17288279": {
    "id": 17288279,
    "parent_id": 0,
    "assigned_to_all": false,
    "billable": false,
    "active": true,
    "type": "regular",
    "has_children": true,
    "billable_rate": 0,
    "short_code": "asm",
    "name": "Assembly Line",
    "last_modified": "2013-07-12T21:13:14+00:00",
    "created": "2013-05-28T20:18:17+00:00",
    "required_customfields": [
 
    ],
    "filtered_customfielditems": ""
   }
  }
 }
}