Get Fields
Purpose
To get the list of available merge fields present in the document.
HTTP Request URL
https://{api.office-integrator_domain}/writer/officeapi/v1/fields
Request Parameters
Parameter | Data Type | Description |
Mandatory Parameters | ||
apikey | 423s***** | Uniquely identifies the web application in which the Writer editor is integrated. |
Body Parameters
Parameter | Data Type | Description |
Mandatory Parameters | ||
file_content or file_url | File or String | Below are the methods to provide the input file that needs to merged with the data depending on its location. file_content - if the input file is from your local drive or desktop. file_url - if the input file is from a publicly accessible Web URL. |
Sample Request
Copiedcurl --location --request POST "https://api.office-integrator.com/writer/officeapi/v1/fields" \
--form "apikey=423s*****" \
--form "file_content=@"
Copiedconst Levels = require("zoi-nodejs-sdk/routes/logger/logger").Levels;
const Constants = require("zoi-nodejs-sdk/utils/util/constants").Constants;
const APIKey = require("zoi-nodejs-sdk/models/authenticator/apikey").APIKey;
const Environment = require("zoi-nodejs-sdk/routes/dc/environment").Environment;
const LogBuilder = require("zoi-nodejs-sdk/routes/logger/log_builder").LogBuilder;
const UserSignature = require("zoi-nodejs-sdk/routes/user_signature").UserSignature;
const InitializeBuilder = require("zoi-nodejs-sdk/routes/initialize_builder").InitializeBuilder;
const fs = require("fs");
const StreamWrapper = require("zoi-nodejs-sdk/utils/util/stream_wrapper").StreamWrapper;
const MergeFieldsResponse = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/merge_fields_response").MergeFieldsResponse;
const GetMergeFieldsParameters = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/get_merge_fields_parameters").GetMergeFieldsParameters;
const InvaildConfigurationException = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/invaild_configuration_exception").InvaildConfigurationException;
const OfficeIntegratorSDKOperations = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/office_integrator_sdk_operations").OfficeIntegratorSDKOperations;
class GetFields {
//Include zoi-nodejs-sdk package in your package json and the execute this code.
static async initializeSdk() {
let user = new UserSignature("john@zylker.com");
let environment = new Environment("https://api.office-integrator.com", null, null);
let apikey = new APIKey("2ae438cf864488657cc9754a27daa480", Constants.PARAMS);
let logger = new LogBuilder()
.level(Levels.INFO)
.filePath("./app.log")
.build();
let initialize = await new InitializeBuilder();
await initialize.user(user).environment(environment).token(apikey).logger(logger).initialize();
console.log("\nSDK initialized successfully.");
}
static async execute() {
//Initializing SDK once is enough. Calling here since code sample will be tested standalone.
//You can place SDK initializer code in your application and call once while your application start-up.
await this.initializeSdk();
try {
var sdkOperations = new OfficeIntegratorSDKOperations();
var parameter = new GetMergeFieldsParameters();
parameter.setFileUrl("https://demo.office-integrator.com/zdocs/OfferLetter.zdoc");
// var fileName = "OfferLetter.zdoc";
// var filePath = __dirname + "/sample_documents/OfferLetter.zdoc";
// var fileStream = fs.readFileSync(filePath);
// var streamWrapper = new StreamWrapper(fileName, fileStream, filePath)
// parameter.setFileContent(streamWrapper);
var responseObject = await sdkOperations.getMergeFields(parameter);
if(responseObject != null) {
console.log("\nStatus Code: " + responseObject.statusCode);
let writerResponseObject = responseObject.object;
if(writerResponseObject != null) {
if(writerResponseObject instanceof MergeFieldsResponse) {
writerResponseObject.getMerge().forEach(mergeField => {
console.log("\n", mergeField);
});
} else if (writerResponseObject instanceof InvaildConfigurationException) {
console.log("\nInvalid configuration exception. Exception json - ", writerResponseObject);
} else {
console.log("\nRequest not completed successfullly");
}
}
}
} catch (error) {
console.log("\nException while running sample code", error);
}
}
}
GetFields.execute();