Zadarma API signature example
This is an example of how to make a sub flow for generating and signing the proper variables per the docs: https://zadarma.com/en/support/api/#intro_authorization
Shared 8/21/2025
297 views
Visual Workflow
JSON Code
{
"meta": {
"instanceId": "a54929f98674c75bd7c2bdca62f6a8fae848011363b67a229fb324a20b6bdab8"
},
"nodes": [
{
"id": "30584f13-d2c6-4cdb-9315-aea8dc5f8a90",
"name": "Create param string for RFC1738",
"type": "n8n-nodes-base.code",
"position": [
320,
-160
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// In: item.json must include:\n// baseUrl, method, methodPath, params (object), userKey, secret, contentType (optional)\n\nfunction urlencodeRFC1738(str) {\n return encodeURIComponent(String(str))\n .replace(/%20/g, '+') // spaces -> '+'\n .replace(/~/g, '%7E'); // match PHP urlencode behavior\n}\n\nfunction buildQueryRFC1738(params) {\n const parts = [];\n const keys = Object.keys(params || {}).sort(); // ksort\n\n for (const k of keys) {\n const v = params[k];\n if (v === undefined || v === null) continue;\n\n if (Array.isArray(v)) {\n // k[0]=v0&k[1]=v1 to match http_build_query() default\n v.forEach((val, i) => {\n parts.push(`${urlencodeRFC1738(`${k}[${i}]`)}=${urlencodeRFC1738(val)}`);\n });\n } else if (typeof v === 'object') {\n // one-level flatten: k[sub]=val (sorted)\n Object.keys(v).sort().forEach(sub => {\n const val = v[sub];\n if (val === undefined || val === null) return;\n parts.push(`${urlencodeRFC1738(`${k}[${sub}]`)}=${urlencodeRFC1738(val)}`);\n });\n } else {\n parts.push(`${urlencodeRFC1738(k)}=${urlencodeRFC1738(v)}`);\n }\n }\n return parts.join('&'); // \"a=1&b=two\"\n}\n\nconst { baseUrl, method, methodPath, params, userKey, secret, contentType } = $json;\nconst paramsStr = buildQueryRFC1738(params || {});\n\nreturn {\n baseUrl,\n method,\n methodPath,\n paramsStr, // <- feed into Crypto (MD5) next\n userKey,\n secret,\n contentType: contentType || 'application/x-www-form-urlencoded'\n }\n"
},
"typeVersion": 2
},
{
"id": "5babb81b-6444-410b-bce0-44e5e4991286",
"name": "Set mock zadarma data",
"type": "n8n-nodes-base.manualTrigger",
"position": [
100,
-420
],
"parameters": {},
"typeVersion": 1
},
{
"id": "9ddfb6d5-270d-4bc5-b4a5-4f7aa10b85bb",
"name": "Create MD5 hash of params",
"type": "n8n-nodes-base.crypto",
"position": [
540,
-160
],
"parameters": {
"value": "={{ $json.paramsStr }}",
"dataPropertyName": "md5Params"
},
"typeVersion": 1
},
{
"id": "d4b5c731-fe98-4ca5-9cc5-972a18178e09",
"name": "Create string for signing",
"type": "n8n-nodes-base.code",
"position": [
760,
-160
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Spec: stringToSign = methodPath + paramsStr + md5(paramsStr)\nconst { methodPath, paramsStr, md5Params, userKey, secret, baseUrl, method, contentType } = $json;\n\nconst stringToSign = `${methodPath}${paramsStr}${md5Params}`;\n\nreturn {\n baseUrl, method, methodPath, paramsStr, md5Params, stringToSign,\n userKey, secret, contentType\n }\n"
},
"typeVersion": 2
},
{
"id": "686f4310-7f54-43c5-a6be-a0243f60ed6a",
"name": "Sign the string",
"type": "n8n-nodes-base.crypto",
"position": [
980,
-160
],
"parameters": {
"type": "=sha1",
"value": "={{ $json.stringToSign }}",
"action": "hmac",
"secret": "={{ $json.secret }}",
"encoding": "base64",
"dataPropertyName": "signature"
},
"typeVersion": 1
},
{
"id": "a2141afd-4601-4115-9fca-4a324dfc28f6",
"name": "Make The Call",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueRegularOutput",
"position": [
540,
-420
],
"parameters": {
"url": "={{$json.baseUrl + $json.methodPath}}",
"body": "={{ $json.paramsStr }}",
"method": "={{ $json.method }}",
"options": {},
"sendBody": true,
"contentType": "raw"
},
"typeVersion": 4.2
},
{
"id": "4d451ca0-7ba9-4eb6-8fff-568150e50f0c",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
100,
-160
],
"parameters": {
"inputSource": "passthrough"
},
"typeVersion": 1.1
},
{
"id": "1bac955e-91a8-4e6b-a230-85dbc980aa36",
"name": "Execute Self as example of getting the auth",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
320,
-420
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "list",
"value": "vxwbLAf8GhnwH8VH",
"cachedResultName": "Zadarma"
},
"workflowInputs": {
"value": {},
"schema": [],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
}
],
"pinData": {
"Set mock zadarma data": [
{
"method": "POST",
"params": {
"sip_id": "SIP_ID",
"user_id": "USER_ID",
"password": "PASSWORD"
},
"secret": "your_secret_key",
"baseUrl": "https://api.zadarma.com",
"userKey": "your_user_key",
"methodPath": "/v1/pbx/create/",
"contentType": "application/json"
}
]
},
"connections": {
"Sign the string": {
"main": [
[]
]
},
"Set mock zadarma data": {
"main": [
[
{
"node": "Execute Self as example of getting the auth",
"type": "main",
"index": 0
}
]
]
},
"Create MD5 hash of params": {
"main": [
[
{
"node": "Create string for signing",
"type": "main",
"index": 0
}
]
]
},
"Create string for signing": {
"main": [
[
{
"node": "Sign the string",
"type": "main",
"index": 0
}
]
]
},
"Create param string for RFC1738": {
"main": [
[
{
"node": "Create MD5 hash of params",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Create param string for RFC1738",
"type": "main",
"index": 0
}
]
]
},
"Execute Self as example of getting the auth": {
"main": [
[
{
"node": "Make The Call",
"type": "main",
"index": 0
}
]
]
}
}
}