Skip to content

Instantly share code, notes, and snippets.

@anderssonjohan
Last active October 21, 2019 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anderssonjohan/1ebf49273b35e1e293886635d3052f52 to your computer and use it in GitHub Desktop.
Save anderssonjohan/1ebf49273b35e1e293886635d3052f52 to your computer and use it in GitHub Desktop.
Upload and attach file to a case in Lime Field

Step 1 - POST to api/files to create a file object

$ curl -v -u user:pass -H 'Accept: application/json' -H 'Content-Type: application/json' \ 
  -d '{}' https://appname.remotex.net/api/files/
< HTTP/2 201
< content-type: application/json
< content-length: 421
< location: https://appname.remotex.net/api/files/19102101595
< etag: "1"
< apistatusmessage: Created
{"Id":"19102101595","CRMSystemId":"","Title":"","Description":"","FileName":"",
"ContentType":"","Length":0,"Content":{"Title":"","Href":"files/19102101595/"},
"Created":"2019-10-21T16:11:03.8153302Z","Updated":"2019-10-21T16:11:03.8153302Z",
"CreatedBy":{"Href":"users/user","Title":"User"},"UpdatedBy":{"Href":"users/user","Title":"User"},
"Href":"files/19102101595","Revision":1,"ContentHash":""}

Step 2 - PUT file content using api/files/id/filename.ext

$ curl -v -u user:pass -T ./cat1.jpg -X PUT https://appname.remotex.net/api/files/19102101595/cat1.jpg
< HTTP/2 204
< apistatusmessage: No Content

Step 3 - Connect file and case using commands

The following command batch will attach the uploaded file to the case at /api/cases/191003-3897. The command batch response succeeds when HasErrors = false. The resources changed by the command are listed in the AffectedItems array of each command result.

$ curl -v -u user:pass -H 'Accept: application/json' -H 'Content-Type: application/json' \ 
 -d '{"Commands":[{
 "Name":"AddAttachmentToCase",
 "Target":"cases/191003-3897",
 "Parameters":[{"Name":"File","Values":["files/19102101595"]}]
 }]}' https://appname.remotex.net/api/commands/
< HTTP/2 OK
< content-type: application/json
< content-length: 415
< apistatusmessage: OK

{
  "Href":"commands/",
  "HasErrors":false,
  "Received":"2019-10-21T16:07:53.0885076Z",
  "Commands":[
    {
      "HasErrors":false,
      "AffectedItems":[{"Href":"files/19102101595","Revision":"5"},{"Href":"cases/191003-3897","Revision":"4"}],
      "Command":{"Name":"AddAttachmentToCase","Target":"cases/191003-3897","Parameters":[{"Name":"File","Values":["files/19102101595"],"Value":"files/19102101595"}]},
      "Code":"Success"
    }
  ],
  "ErrorMessages":""
}

Note: Skipping step 2 would attach an empty file to the case and could break other integrations expecting all attached files to have filename and content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment