Pulsar Attachment API
Single Attachment Actions
readAttachment
This API call returns an array containing a dictionary with the Attachment object matching the Id specified.
Important returned fields:
Body
– base64 encoded attachment data (ifReturnBase64Data
is notfalse
)ThumbBody
– base64 encoded attachment thumbnail data (ifReturnBase64Data
is notfalse
and attachment is an image)FileURL
– local URL to the attachment fileThumbURL
– local URL to the attachment thumbnail file (empty string if attachment is not an image)
Related Pulsar Settings:
var request = {
"type" : "readAttachment",
"data" : {
"Id" : "001234567891234", // Required attachment Id
"ReturnBase64Data" : false // Optional, default true. If false you will still have access to URL of attachment
}
};
bridge.send(request, function (responseData) { alert('The Attachment is located here: ' + responseData.data[0].FileURL });
Normal data reads through 'select' API will not contain Base64 Attachment data in the body field unless that body field has previously been queried from Salesforce or otherwise populated with Base64 data.
queryAttachment
This API call returns an array of dictionaries representing Attachment objects matching the specified filter. The filter is specified in sqlite where clause format, and is applied to objects in the Attachment table only. For example "(ParentId = '001234567891234')" will return all Attachments where the ParentId field is set to 001234567891234. This method will return URLs to a cached version of the Attachment file, but will not return the file data directly as in readAttachment
.
Important returned fields:
FileURL
– local URL to the attachment fileThumbURL
– local URL to the attachment thumbnail file (empty string if attachment is not an image)
Related Pulsar Settings:
var request = {
"type" : "queryAttachment",
"data" : {
"filter" : "ParentId = '001234567891234'"
}
};
bridge.send(request, function (responseData) { alert('The first Attachment is located here: ' + responseData.data[0].FileURL });
The queryAttachment
API call will NOT return the Attachment's Base64 Body field or the Base64 data representing the thumbnail.
createAttachmentFromCamera
The createAttachmentFromCamera
method allows creation of Attachments directly from the device's camera. The intended Attachment ParentId is a required argument. Optionally, you can specify a file name for the attachment, instead of using the name of the original file. On success, the response data contains the Id of the created attachment.
var request = {
"type" : "createAttachmentFromCamera",
"data" : {
"ParentId" : "001234567891234", // Required
"Name" : "AttachmentName.jpg" // Optional
}
};
bridge.send(request, function (responseData) {
if (responseData.type == "createAttachmentResponse") {
alert('Created Attachment Id: ' + responseData.data);
}
else {
// error code
}
});
Create Actions on Multiple Attachments (recommended v14+)
createBatchResponse returned from batch endpoints
All of the following endpoints return a response in the format below. The response below is simplified for brevity.
Full Success – all files saved
{
"type": "createbatchResponse",
"object": "Attachment",
"data": {
"summary": { "success": "TRUE" },
"results": {
"0": {
"objectId": "CURIUM_1111111111_1", // this could also be an 069 ContentDocumentId if performed online.
"success": "TRUE",
"FileURL": "http://127.0.0.1:17014/datacache/FileName1.jpg"
},
"1": {
"objectId": "CURIUM_222222222_2", // this could also be an 069 ContentDocumentId if performed online.
"success": "TRUE",
"FileURL": "http://127.0.0.1:17014/datacache/FileName2.jpg"
}
}
}
}
Partial Success – some files saved
{
"type": "createbatchResponse",
"object": "Attachment",
"data": {
"summary": { "success": "FALSE" },
"results": {
"0": {
"objectId": "CURIUM_1111111111_1", // this could also be an 069 ContentDocumentId if performed online.
"success": "TRUE",
"FileURL": "http://127.0.0.1:17014/datacache/FileName.jpg"
},
"1": {
"success": "FALSE",
"error": "...error message from API for this file..."
}
}
}
}
createAttachmentBatch
The createAttachmentBatch
method allows creation of multiple Attachments directly from Base64 encoded data. An array of objects with their intended parent SObject Id (ParentId), Name, and Body are required arguments. The ContentType of the File may be optionally specified in MIME type format, as in the example below. On success, the response data contains the Id of the created Attachment.
var request = {
"type" : "createAttachmentBatch",
"data" : [
{
"ParentId" : "001234567891234", // Required
"Name" : "FileName.jpg", // Required
"Body" : "AABBCCDDEEFF...", // Base64 data -- Required
"ContentType" : "image/jpeg" // Optional -- manual entry of content type
},
{ ... },
{ ... },
]};
bridge.send(request, function (responseData) {
if (responseData.type == "createbatchResponse") {
// process results
}
else {
// error code
}
});
createAttachmentFromFilePathBatch
The createAttachmentSFFileFromFilePathBatch
method allows creation of multiple Attachments directly from valid, accessible, device file paths. An array of objects with their intended parent SObject Id (ParentId), Name, and Body are required arguments. The ContentType of the File may be optionally specified in MIME type format, as in the example below. Optionally, you can specify a file name, instead of using the name of the original file. On success, the response data contains the Id of the created Attachment.
var request = {
"type" : "createAttachmentFilePath",
"data" : {
"ParentId" : "001234567891234", // Required
"Name" : "FileName.jpg", // Optional
"ContentType" : "image/jpeg", // Optional -- manual entry of content type
"FilePath" : "/Valid/Path/To/File.Jpg" // Required
}
};
bridge.send(request, function (responseData) {
if (responseData.type == "createbatchResponse") {
// process results
}
else {
// error code
}
});
Create Actions on Single Attachments
createAttachment
The createAttachment
method allows creation of Attachments directly from Base64 encoded data. The intended Attachment ParentId, Name, and Body are required arguments. The ContentType of the Attachment may be optionally specified in MIME type format, as in the example below. On success, the response data contains the Id of the created attachment.
Multiple create or delete requests MUST NOT run concurrently. If you need to create multiple attachments, it is recommend you using the createAttachmentBatch endpoint to avoid the effort of using callbacks and/or promises with .then() for continuations.
var request = {
"type" : "createAttachment",
"data" : {
"ParentId" : "001234567891234", // Required
"Name" : "AttachmentName.jpg", // Required
"Body" : "AABBCCDDEEFF...", // Base64 data -- Required
"ContentType" : "image/jpeg" // Optional -- manual entry of content type
}
};
bridge.send(request, function (responseData) {
if (responseData.type == "createAttachmentResponse") {
alert('Created Attachment Id: ' + responseData.data);
}
else {
// error code
}
});
createAttachmentFromFilePath
The createAttachmentFromFilePath
method allows creation of Attachments directly from valid, accessible, device file paths. The intended Attachment ParentId, FilePath are required arguments. The ContentType of the Attachment may be optionally specified in MIME type format, as in the example below. Optionally, you can specify a file name for the attachment, instead of using the name of the original file. On success, the response data contains the Id of the created attachment.
Multiple create or delete requests MUST NOT run concurrently. If you need to create multiple attachments, it is recommend you using the createAttachmentFromFilePathBatch endpoint to avoid the effort of using callbacks and/or promises with .then() for continuations.
var request = {
"type" : "createAttachmentFromFilePath",
"data" : {
"ParentId" : "001234567891234", // Required
"Name" : "AttachmentName.jpg", // Optional
"ContentType" : "image/jpeg", // Optional -- manual entry of content type
"FilePath" : "/Valid/Path/To/File.Jpg" // Required
}
};
bridge.send(request, function (responseData) {
if (responseData.type == "createAttachmentResponse") {
alert('Created Attachment Id: ' + responseData.data);
}
else {
// error code
}
});