GreenMonkey API Reference

Complete API documentation for integrating with GreenMonkey's marketplace platform.

Overview

The GreenMonkey API provides programmatic access to:

  • Browse and search products
  • Manage your products
  • Process purchases
  • Access analytics
  • Execute AI operations

Base URL

https://api.greenmonkey.dev/v1

Authentication

All API requests require authentication via API key:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.greenmonkey.dev/v1/products

Get your API key from Dashboard → Settings → API.

Rate Limits

Plan Requests/Minute Requests/Day
Free N/A N/A
Pro 100 10,000
Business 1,000 100,000
Enterprise Custom Custom

Response Format

All responses are JSON:

{
  "success": true,
  "data": { ... },
  "meta": {
    "page": 1,
    "limit": 20,
    "total": 100
  }
}

Error responses:

{
  "success": false,
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid",
    "details": { ... }
  }
}

Products API

List Products

Get a paginated list of products.

GET /products

Query Parameters

Parameter Type Description Default
page integer Page number 1
limit integer Items per page (max 100) 20
type string Product type filter all
category string Category slug all
provider string AI provider filter all
minPrice number Minimum price 0
maxPrice number Maximum price none
sort string Sort field relevance
order string Sort order (asc/desc) desc
search string Search query none

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://api.greenmonkey.dev/v1/products?type=prompt&category=marketing&limit=10"

Example Response

{
  "success": true,
  "data": [
    {
      "id": "clx1234567890",
      "title": "SEO Blog Post Generator",
      "description": "Generate SEO-optimized blog posts...",
      "type": "PROMPT",
      "price": 19.99,
      "currency": "USD",
      "author": {
        "id": "usr_123",
        "name": "Jane Doe",
        "verified": true
      },
      "rating": {
        "average": 4.8,
        "count": 156
      },
      "stats": {
        "views": 1520,
        "purchases": 89
      },
      "compatibility": ["openai", "anthropic"],
      "tags": ["seo", "blogging", "content"],
      "createdAt": "2024-01-15T10:00:00Z",
      "updatedAt": "2024-03-20T15:30:00Z"
    }
  ],
  "meta": {
    "page": 1,
    "limit": 10,
    "total": 47
  }
}

Get Product Details

Retrieve detailed information about a specific product.

GET /products/{productId}

Path Parameters

Parameter Type Description
productId string Product ID

Example Request

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.greenmonkey.dev/v1/products/clx1234567890

Example Response

{
  "success": true,
  "data": {
    "id": "clx1234567890",
    "title": "SEO Blog Post Generator",
    "description": "Full product description...",
    "content": "Detailed prompt content...",
    "type": "PROMPT",
    "price": 19.99,
    "currency": "USD",
    "author": {
      "id": "usr_123",
      "name": "Jane Doe",
      "verified": true,
      "bio": "AI prompt engineer..."
    },
    "requirements": ["OpenAI API key", "GPT-4 access"],
    "features": ["SEO optimization", "Multiple tone options", "Keyword integration"],
    "version": "2.1.0",
    "changelog": "Added new templates...",
    "files": [
      {
        "name": "main-prompt.txt",
        "size": 2048,
        "type": "text/plain"
      }
    ],
    "images": ["https://cdn.greenmonkey.dev/products/..."],
    "stats": {
      "views": 1520,
      "purchases": 89,
      "rating": 4.8,
      "reviews": 156
    }
  }
}

Create Product

Create a new product listing.

POST /products

Request Body

{
  "title": "Advanced Email Copywriter",
  "description": "AI-powered email templates...",
  "type": "PROMPT",
  "category": "marketing",
  "price": 29.99,
  "content": "System prompt content...",
  "requirements": ["OpenAI API key"],
  "tags": ["email", "marketing", "copywriting"],
  "compatibility": ["openai", "anthropic"]
}

Example Response

{
  "success": true,
  "data": {
    "id": "clx9876543210",
    "status": "draft",
    "message": "Product created successfully"
  }
}

Update Product

Update an existing product.

PATCH /products/{productId}

Request Body

Only include fields to update:

{
  "price": 24.99,
  "description": "Updated description..."
}

Delete Product

Remove a product from the marketplace.

DELETE /products/{productId}

Purchases API

Create Purchase

Purchase a product.

POST /purchases

Request Body

{
  "productId": "clx1234567890",
  "paymentMethodId": "pm_123", // Optional, uses default
  "referralCode": "SAVE10" // Optional
}

Example Response

{
  "success": true,
  "data": {
    "orderId": "ord_987654321",
    "status": "completed",
    "amount": 19.99,
    "currency": "USD",
    "downloadUrl": "https://api.greenmonkey.dev/v1/downloads/...",
    "receipt": {
      "url": "https://receipts.greenmonkey.dev/...",
      "pdf": "https://receipts.greenmonkey.dev/.../pdf"
    }
  }
}

List Purchases

Get user's purchase history.

GET /purchases

