REST API: Add Jobcode Assignments

Last Updated: May 16, 2017

Description

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

When assigning jobcodes, keep in mind that when assigning a parent jobcode (in a multi-level jobcode scenario), all child jobcodes will also be assigned to the user.

Resource Information

HTTP Method POST
Endpoint https://rest.tsheets.com/api/v1/jobcode_assignments
Authentication Token header required. See authentication section
Request format json object. Pass an array of jobcode assignment objects as the value to a 'data' property (see example below).
Response format json
Response object Jobcode Assignment
Permissions You must be a group manager of the user you're making assignments for, be an admin, or have the manage_users permission.

Required Jobcode Assignment Properties

user_id:
String. User id for this jobcode assignment.

NOTE: You can specify a user_id of 0 to indicate that this jobcode_assignment should apply to all users. This is equivalent to setting the assigned_to_all property to true on a jobcode object.
jobcode_id:
String. Jobcode id for this jobcode assignment.

Status Codes

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

_status_code Meaning
200 OK. Jobcode assignment was created successfully.
417 Expectation Failed. Something was wrong or missing with the properties supplied for this jobcode assignment. See the _status_extra value for more detail.

Examples

Create two new jobcode assignments. One succeeds. The other fails because of a permissions issue with the user_id.

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

## contents of the jobcode_assignment_create.json file are:
{
 "data":
  [
    {
     "user_id":"1234",
     "jobcode_id":"37"
    },
    {
     "user_id":"4567",
     "jobcode_id":"37"
    }
  ]
}



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

{
 "results": {
  "jobcode_assignments": {
   "1": {
    "_status_code": 200,
    "_status_message": "Created",
    "id": 106063,
    "user_id": "1234",
    "jobcode_id": "37",
    "last_modified": "2013-01-17 21:15:18",
    "created": "2013-01-17 21:15:18"
   },
   "2": {
    "_status_code": 417,
    "_status_message": "Expectation Failed",
    "_status_extra": "Oops! You don't have permission to manage that user",
    "user_id": "4567",
    "jobcode_id": "37"
   }
  }
 },
 "supplemental_data": {
  "users": {
   "1234": {
    "id": "1234",
    "first_name": "John",
    "last_name": "Smith",
    "group_id": "983247",
    "active": 1,
    "employee_number": 0,
    "salaried": 1,
    "exempt": 1,
    "username": "jsmith",
    "email": "jsmith@example.com",
    "payroll_id": 127,
    "hire_date": "2011-04-01",
    "term_date": "0000-00-00",
    "last_modified": "2011-04-20T16:21:56+00:00",
    "last_active": "2014-01-28T05:24:59+00:00",
    "created": "2011-04-19T16:20:20+00:00",
    "client_url": "fake",
    "mobile_number": "",
    "approved_to": "2000-01-01",
    "submitted_to": "2000-01-01",
    "manager_of_group_ids": {
     "permissions": {
      "admin": 1,
      "mobile": "",
      "status_box": "",
      "reports": "",
      "manage_timesheets": "",
      "manage_authorization": "",
      "manage_users": "",
      "manage_my_timesheets": "",
      "manage_jobcodes": "",
      "approve_timesheets": "",
      "manage_no_schedules": false,
      "manage_my_schedule": false,
      "manage_schedules": true,
      "manage_company_schedules": false,
      "view_my_schedules": false,
      "view_group_schedules": false,
      "view_company_schedules": false
      }
     }
    }
   },
   "jobcodes": {
    "37": {
     "id": 37,
     "parent_id": 0,
     "assigned_to_all": "",
     "billable": "",
     "active": 1,
     "type": "regular",
     "has_children": "",
     "billable_rate": "0,
     "short_code": "",
     "name": "My Jobcode Name",
     "last_modified": "2014-06-27T21:34:05+00:00",
     "created": "2014-06-27T21:33:45+00:00",
     "required_customfields": {
      }
     "filtered_customfielditems": {
      }
     }
    }
  }
}