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
| Parameter | Type | Required | Description |
|---|---|---|---|
url | String | Yes | Third-party API endpoint URL |
type | String | Yes | HTTP method: GET, POST, PUT, DELETE, PATCH |
headers | Object | Yes | HTTP headers object |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
postBody | Object | Request payload for POST/PUT/PATCH |
data | Object | Query parameters to append to URL |
connectionLinkName | String | Connection name for authenticated requests |
responseType | String | arraybuffer, blob, document, json, text |
fileObj | Array | File objects for upload |
includeContent | Boolean | Include document content in request |
contentParamName | String | Parameter name for content bytes |
contentFormat | String | txt, zip, html, pdf, docx, rtf |
sendAsFile | Boolean | Send as multipart file format |
Best Practices
- ✓ Always use
connectionLinkNamefor authenticated APIs — never hardcode credentials - ✓ Always handle errors with try-catch
- ✓ Use
datafor GET query parameters,postBodyfor POST/PUT bodies - ✓ Whitelist domains in plugin-manifest
whiteListedDomainfor 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;
}
}