Sending Documents via API


Is there anyway to turn files blob data into a base 64 string for sending (both file content string and raw content file string)? I have looked at the document object and the only data i get is an integer.


Hi Robin,

Use the standard Field Processor “Base64 Encode” :slight_smile:

From my Generic Rest connection example I select the “file” property then the Preprocessor:



Hi Neil,

So I’m trying to do this in an event and I’m not adding the field in basics as it’s a one to many relationship. Instead the following coding works out where the Documents object is linked to the case object then gets some of the fields and attributes.

var case_relationships = record_object.schema(base_object_id).relationships;

POST_Confirm.prototype.set_document_details = function(case_relationships){

record_object =  cs.record(this.record_id);

// get document properties from base object (use this in future)
for (let relationship in case_relationships) {

    //get document path
    if(case_relationships[relationship].target_name == 'Documents'){

        var doc_schema = record_object.schema(case_relationships[relationship].target_object_id);
        var doc_properties = record_object.schema(case_relationships[relationship].target_object_id).properties;
        var doc_attributes = record_object.schema(case_relationships[relationship].target_object_id).attributes;

        this.doc_object_id =;
        this.doc_relation_path = case_relationships[relationship].id;

        // get field paths
        for (let property in doc_properties) {

            if(doc_properties[property] == 'Description'){
                this._doc_description = ':' + property;

            else if(doc_properties[property] == 'Document'){
                this._doc_document =':' + property;

            else if(doc_properties[property] == 'Internal Only'){
                this._doc_internal_only = ':' + property;

            else if(doc_properties[property] == 'Case Stage When Added'){
                this._doc_case_stage_when_added = ':' + property;

            else if(doc_properties[property] == 'Upload reason'){
                this._doc_upload_reason = ':' + property;


        // get attribute paths
        for (let attribute in doc_attributes) {

            if(doc_attributes[attribute] == 'create_stamp'){
                this._doc_date_created = ':' + attribute;
            else if(doc_attributes[attribute] == 'file_id'){
                this._doc_file =':' + attribute;
            else if(doc_attributes[attribute] == 'filename'){
                this._doc_filename = ':' + attribute;

            else if(doc_attributes[attribute] == 'mime_type'){
                this._doc_mime_type = ':' + attribute;

            else if(doc_attributes[attribute] == 'extension'){
                this._doc_extension = ':' + attribute;

// get all documents from link
let doc_records = record_object.get_related(this.doc_relation_path);

let select = {
    description : this._doc_description,
    document : this._doc_document,
    internal_only : this._doc_internal_only,
    case_stage_when_added : this._doc_case_stage_when_added,
    upload_reason : this._doc_upload_reason,
    date_created : this._doc_date_created,
    file : this._doc_file,
    filename : this._doc_filename,
    mime_type : this._doc_mime_type,
    extrension : this._doc_extension

while (rec = doc_records.next_row()) {

    var item = rec.get(select, 'displayable');
    let document_object = cs.record(item.document);



When running this the document property and file attribute gives a 4 digit integer. If I try and use cs.readfile I can only get this working on a single file not where I’m looking through each response and even with that by using cs.base64_encode it cannot get given the header data:image/gif;base64, and putting into the URL bar showing the image Im expecting.


If I read what you’re trying to do correctly, it’s nearly there: cs.read_file takes a record ID plus field path, both of which you have by the time you’re creating your doc_details array. If the last while() changes to:

		while (rec = doc_records.next_row()) {
			var item = rec.get(select, 'displayable');			
			let file_contents = cs.read_file(rec.get(":id"),this._doc_file,"base64");
			item.file_contents = file_contents

…the cs.log() shows that you have the contents as part of the details array (I tried it without base64 encoding, and the csv file contents are what I’d expect to see, so the base64 is being applied):

1 Like

Hi Phil,

Finally got it all working able to send out data via a curl event


1 Like