Here you can download a file with example configurations for the scripted REST API: [SOC] - Scripted REST API. Import the pack to your instance and try the following example settings.
To verify the example:
As a result, you receive a response from the API action /record/sys_api_action/164054047017513732 with a system property value simple.auth_page.support_phone.
To verify the example:
As a result, you receive a response from the API action /record/sys_api_action/161831494014244852.
On the bottom of the script form, there is a link to the created task record. See the screenshot below:
The record contains two attachments with base 64 files transferred in lines 14-15 of the script in Step 1. See the screenshot below:
You can create attachments using Scripted REST API. To pass file content, use the base64 format. To get a file content in base64 format, use the readBase64(attachmentId) method.
To send an attachment with the Scripted Rest API, do the following:
1) Create an API action to operate POST resquests with the attached content. For more information see the Configuring Scripted REST API article.
(function (request, response) { const data = request.getBody(); const TABLE_ID = data.table_id; const RECORD_ID = data.record_id; const RECORD_DOC_ID = ss.getDocIdByIds(TABLE_ID, RECORD_ID); const attachments = data.attachments; const simpleAttach = new SimpleAttachment(); let createdAttachmentIds = []; Object.keys(attachments).forEach(attachment => { createdAttachmentIds.push(simpleAttach.writeBase64(RECORD_DOC_ID, ...attachments[attachment])); }); response.setBody(createdAttachmentIds); }) (SimpleApiRequest, SimpleApiResponse) |
2) Create a script to send the requests.
const API_ACTION_URL = ''; // https://docs.simpleone.ru/display/SAPI/Configuring+Scripted+REST+API#ConfiguringScriptedRESTAPI-ScriptedRESTAPIURIs const payloadRequest = sws.restRequestV1(); payloadRequest.setRequestUrl(API_ACTION_URL); payloadRequest.setRequestMethod('POST'); payloadRequest.setRequestHeader('Content-type', 'application/json'); const payload = { table_id: '155931135900000084', // user table ID record_id: '155931135900000001', // admin record ID record attachments: { 1: ['file_example.gif', 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', 'image/gif'] } } payloadRequest.setRequestBody(JSON.stringify(payload)); const response = payloadRequest.execute().getBody(); print('Response: ' + response); |