Skip to content

nexscope-ai/nexscope-ecommerce-skills / ecommerce-amazon-advertising-api

ecommerce.amazon-advertising-api

Verified

Authorize Amazon Ads accounts, manage SP, SB, and SD entities, and retrieve advertising reports.

FileKindSize
SKILL.mdskill md36.6 KB
manifest.jsonconfig674 B
references/ads-report-types.jsonconfig288.8 KB
references/api.jsonconfig154.6 KB
references/api.mdmarkdown130.0 KB
references/testing.mdmarkdown2.6 KB
scripts/amazon_ads_report_workflow.pyscript11.8 KB
scripts/amazon_api.pyscript21.2 KB
scripts/amazon_connection.pyscript2.4 KB

scripts/amazon_connection.py

View on GitHub
#!/usr/bin/env python3
"""Manage an Amazon connection without exposing provider credentials."""
import json, os, sys
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import Request, urlopen

BASE = os.environ.get("NEXSCOPE_PROXY_BASE", "").strip().rstrip("/")
KEY = os.environ.get("NEXSCOPE_API_KEY", "").strip()
MAX_RESPONSE_BYTES = 32 * 1024 * 1024
ROUTES = {'authorize': ('POST', '/api/skill/amazon/connections/amazon-ads/authorize'), 'status': ('GET', '/api/skill/amazon/connections/amazon-ads/status'), 'connections': ('GET', '/api/skill/amazon/connections/amazon-ads'), 'profiles': ('GET', '/api/skill/amazon/connections/amazon-ads/profiles')}

def main():
    if len(sys.argv) != 2:
        raise ValueError("Provide exactly one JSON object argument")
    params = json.loads(sys.argv[1])
    if not isinstance(params, dict):
        raise ValueError("The argument must be a JSON object")
    action = str(params.pop("action", "authorize")).lower()
    if action not in ROUTES:
        raise ValueError("Unknown action")
    method, path = ROUTES[action]
    if not BASE or not KEY:
        raise ValueError("NEXSCOPE_PROXY_BASE and NEXSCOPE_API_KEY are required")
    data = None
    if method == "GET":
        if params:
            path += "?" + urlencode(params)
    else:
        data = json.dumps(params).encode()
    request = Request(BASE + path, data=data, headers={"Authorization": "Bearer " + KEY,
        "Content-Type": "application/json", "Accept": "application/json"}, method=method)
    try:
        with urlopen(request, timeout=60) as response:
            raw = response.read(MAX_RESPONSE_BYTES + 1)
            if len(raw) > MAX_RESPONSE_BYTES: raise RuntimeError("Gateway response exceeds 32 MiB limit")
            value = json.loads(raw.decode("utf-8"))
    except HTTPError as error:
        raise RuntimeError(f"Gateway HTTP {error.code}") from error
    except URLError as error:
        raise RuntimeError("Gateway request failed") from error
    if not isinstance(value, dict) or value.get("code") != 0:
        raise RuntimeError("Gateway application failure" if isinstance(value, dict) else "Invalid gateway response")
    print(json.dumps(value.get("data"), indent=2, ensure_ascii=True))

if __name__ == "__main__":
    try: main()
    except (OSError, ValueError, RuntimeError, json.JSONDecodeError) as error:
        print(json.dumps({"error": str(error)}), file=sys.stderr); raise SystemExit(1)
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall