I’ve came across many questions around using the Web Services API in Sugar to upload files into Sugar. As you know, Sugar supports storing files attached to the records of Notes, as well as having a Documents module to track uploaded files and manage the revisions made to them. Our web services API supports uploading to them, but it isn’t exactly clear on how to do this. For today, let’s look at how to do this for Documents
Let’s first look at create a new Document record, and then uploading a new Document to it. First the easy part, let’s build the document record.
Now with a Document record, we can call the set_document_revision method to actually upload the document. You’ll be pushing the raw document contents up here, and you’ll need to be sure it’s base64 encoded.
The nice part about the Documents module is that it stores each revision made to a document as a part of the record. This means that for each new call made to set_document_revision, it automatically creates a new revision for you and saves the old one.
Come back tomorrow and we’ll see how to upload Note attachments to Sugar.