Uploading file via API V8 to Documents module

Hello,

Is it possible to upload a file via API to a Case? I created a Case and while editing in SuiteCRM panel i tried to add a file on field “Updates - Attachment form” to see the value that it gets from postman when retrieving that Case but nothing changed at all.

Thanks.

I assume the same for the API but the upload file button on the interface is a bit broken and it is best to upload and relate a document or note instead

1 Like

Do you know if there’s any correct guide on how to upload a file via API? All i have found are kind of not working.

Also while creating a Document via API with just some info on the request am getting an error of "“detail”: “Notes module with id cb08e375-d6ca-4c4c-941d-5ef2fa18c511 is not found”, which that id is the id of the document which was created a while ago.

Are documents and notes somehow related to each other?

Here’s an example used with postman

Request

POST {{suitecrm.url}}/V8/module

Body

{
  "data": {
    "type": "Document",
    "attributes": {
      "name": "New Document",
         "filename":"image.jpg",
      "filecontents": ""
    }
  }
}
1 Like

With the body you

have sent, this is the following message on the call
filecontents is invalid in module Document.

Request is the same as you wrote on your comment.

What i have done so far is that i can create a Document with this body:

{
“data”: {
“type”: “Document”,
“attributes”: {
“name”: “suitecrm”,
“filename”:“suitecrm”,
“document_name”: “suitecrm”,
“doc_url”: “https://images.unsplash.com/photo-1494548162494-384bba4ab999?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80
}
}
}

After this call am getting the error 400 : Notes module with id db20f96f-171d-4511-4e6a-5ef439898823 is not found. But document still gets created. And it’s the only way to attach a file and working to see that in CRM by adding doc_url, otherwise document is broken.

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”
}
}
}

3 Likes

I have been playing with SuiteCRM API (V8 on 8.8.1) and created few test workflows with N8N (based on @BastianHammer great instructional videos, you really need to see them since documentation and actuall access to api have few significant differences).

My latest issue was how to upload a file, so I would just like to point out that solution provided by @Shoukat is correct. This is important because field used to actually upload binary of the file is not reported in regular module inventory request.

The thing with N8N (and this is very simplified flow) is that you need to convert your document to base64 (therefore here you have convert to base64 node) and only then upload it to CRM, my json code for uploading is as follows:

{ “data”:
{
“type”: “Document”,
“attributes”: {
“name”: “{{ $(‘upload file’).item.json.dokument.filename }}”,
“description”: “this is document description”,
“document_name”: “{{ $(‘upload file’).item.json.dokument.filename }} - {{ $now }}”,
“filename”: “{{ $(‘upload file’).item.json.dokument.filename }}”,
“category_id”: “Letters”,
“last_rev_mime_type”: “{{ $(‘upload file’).item.json.dokument.mimetype }}”,
“filecontents”: “{{ $(‘Extract from File’).item.json.data }}”
}}}

p.s. there appears to be three separate locations where you can write filename so I wrote it in all three

2 Likes

Thank you guys very much for this topic.

The documentation still claims that the API "expects the contents of the file to be assigned to the {fieldname}_file attribute” while in fact it is the “filecontents” attribute.

File uploads via API is an awesome functionality, thank you to all the hardworking devs and the amazing community for giving us this amazing software absolutely for free :slight_smile:

2 Likes