Uploading Note attachments to Sugar via Web Services

sugarcrmdevelopers —  August 17, 2012 — 12 Comments

Yesterday we saw how to upload files to Documents and new revisions of files to Documents via the SugarCRM Web Services API. Note records also support uploading an attachment to them, which we’ll see how to do in today’s post.

First thing’s first, let’s create a Note record for this example.

Where with the Documents module we used the set_document_revision method for doing the upload, the Notes module has it’s own method for doing this with the set_note_attachment method. See the below code snippet for how to do this.

Come back next week and we’ll see how to download files stored in the Documents and Notes module in Sugar via Web Services.

12 responses to Uploading Note attachments to Sugar via Web Services


    Example with note works fine, but having issues with relating an existing document to an account – the result is that Accounts does not show the document in the Documents subpanel…

    // setup for set_relationship: relate document id to account id (use your own ids)
    $parameters = array(
    ‘session’ => $sessionId,
    ‘module_name’ => ‘Accounts’,
    ‘module_id’ => ‘8f64ec8c-5377-0c6f-6a1d-4ff9d18da55b’,
    ‘link_field_name’ => ‘documents’,
    ‘related_ids’ => array(‘b7d2f5a7-0d42-9f8c-cce8-4ff9e9bb481a’)
    $json = json_encode($parameters);
    $postArgs = array(
    ‘method’ => ‘set_relationship’,
    ‘input_type’ => ‘JSON’,
    ‘response_type’ => ‘JSON’,
    ‘rest_data’ => $json
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
    // Make the REST call, returning the result
    $response = curl_exec($curl);
    //JSON response is: {“created”:1,”failed”:0,”deleted”:0}
    // Convert the result from JSON format to a PHP array
    $results = json_decode($response);
    if ( !is_object($results) )
    die(“Error handling result.n”);
    if (count($results) > 0)
    echo “Created relationship”rn”;


    How would I go about attaching a file to a custom file module via rest. I wanted the file upload field on my form so I just made the module of type file and added the custom fields but I cannot seem to upload the file via rest. I’ve tried set_entry, set_document_revision and set_note_attachment, but none of these will work.


    l need to reply to cases via rest api.Is treating case reply as Case notes the best way to do it if so how do l add just a note


    thanks i got here because i am investigating how to use sugar to capture an image from a mobile device android phoneusing html5’s media capture another post indicated the html5 implemented the media capure by overloading the file inlput i am going to modify the notes attachment to capureand store the image.

Trackbacks and Pingbacks:

  1. SugarCRM Developer Blog » Blog Archive » Downloading a Note attachment via Web Services - August 21, 2012

    […] Last week we showed how to upload an attachment to a Note record via SugarCRM Web Services. But what if you want to download that attachment along with the rest of the Note record? Luckily, there’s a method for that called get_note_attachment. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s