REST API: Edit Files

Last Updated: July 27, 2018

Description

Edit one or more files that are attached to objects (Example: timesheet). More than 50 files will result in a 413 - Request entity too large error.

Resource Information

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

File properties

When editing a file, you must uniquely identify the file by passing in its id. All other properties defined below may be passed in to the request with a new value in order to change it. If the value passed in is the same as it was previously, or if a particular property is not passed in at all, it will be ignored.

id:
required
Integer. Read-only. Id of this file.
file_name:
optional
String. Name of this file.
meta_data:
optional
JSON object. This is a key / value map of any additional data associated with this file. List of allowed keys:
  • file_description: String. Description of this file.
  • image_rotation: Integer. Original image orientation in degrees

Status Codes

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

_status_code Meaning
200 OK. File was updated successfully.
404 Not Found. File either has never existed or has been deleted.
417 Expectation Failed. Something was wrong or missing with the properties supplied for this file. See the _status_extra value for more detail.

Examples

Update a file.

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

## contents of the tsfile_update.json file are:
{
 "data":
  [
    {
     "id":"123455",   
     "meta_data": {
           "file_description":"Testing PUT request",
           "image_rotation": 180
     }
    }
  ]
}

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

{
 "results": {
  "files": {
   "123455": {
    "_status_code": 200,
    "_status_message": "Updated",
    "id": 123455,
    "uploaded_by_user_id": 19128,
    "file_name": "invisible_minion.png",
    "active": true,
    "size": 95,
    "last_modified": "2017-09-19T00:09:32+00:00",
    "created": "2017-08-24T00:09:32+00:00",
    "linked_objects": [],
    "meta_data": {
     "file_description": "Testing PUT request",
     "image_rotation": 180
    }
   }
  }
 },
 "supplemental_data": {
  "users": {
   "19128": {
    "id": 19128,
    "first_name": "Shree",
    "last_name": "Yalamanchili",
    "group_id": 0,
    "active": true,
    "employee_number": 0,
    "salaried": false,
    "exempt": false,
    "username": "shree",
    "email": "shree_dev@tsheets.com",
    "email_verified": true,
    "payroll_id": "",
    "hire_date": "0000-00-00",
    "term_date": "0000-00-00",
    "last_modified": "2017-08-16T18:32:46+00:00",
    "last_active": "2017-08-16T15:16:22+00:00",
    "created": "2016-04-05T15:41:30+00:00",
    "client_url": "devrocks",
    "company_name": "DevRocks",
    "profile_image_url": "",
    "mobile_number": "",
    "pto_balances": "",
    "submitted_to": "2017-01-22",
    "approved_to": "2016-04-06",
    "manager_of_group_ids": [
        27520
    ],
    "require_password_change": false,
    "pay_rate": 0,
    "pay_interval": "hour",
    "permissions": {
     "admin": true,
     "mobile": true,
     "status_box": true,
     "reports": true,
     "manage_timesheets": true,
     "manage_authorization": true,
     "manage_users": true,
     "manage_my_timesheets": true,
     "manage_jobcodes": true,
     "pin_login": true,
     "approve_timesheets": true,
     "manage_schedules": true,
     "external_access": false,
     "manage_my_schedule": false,
     "manage_company_schedules": true,
     "view_company_schedules": false,
     "view_group_schedules": false,
     "manage_no_schedules": false,
     "view_my_schedules": false
    },
   "customfields": ""
   }
  }
 }
}