niquelb
niquelb

Reputation: 1

Upload files in SuiteCRM using the v4.1 API through the body of the request

I'm using the Suite CRM v4.1 API and I'm developing a webapp that allows users to upload files to the CRM.

The code works, however the request requires the use of parameters which get appended to the URL, hence when uploading a file (which has to be encoded in Base 64) I run into the URL char limit (2k~ characters) since even an empty pdf encoded in B64 takes up at least 30k characters. (when uploading an empty or almost empty txt file it works fine because of this).

The solution would obviously be to send the data in the request body, however the documentation isn't great and I haven't found any way of doing so.

I may be doing this completely the wrong way but I haven't found anything in regards to sending data to the API using the request body.

If anyone has encountered the same issue in the past and has any tips I'd appreciate it.

The params I'm sending look like this on Postman:

method:set_document_revision
input_type:JSON
response_type:JSON
rest_data: {
 "session":"[token]",
 "note": {
   "id":"[entry id]",
   "file":"[encoded file (in B64)]",
   "filename":"[filename eg. test.pdf]"
 }
}

Upvotes: 0

Views: 359

Answers (2)

Shoukat Mirza
Shoukat Mirza

Reputation: 828

I also encountered a similar issue with SuiteCRM v8 API, but I managed to resolve it by sending the file as base64 data in the filecontents parameter.

{
  "data": {
    "type" : "Notes",
    "attributes": {
      "name": "Test Note",
      "file_mime_type" : "text/plain",
      "filename" : "TextFile.txt",
      "filecontents" : "SWYgeW91IGFyZSBhYmxlIHRvIHNlZSB0aGlzLCBpdCBtZWFucyB0aGF0IHRoZSBmaWxlIHVwbG9hZGluZyBpcyB3b3JraW5nIGZpbmUu"
    }
  }
}

enter image description here

Upvotes: 0

niquelb
niquelb

Reputation: 1

I figured it out, aparently it's not a true Rest-Compliant API, the solution is to send the exact data I was sending as params in the body as www-form-unencoded

Upvotes: 0

Related Questions