Types of Inputs - Serverless Functions

Types of Inputs - Serverless Functions


The input for the function can be acquired in the following types

Parameters

Parameters are passed in URL of query string and the data passed in the post "form-data" section in an input. The "params" in the crmAPIRequest map contains these parameters which has all of the information that are passed in the request.

Sending parameters using POSTMAN, within the request URL

Sending parameters using POSTMAN, as JSON objects in form-data

Sending parameters using POSTMAN as keys in form-data

Any parameters that map the arguments defined in the function, it is automatically synced.

To get the additional parameters used in the request

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the parameters of the request
  3. parameters = crmAPIRequestMap.get("params");
  4. /**
  5. Your Business Logic here
  6. **/
  7. return crmAPIRequestMap;

Note
  • Please avoid using the name "arguments" as an argument within the function. As the name mismatch might lead to some arguments not functioning.
  • Mapping of the arguments of the function is done automatically when passed through "parameters", ie. passed through the Query String(of the URL) or the form-data.

Stream

The "Body" of the request can be used to get the content that is passed as a stream to the request. Usually body is in use only when the request method is POST.

Sending body using POSTMAN as a stream (raw)

Sending body using POSTMAN as a binary file

To get the entire body section of the request in a function

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the Body content of the request
  3. request_body = crmAPIRequestMap.get("body");
  4. /**
  5. Your Business Logic here
  6. **/
  7. return crmAPIRequestMap;

In POSTMAN, the body content can be passed either in the raw or binary.

Note
  • If arguments of the function are passed through Stream, they will not mapped to the arguments of the function.
  • In case you need to encode/decode the input data within the function, you can use the Encryption tasks available in Deluge.

File Content

If the content type of the request is Multipart, it will be considered as a file. You can get the file within the function in the request object.

The file types currently supported are the text files. In order to send the file to the function as a multipart data, send it under the argument name "inputFile".

To get the file uploaded to be used in the function

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the File content of the request
  3. parameters = crmAPIRequestMap.get("file_content");
  4. /**
  5. Your Business Logic here
  6. **/
  7. return crmAPIRequestMap;

Note

If input for the function are given as a "file", the arguments in the file will not mapped to the arguments of the function.

Headers

The header of a request usually contains additional information about the request. The information that is available in header can be acquired in the "headers" key within the crmAPIRequest argument.

To get the headers of the request

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the user info of the request
  3. header_request = crmAPIRequestMap.get("headers");
  4. /**
  5. Your Business Logic here
  6. **/
  7. return crmAPIRequestMap;

User Information

This key can be used to get the information about the user, as well as the organization of the user, who invokes the function using the OAuth2 method.

To get the info about the users

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the user info of the request
  3. user_info = crmAPIRequestMap.get("user_info");
  4. /**
  5. Your Business Logic here
  6. **/
  7. return crmAPIRequestMap;

Note

If the function is called as the API key, the user info that you get would be the info of the super admin and not the one who invokes the function.

Authentication Type and Method

These 2 keys can be used to get the authentication information (apikey or oauth) and the HTTP method (GET/POST).

To get the info about the authentication type

  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. // to get the HTTP method of the request
  3. user_info = crmAPIRequestMap.get("method");
  4. // to get the authentication type of the request
  5. user_info = crmAPIRequestMap.get("auth_type");
  6. /**
  7. Your Business Logic here
  8. **/
  9. return crmAPIRequestMap;


    • Related Articles

    • Overview - Serverless Functions

      Serverless architecture, also known as “Function-as-a-service”(Faas), provides a platform for developers to execute their own codes in response of various business events. In Zoho CRM, all these codes can be written through deluge scripts and can be ...
    • Authentication - Serverless Functions

      Authentication Method A serverless function within your CRM can be invoked from any third-party application or within the CRM. However, commonly not all of the applications support a single authentication method. Keeping that in mind, we have two ...
    • Using API Key - Serverless Functions

      Introduction A severless function within your CRM can be invoked from any third-party application or within the CRM using a webhook. However, generally most of the webhooks do not support OAuth2, save for a few of them. In that case, you can execute ...
    • Request and Response Object - Serverless Functions

      Request object You can get the entire Request Object within the function using the "crmAPIRequest" argument. Say you've created a function and defined 2 arguments. Now you need to use the same function in 2 different webhooks, each of which might ...
    • Using OAuth2 - Serverless Functions

      Introduction Functions can be made accessible through OAuth2 protocol. OAuth2 method allows you to share specific data with any application while keeping your usernames and passwords private, by having specific scopes which grant access to specfic ...