Widget Request Method

Summary

The Widget Request Method enables secure API calls from your extension to third-party services. It prevents credential exposure, handles CORS issues, and provides multiple HTTP methods for API integration.

Purpose

The Request Method routes calls securely:

Your Extension → Zoho Secure Proxy → Third-Party API → Response back to Extension
  • Credentials are never exposed to client-side code
  • CORS issues are resolved automatically
  • Server-side authentication via Connections
  • Secure implementation by default

Syntax

SigmaSDK.WRITER.request({
    url: "https://api.example.com/endpoint",
    type: "GET|POST|PUT|DELETE|PATCH",
    headers: { /* headers */ },
    postBody: { /* request body */ }
})

Parameters

Required Parameters

ParameterTypeRequiredDescription
urlStringYesThird-party API endpoint URL
typeStringYesHTTP method: GET, POST, PUT, DELETE, PATCH
headersObjectYesHTTP headers object

Optional Parameters

ParameterTypeDescription
postBodyObjectRequest payload for POST/PUT/PATCH
dataObjectQuery parameters to append to URL
connectionLinkNameStringConnection name for authenticated requests
responseTypeStringarraybuffer, blob, document, json, text
fileObjArrayFile objects for upload
includeContentBooleanInclude document content in request
contentParamNameStringParameter name for content bytes
contentFormatStringtxt, zip, html, pdf, docx, rtf
sendAsFileBooleanSend as multipart file format

Best Practices

  • ✓ Always use connectionLinkName for authenticated APIs — never hardcode credentials
  • ✓ Always handle errors with try-catch
  • ✓ Usedata for GET query parameters, postBody for POST/PUT bodies
  • ✓ Whitelist domains in plugin-manifest whiteListedDomain for security

Related Pages

Notes

  • Security: All requests are proxied through Zoho's secure infrastructure.
  • CORS: Cross-origin requests are handled transparently — no need for CORS headers.
  • Async: All requests return Promises.

Request Method Sample Request

Copied<!DOCTYPE html>
<html>
<head>
    <title>API Request Widget</title>
    <script src="https://static.zohocdn.com/sigma/client/sdk/v3/sigma-sdk.min.js"></script>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        button { padding: 10px 20px; cursor: pointer; }
        #response { margin-top: 20px; padding: 10px; background: #f0f0f0; }
    </style>
</head>
<body>
    <h2>API Request Widget</h2>
    <button onclick="fetchData()">Fetch Data</button>
    <div id="response"></div>

    <script>
        SigmaSDK.WRITER.init();

        async function fetchData() {
            try {
                const response = await SigmaSDK.WRITER.request({
                    url: "https://api.example.com/data",
                    type: "GET",
                    headers: { "Content-Type": "application/json" },
                    connectionLinkName: "my_connection"
                });
                document.getElementById("response").innerHTML =
                    "<pre>" + JSON.stringify(response, null, 2) + "</pre>";
            } catch (error) {
                SigmaSDK.WRITER.showMessage({
                    type: "error",
                    message: "Request failed: " + error.message
                });
            }
        }
    </script>
</body>
</html>

Get Sample Request

Copiedconst response = await SigmaSDK.WRITER.request({
    url: "https://api.example.com/users",
    type: "GET",
    headers: { "Content-Type": "application/json" }
});
console.log(response);

Post Sample Request

Copiedconst response = await SigmaSDK.WRITER.request({
    url: "https://api.example.com/users",
    type: "POST",
    headers: { "Content-Type": "application/json" },
    postBody: { name: "John Doe", email: "john@example.com" }
});

Request with Query Parameters Sample Request

Copiedconst response = await SigmaSDK.WRITER.request({
    url: "https://api.example.com/users",
    type: "POST",
    headers: { "Content-Type": "application/json" },
    postBody: { name: "John Doe", email: "john@example.com" }
});

Connection Based Sample Request

Copiedconst response = await SigmaSDK.WRITER.request({
    url: "https://api.example.com/data",
    type: "GET",
    headers: {},
    connectionLinkName: "myconnection"
    // Connection handles authentication automatically
});

Error Handling Sample Request

Copiedasync function safeRequest(params) {
    try {
        const response = await SigmaSDK.WRITER.request(params);
        return response;
    } catch (error) {
        console.error("Request failed:", error);
        SigmaSDK.WRITER.showMessage({
            type: "error",
            title: "Request Failed",
            message: error.message || "An error occurred"
        });
        return null;
    }
}