Documentation Center

Upload files as attribute values

Upload a file and set it as the value of an attribute.

For security reasons, you need to perform a Login action before making any other public calls to the WorldServer API. The sessionId in the response is your session token. Use this token in all the other calls that you make.

Also, make sure that you have the appropriate user type permissions to perform this API call. To view or update your permissions, in WorldServer, go to Management > User Setup > User Types, and then select your user type.

Prerequisites

To upload a file as the value of an attribute, you need to find out the ID of the attribute definition to which you want to attach the file. You can find out its ID by making a GET call to the following endpoint, and then writing down the ID of the appropriate attribute definition in the response: <protocol>://<ws-host>:<ws-port>/ws-api/v2/attributeDefinitions?token=<sessionId>&resourceType=<value>

In this example, Attachment_Test is a custom Attachment-type attribute defined for tasks (resourceType=TASK). Its ID is highlighted in the response:A screen shot that highlights the ID of an attribute definition in the response to the Get attribute definitions call.

API call

<protocol>://<ws-host>:<ws-port>/ws-api/v2/files/attachments/<attributeDefinitionId>?token=<sessionId>

Details

  • POST method
  • Content-Type in the header: application/json
  • Mandatory body type: form-data, with a file as its content (a property key named file and the file that you want to upload as its value)
  • Mandatory parameters: the session token (as a query string parameter or as a key-value pair in the header), the file (in the form-data body) and the ID of the attribute definition to which you want to attach the file (as a URI parameter)

Response

A screen shot that shows a typical response to this call.

Error messages

MessageStatus code
No session token provided or invalid token401 Unauthorized
Resource ATTRIBUTE_DEFINITION (ID) not found404 Not Found
Internal Server Error:
  • If the value of the attribute definition ID is not a number.
  • If you did not add a file to the form-data body.
500 Internal Server Error