Compare commits

...

3 Commits

Author SHA1 Message Date
Guillaume BOURGEOIS 9f88891457 feat(freshservice): new Freshservice ITSM integration
Freshservice API v2, 7 commands: create/get/update/list tickets, add note
(public/private), list agents. API-key (Basic) auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:31:45 +02:00
Guillaume BOURGEOIS 9892f2cf06 feat(zendesk): new Zendesk ticketing integration
Zendesk Support API v2, 7 commands: create/get/update/search tickets, add
comment (public/internal), list users. API-token (Basic) auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:31:44 +02:00
Guillaume BOURGEOIS be8bf9f822 feat(thehive): new TheHive case-management integration
TheHive 5 API v1, 10 commands: case create/get/update/search, create task,
alert create/get/promote-to-case, add observable. Bearer (API key) auth,
stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 00:31:43 +02:00
27 changed files with 1724 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
id: freshservice
name: Freshservice
version: 1.0.0
description: "Freshservice (REST API v2) — IT service management: create, read, update and list tickets, add notes (public or private), and list agents. API-key (Basic) authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: create/get/update/list tickets, add note, list agents."
category: ticketing
# Per-instance configuration. Auth is HTTP Basic with '<api_key>:X'.
config_schema:
properties:
domain:
type: string
description: "Freshservice domain (the X in https://X.freshservice.com)"
api_key:
type: string
description: "Freshservice API key"
x-soar-sensitive: true
required:
- domain
- api_key
commands:
- id: create_ticket
name: freshservice-create-ticket
description: "Create a ticket."
inputs_schema:
properties:
subject: { type: string, description: "Ticket subject" }
description: { type: string, description: "Ticket description (HTML allowed)" }
email: { type: string, description: "Requester email" }
priority: { type: number, description: "1 (low) - 4 (urgent), default 1" }
status: { type: number, description: "2 (open) - 5 (closed), default 2" }
tags: { type: string, description: "Comma-separated tags" }
required: [subject, description, email]
outputs_schema: { properties: {} }
- id: get_ticket
name: freshservice-get-ticket
description: "Get a ticket by ID."
risk: read
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
required: [ticket_id]
outputs_schema: { properties: {} }
- id: update_ticket
name: freshservice-update-ticket
description: "Update a ticket (status, priority, or assignment)."
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
status: { type: number, description: "2 (open) - 5 (closed)" }
priority: { type: number, description: "1-4" }
responder_id: { type: string, description: "Assigned agent ID" }
required: [ticket_id]
outputs_schema: { properties: {} }
- id: list_tickets
name: freshservice-list-tickets
description: "List tickets."
risk: read
inputs_schema:
properties:
page: { type: number, description: "Page number (default 1)" }
per_page: { type: number, description: "Page size (default 30, max 100)" }
required: []
outputs_schema: { properties: {} }
- id: add_note
name: freshservice-add-note
description: "Add a note to a ticket (public or private)."
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
body: { type: string, description: "Note body (HTML allowed)" }
private: { type: boolean, description: "Private note (default true)" }
required: [ticket_id, body]
outputs_schema: { properties: {} }
- id: list_agents
name: freshservice-list-agents
description: "List agents."
risk: read
inputs_schema:
properties:
email: { type: string, description: "Optional email filter" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: freshservice-test-connection
description: "Verify connectivity and the API key (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,65 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
note_body = inputs.get("body")
if not note_body:
raise Exception("body is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
private = inputs.get("private")
private_val = True if private is None else bool(private)
body = {"body": note_body, "private": private_val}
return request("POST", "/tickets/" + q(ticket_id) + "/notes", cfg, body=body)
_run(main)
@@ -0,0 +1,76 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
subject = inputs.get("subject")
if not subject:
raise Exception("subject is required")
description = inputs.get("description")
if not description:
raise Exception("description is required")
email = inputs.get("email")
if not email:
raise Exception("email is required")
priority = inputs.get("priority")
status = inputs.get("status")
tags_raw = inputs.get("tags")
tags = [s.strip() for s in str(tags_raw).split(",") if s.strip()] if tags_raw else []
body = {
"subject": subject,
"description": description,
"email": email,
"priority": int(priority or 1),
"status": int(status or 2),
}
if tags:
body["tags"] = tags
return request("POST", "/tickets", cfg, body=body)
_run(main)
@@ -0,0 +1,57 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/tickets/" + q(ticket_id), cfg)
_run(main)
@@ -0,0 +1,56 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
email = inputs.get("email")
params = {"email": email}
return request("GET", "/agents", cfg, params=params)
_run(main)
@@ -0,0 +1,60 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
page = inputs.get("page")
per_page = inputs.get("per_page")
params = {
"page": int(page or 1),
"per_page": int(per_page or 30),
}
return request("GET", "/tickets", cfg, params=params)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
request("GET", "/tickets", cfg, params={"per_page": 1})
return {"ok": True}
_run(main)
@@ -0,0 +1,72 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("domain", "")) + ".freshservice.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("api_key", "")) + ":X"
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
status = inputs.get("status")
priority = inputs.get("priority")
responder_id = inputs.get("responder_id")
body = {}
if status not in (None, ""):
body["status"] = int(status)
if priority not in (None, ""):
body["priority"] = int(priority)
if responder_id not in (None, ""):
body["responder_id"] = int(responder_id)
if not body:
raise Exception("at least one field to update is required")
return request("PUT", "/tickets/" + q(ticket_id), cfg, body=body)
_run(main)
+125
View File
@@ -0,0 +1,125 @@
id: thehive
name: TheHive
version: 1.0.0
description: "TheHive (case-management API v1) — SOC case handling: create/read/update/search cases, create tasks, create and read alerts, promote an alert to a case, and add observables. Bearer (API key) authentication; stdlib-only, no extra Python dependencies. Targets TheHive 5."
changelog: "1.0.0 — Initial release: case create/get/update/search, create task, alert create/get/promote, add observable."
category: case_management
# Per-instance configuration. The API key is sent as 'Authorization: Bearer <api_key>'.
config_schema:
properties:
base_url:
type: string
description: "TheHive URL (e.g. https://thehive.example.com:9000)"
api_key:
type: string
description: "TheHive API key"
x-soar-sensitive: true
required:
- base_url
- api_key
commands:
- id: create_case
name: thehive-create-case
description: "Create a case."
inputs_schema:
properties:
title: { type: string, description: "Case title" }
description: { type: string, description: "Case description" }
severity: { type: number, description: "1 (low) - 4 (critical), default 2" }
tlp: { type: number, description: "TLP 0 (white) - 4 (red), default 2" }
tags: { type: string, description: "Comma-separated tags" }
required: [title, description]
outputs_schema: { properties: {} }
- id: get_case
name: thehive-get-case
description: "Get a case by ID."
risk: read
inputs_schema:
properties:
case_id: { type: string, description: "Case ID" }
required: [case_id]
outputs_schema: { properties: {} }
- id: update_case
name: thehive-update-case
description: "Update a case (status, severity, or assignee)."
inputs_schema:
properties:
case_id: { type: string, description: "Case ID" }
status: { type: string, description: "New status (e.g. Open, Resolved)" }
severity: { type: number, description: "1-4" }
assignee: { type: string, description: "Assignee login" }
required: [case_id]
outputs_schema: { properties: {} }
- id: search_cases
name: thehive-search-cases
description: "Search cases with a free-text query."
risk: read
inputs_schema:
properties:
query: { type: string, description: "Free-text keyword to match in title/description" }
limit: { type: number, description: "Max cases (default 50)" }
required: []
outputs_schema: { properties: {} }
- id: create_task
name: thehive-create-task
description: "Add a task to a case."
inputs_schema:
properties:
case_id: { type: string, description: "Case ID" }
title: { type: string, description: "Task title" }
description: { type: string, description: "Task description" }
required: [case_id, title]
outputs_schema: { properties: {} }
- id: create_alert
name: thehive-create-alert
description: "Create an alert."
inputs_schema:
properties:
title: { type: string, description: "Alert title" }
description: { type: string, description: "Alert description" }
type: { type: string, description: "Alert type (e.g. external)" }
source: { type: string, description: "Alert source" }
source_ref: { type: string, description: "Unique source reference" }
severity: { type: number, description: "1-4, default 2" }
required: [title, description, type, source, source_ref]
outputs_schema: { properties: {} }
- id: get_alert
name: thehive-get-alert
description: "Get an alert by ID."
risk: read
inputs_schema:
properties:
alert_id: { type: string, description: "Alert ID" }
required: [alert_id]
outputs_schema: { properties: {} }
- id: promote_alert
name: thehive-promote-alert
description: "Promote an alert to a case."
inputs_schema:
properties:
alert_id: { type: string, description: "Alert ID" }
required: [alert_id]
outputs_schema: { properties: {} }
- id: add_observable
name: thehive-add-observable
description: "Add an observable to a case."
inputs_schema:
properties:
case_id: { type: string, description: "Case ID" }
data_type: { type: string, description: "Observable type (ip, domain, url, hash, mail, ...)" }
data: { type: string, description: "Observable value" }
message: { type: string, description: "Optional note" }
ioc: { type: boolean, description: "Mark as IOC (default false)" }
required: [case_id, data_type, data]
outputs_schema: { properties: {} }
- id: test_connection
name: thehive-test-connection
description: "Verify connectivity and the API key (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,62 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
case_id = str(inputs.get("case_id", "")).strip()
data_type = str(inputs.get("data_type", "")).strip()
data = str(inputs.get("data", "")).strip()
if not case_id:
raise Exception("case_id is required")
if not data_type:
raise Exception("data_type is required")
if not data:
raise Exception("data is required")
message = inputs.get("message")
ioc = inputs.get("ioc", False)
body = {
"dataType": data_type,
"data": data,
"ioc": bool(ioc),
}
if message not in (None, ""):
body["message"] = str(message)
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("POST", "/api/v1/case/" + q(case_id) + "/observable", cfg, body)
_run(main)
@@ -0,0 +1,67 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
title = str(inputs.get("title", "")).strip()
description = str(inputs.get("description", "")).strip()
type_ = str(inputs.get("type", "")).strip()
source = str(inputs.get("source", "")).strip()
source_ref = str(inputs.get("source_ref", "")).strip()
if not title:
raise Exception("title is required")
if not description:
raise Exception("description is required")
if not type_:
raise Exception("type is required")
if not source:
raise Exception("source is required")
if not source_ref:
raise Exception("source_ref is required")
severity = inputs.get("severity")
body = {
"title": title,
"description": description,
"type": type_,
"source": source,
"sourceRef": source_ref,
"severity": int(severity) if severity not in (None, "") else 2,
}
return request("POST", "/api/v1/alert", cfg, body)
_run(main)
@@ -0,0 +1,62 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
title = str(inputs.get("title", "")).strip()
description = str(inputs.get("description", "")).strip()
if not title:
raise Exception("title is required")
if not description:
raise Exception("description is required")
severity = inputs.get("severity")
tlp = inputs.get("tlp")
tags_raw = inputs.get("tags")
body = {
"title": title,
"description": description,
"severity": int(severity) if severity not in (None, "") else 2,
"tlp": int(tlp) if tlp not in (None, "") else 2,
}
if tags_raw not in (None, ""):
tags = [s.strip() for s in str(tags_raw).split(",") if s.strip()]
if tags:
body["tags"] = tags
return request("POST", "/api/v1/case", cfg, body)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
case_id = str(inputs.get("case_id", "")).strip()
title = str(inputs.get("title", "")).strip()
if not case_id:
raise Exception("case_id is required")
if not title:
raise Exception("title is required")
description = inputs.get("description")
body = {"title": title}
if description not in (None, ""):
body["description"] = str(description)
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("POST", "/api/v1/case/" + q(case_id) + "/task", cfg, body)
_run(main)
+44
View File
@@ -0,0 +1,44 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
alert_id = str(inputs.get("alert_id", "")).strip()
if not alert_id:
raise Exception("alert_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/api/v1/alert/" + q(alert_id), cfg)
_run(main)
+44
View File
@@ -0,0 +1,44 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
case_id = str(inputs.get("case_id", "")).strip()
if not case_id:
raise Exception("case_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("GET", "/api/v1/case/" + q(case_id), cfg)
_run(main)
@@ -0,0 +1,44 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
alert_id = str(inputs.get("alert_id", "")).strip()
if not alert_id:
raise Exception("alert_id is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
return request("POST", "/api/v1/alert/" + q(alert_id) + "/case", cfg, {})
_run(main)
@@ -0,0 +1,50 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
query = inputs.get("query")
limit = inputs.get("limit")
limit_val = int(limit) if limit not in (None, "") else 50
ql = [{"_name": "listCase"}]
if query not in (None, ""):
ql.append({"_name": "filter", "_like": {"_field": "title", "_value": str(query)}})
ql.append({"_name": "page", "_from": 0, "_to": limit_val})
body = {"query": ql}
resp = request("POST", "/api/v1/query", cfg, body)
return {"results": resp}
_run(main)
@@ -0,0 +1,40 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
request("GET", "/api/v1/user/current", cfg)
return {"ok": True}
_run(main)
@@ -0,0 +1,62 @@
import json, os, sys, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def request(method, path, cfg, body=None):
url = str(cfg.get("base_url", "")).rstrip("/") + path
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": "Bearer " + str(cfg.get("api_key", "")), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
case_id = str(inputs.get("case_id", "")).strip()
if not case_id:
raise Exception("case_id is required")
status = inputs.get("status")
severity = inputs.get("severity")
assignee = inputs.get("assignee")
body = {}
if status not in (None, ""):
body["status"] = str(status).strip()
if severity not in (None, ""):
body["severity"] = int(severity)
if assignee not in (None, ""):
body["assignee"] = str(assignee).strip()
if not body:
raise Exception("at least one field to update is required")
q = lambda v: urllib.parse.quote(str(v), safe="")
resp = request("PATCH", "/api/v1/case/" + q(case_id), cfg, body)
if not resp:
return {"ok": True, "case_id": case_id}
return resp
_run(main)
+96
View File
@@ -0,0 +1,96 @@
id: zendesk
name: Zendesk
version: 1.0.0
description: "Zendesk Support (REST API v2) — ticketing: create, read, update and search tickets, add comments (public or internal), and list users. API-token (Basic) authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: create/get/update/search tickets, add comment, list users."
category: ticketing
# Per-instance configuration. Auth is HTTP Basic with '<email>/token:<api_token>'.
config_schema:
properties:
subdomain:
type: string
description: "Zendesk subdomain (the X in https://X.zendesk.com)"
email:
type: string
description: "Agent email address"
api_token:
type: string
description: "Zendesk API token"
x-soar-sensitive: true
required:
- subdomain
- email
- api_token
commands:
- id: create_ticket
name: zendesk-create-ticket
description: "Create a ticket."
inputs_schema:
properties:
subject: { type: string, description: "Ticket subject" }
comment: { type: string, description: "Initial comment / description" }
priority: { type: string, description: "low, normal, high, or urgent" }
type: { type: string, description: "problem, incident, question, or task" }
tags: { type: string, description: "Comma-separated tags" }
requester_email: { type: string, description: "Requester email (optional)" }
required: [subject, comment]
outputs_schema: { properties: {} }
- id: get_ticket
name: zendesk-get-ticket
description: "Get a ticket by ID."
risk: read
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
required: [ticket_id]
outputs_schema: { properties: {} }
- id: update_ticket
name: zendesk-update-ticket
description: "Update a ticket (status, priority, or assignee)."
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
status: { type: string, description: "new, open, pending, hold, solved, or closed" }
priority: { type: string, description: "low, normal, high, or urgent" }
assignee_id: { type: string, description: "Assignee user ID" }
required: [ticket_id]
outputs_schema: { properties: {} }
- id: search_tickets
name: zendesk-search-tickets
description: "Search tickets with a Zendesk search query."
risk: read
inputs_schema:
properties:
query: { type: string, description: "Search query (e.g. status:open priority:high)" }
required: [query]
outputs_schema: { properties: {} }
- id: add_comment
name: zendesk-add-comment
description: "Add a comment to a ticket (public or internal note)."
inputs_schema:
properties:
ticket_id: { type: string, description: "Ticket ID" }
comment: { type: string, description: "Comment body" }
public: { type: boolean, description: "Public comment (default true; false = internal note)" }
required: [ticket_id, comment]
outputs_schema: { properties: {} }
- id: list_users
name: zendesk-list-users
description: "List users (optionally filter by role)."
risk: read
inputs_schema:
properties:
role: { type: string, description: "Optional role filter (end-user, agent, admin)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: zendesk-test-connection
description: "Verify connectivity and credentials (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,67 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
comment = str(inputs.get("comment", "")).strip()
if not comment:
raise Exception("comment is required")
public = inputs.get("public")
public_val = True if public is None else bool(public)
body = {"ticket": {"comment": {"body": comment, "public": public_val}}}
return request("PUT", "/tickets/" + q(ticket_id) + ".json", cfg, body=body)
_run(main)
@@ -0,0 +1,79 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
subject = str(inputs.get("subject", "")).strip()
if not subject:
raise Exception("subject is required")
comment = str(inputs.get("comment", "")).strip()
if not comment:
raise Exception("comment is required")
ticket = {"subject": subject, "comment": {"body": comment}}
priority = inputs.get("priority")
if priority:
ticket["priority"] = priority
ticket_type = inputs.get("type")
if ticket_type:
ticket["type"] = ticket_type
tags = inputs.get("tags")
if tags:
tags_list = [s.strip() for s in str(tags).split(",") if s.strip()]
if tags_list:
ticket["tags"] = tags_list
requester_email = inputs.get("requester_email")
if requester_email:
ticket["requester"] = {"email": requester_email}
return request("POST", "/tickets.json", cfg, body={"ticket": ticket})
_run(main)
@@ -0,0 +1,59 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
return request("GET", "/tickets/" + q(ticket_id) + ".json", cfg)
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
role = inputs.get("role")
return request("GET", "/users.json", cfg, params={"role": role})
_run(main)
@@ -0,0 +1,56 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
query = str(inputs.get("query", "")).strip()
if not query:
raise Exception("query is required")
return request("GET", "/search.json", cfg, params={"query": "type:ticket " + query})
_run(main)
@@ -0,0 +1,53 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
request("GET", "/users/me.json", cfg)
return {"ok": True}
_run(main)
@@ -0,0 +1,76 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return "https://" + str(cfg.get("subdomain", "")) + ".zendesk.com/api/v2"
def _auth(cfg):
raw = str(cfg.get("email", "")) + "/token:" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
ticket_id = inputs.get("ticket_id")
if not ticket_id:
raise Exception("ticket_id is required")
ticket = {}
status = inputs.get("status")
if status:
ticket["status"] = status
priority = inputs.get("priority")
if priority:
ticket["priority"] = priority
assignee_id = inputs.get("assignee_id")
if assignee_id not in (None, ""):
ticket["assignee_id"] = int(assignee_id)
if not ticket:
raise Exception("at least one field to update is required")
return request("PUT", "/tickets/" + q(ticket_id) + ".json", cfg, body={"ticket": ticket})
_run(main)