Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Operational SendPulse skill with live-verified REST, MCP handshake, and MCP tool-call tests.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/rest_request.sh
1#!/usr/bin/env bash2set -euo pipefail34BASE_URL="https://api.sendpulse.com"5METHOD="GET"6PATH_VALUE=""7DATA=""8BEARER_TOKEN="${SENDPULSE_BEARER_TOKEN:-}"9API_KEY="${SENDPULSE_API_KEY:-}"10DRY_RUN=01112usage() {13cat <<'EOF'14Usage:15rest_request.sh --path <path> [--method GET|POST|PUT|DELETE|PATCH] [--data '<json>'] [--bearer-token <token>] [--api-key <key>] [--base-url <url>] [--dry-run]1617Purpose:18Send a generic SendPulse REST API request using either:19- a ready Bearer token20- an API key used as Bearer token2122Env fallback:23SENDPULSE_BEARER_TOKEN24SENDPULSE_API_KEY25EOF26}2728while [[ $# -gt 0 ]]; do29case "$1" in30--path)31PATH_VALUE="${2:-}"32shift 233;;34--method)35METHOD="${2:-}"36shift 237;;38--data)39DATA="${2:-}"40shift 241;;42--bearer-token)43BEARER_TOKEN="${2:-}"44shift 245;;46--api-key)47API_KEY="${2:-}"48shift 249;;50--base-url)51BASE_URL="${2:-}"52shift 253;;54--dry-run)55DRY_RUN=156shift57;;58-h|--help)59usage60exit 061;;62*)63echo "Unknown argument: $1" >&264usage >&265exit 166;;67esac68done6970if [[ -z "${PATH_VALUE}" ]]; then71echo "Missing --path" >&272usage >&273exit 174fi7576if [[ "${PATH_VALUE}" != /* ]]; then77PATH_VALUE="/${PATH_VALUE}"78fi7980TOKEN="${BEARER_TOKEN:-${API_KEY:-}}"81if [[ -z "${TOKEN}" ]]; then82echo "Missing auth token. Pass --bearer-token, --api-key, or set SENDPULSE_BEARER_TOKEN / SENDPULSE_API_KEY." >&283exit 184fi8586URL="${BASE_URL}${PATH_VALUE}"87CURL_CMD=(88curl --silent --show-error --fail-with-body89-X "${METHOD}"90-H 'Accept: application/json'91-H "Authorization: Bearer ${TOKEN}"92)9394if [[ -n "${DATA}" ]]; then95CURL_CMD+=( -H 'Content-Type: application/json' --data "${DATA}" )96fi9798CURL_CMD+=( "${URL}" )99100if [[ ${DRY_RUN} -eq 1 ]]; then101echo "[dry-run] ${METHOD} ${URL}"102if [[ -n "${DATA}" ]]; then103echo "[dry-run] body: ${DATA}"104fi105echo "[dry-run] Authorization: Bearer <redacted>"106printf '[dry-run] curl'; printf ' %q' "${CURL_CMD[@]//${TOKEN}/<redacted>}"; printf '\n'107exit 0108fi109110"${CURL_CMD[@]}"111