Query Parameters

Parameter Type Description Default
page integer Page number 1
limit integer Items per page 20
status string Filter by status all

Get Purchase Details

GET /purchases/{orderId}

Request Refund

POST /purchases/{orderId}/refund

Request Body

{
  "reason": "Product not as described",
  "details": "Optional additional details..."
}

Analytics API

Product Analytics

Get analytics for your products.

GET /analytics/products

Query Parameters

Parameter Type Description Default
period string Time period (day/week/month/year) month
startDate date Start date (YYYY-MM-DD) 30 days ago
endDate date End date (YYYY-MM-DD) today
productId string Filter by product all

Example Response

{
  "success": true,
  "data": {
    "summary": {
      "totalRevenue": 4567.89,
      "totalSales": 234,
      "avgOrderValue": 19.52,
      "conversionRate": 3.4
    },
    "timeline": [
      {
        "date": "2024-03-01",
        "revenue": 234.56,
        "sales": 12,
        "views": 456
      }
    ],
    "topProducts": [
      {
        "id": "clx1234567890",
        "title": "SEO Blog Post Generator",
        "revenue": 1789.0,
        "sales": 89
      }
    ]
  }
}

Revenue Analytics

GET /analytics/revenue

Customer Analytics

GET /analytics/customers

AI Execution API

Execute Prompt

Execute a purchased prompt with user's API key.

POST /ai/execute

Request Body

{
  "productId": "clx1234567890",
  "apiKeyId": "key_abc123", // User's stored key ID
  "variables": {
    "topic": "AI in Healthcare",
    "tone": "professional",
    "length": "1000 words"
  },
  "options": {
    "model": "gpt-4",
    "temperature": 0.7,
    "maxTokens": 2000
  }
}

Example Response

{
  "success": true,
  "data": {
    "executionId": "exec_123456",
    "output": "Generated content here...",
    "usage": {
      "promptTokens": 245,
      "completionTokens": 1523,
      "totalTokens": 1768,
      "estimatedCost": 0.053
    },
    "metadata": {
      "model": "gpt-4-0125-preview",
      "duration": 4.3,
      "provider": "openai"
    }
  }
}

Execute Workflow

Run a workflow product.

POST /ai/workflows/{workflowId}/execute

Request Body

{
  "input": {
    "data": "Input data for workflow"
  },
  "apiKeys": {
    "openai": "key_abc123",
    "anthropic": "key_def456"
  },
  "webhookUrl": "https://your-app.com/webhook" // Optional
}

Webhooks

Webhook Events

Configure webhooks for real-time events:

  • product.published - New product published
  • product.updated - Product updated
  • purchase.completed - Purchase successful
  • purchase.refunded - Refund processed
  • payout.completed - Seller payout sent
  • review.created - New review posted

Webhook Payload

{
  "id": "evt_123456789",
  "type": "purchase.completed",
  "created": "2024-03-20T10:00:00Z",
  "data": {
    // Event-specific data
  }
}

Webhook Security

Verify webhook signatures:

const crypto = require('crypto');

function verifyWebhook(payload, signature, secret) {
  const hash = crypto.createHmac('sha256', secret).update(payload).digest('hex');

  return hash === signature;
}

Error Codes

Code Description Solution
INVALID_API_KEY API key invalid or expired Check key in dashboard
RATE_LIMIT_EXCEEDED Too many requests Implement backoff
INSUFFICIENT_FUNDS Payment method declined Update payment method
PRODUCT_NOT_FOUND Product ID invalid Verify product exists
UNAUTHORIZED Missing permissions Check API key scope
VALIDATION_ERROR Invalid request data Check request format
INTERNAL_ERROR Server error Retry with backoff

SDK Libraries

JavaScript/TypeScript

npm install @greenmonkey/sdk
import { GreenMonkey } from '@greenmonkey/sdk';

const gm = new GreenMonkey({
  apiKey: process.env.GREENMONKEY_API_KEY,
});

// List products
const products = await gm.products.list({
  type: 'prompt',
  category: 'marketing',
});

// Purchase product
const order = await gm.purchases.create({
  productId: 'clx1234567890',
});

Python

pip install greenmonkey
from greenmonkey import GreenMonkey

gm = GreenMonkey(api_key="YOUR_API_KEY")

# List products
products = gm.products.list(
    type="prompt",
    category="marketing"
)

# Execute prompt
result = gm.ai.execute(
    product_id="clx1234567890",
    variables={"topic": "AI Ethics"}
)

More SDKs

  • Ruby (coming soon)
  • PHP (coming soon)
  • Go (coming soon)
  • Java (coming soon)

Best Practices

  1. Authentication - Store API keys securely, never in code
  2. Rate Limiting - Implement exponential backoff
  3. Error Handling - Handle all error codes gracefully
  4. Pagination - Always paginate large result sets
  5. Caching - Cache product data when appropriate
  6. Webhooks - Use webhooks for real-time updates

Support