Getting started overview

To begin generating videos programmatically with JSON2Video, the initial steps involve establishing an account, retrieving your API credentials, and then executing a basic API call. This process typically includes:

  1. Account Creation: Registering for a JSON2Video account, which provides access to the platform's dashboard and API services.
  2. API Key Retrieval: Locating and securing your unique API key from your user dashboard. This key authenticates your requests to the JSON2Video API.
  3. API Request Construction: Crafting a JSON payload that specifies the desired video's elements, such as text, images, and audio, along with its structure and styling.
  4. First API Call: Sending the constructed JSON payload to the JSON2Video API endpoint using a tool like cURL or an HTTP client in a programming language.
  5. Video Generation and Retrieval: The API processes the request, generates the video, and returns a URL where the completed video can be accessed.

The JSON2Video API is a RESTful interface designed for automated video creation and programmatic video editing, enabling dynamic video content generation through structured JSON inputs. For detailed information on available endpoints and data models, refer to the official JSON2Video API reference documentation.

Here's a quick reference table outlining the getting started process:

Step What to Do Where
1. Sign Up Create a new JSON2Video account. JSON2Video homepage
2. Get API Key Access your dashboard and copy your API key. JSON2Video Dashboard > API Keys section
3. Prepare JSON Define your video content and structure in a JSON file. Local development environment, using JSON2Video documentation examples
4. Make Request Send the JSON payload to the API endpoint. Terminal (cURL) or preferred programming language (Python, Node.js, etc.)
5. Get Video URL Parse the API response to retrieve the generated video's URL. API Response Body

Create an account and get keys

Accessing the JSON2Video API requires an active account and an API key for authentication. Follow these steps to set up your account and retrieve your credentials:

  1. Navigate to the JSON2Video Website: Open your web browser and go to the JSON2Video homepage.
  2. Sign Up: Look for a "Sign Up" or "Get Started Free" button. JSON2Video offers a free plan that includes 5 minutes of video generation per month, which is sufficient for initial testing and development. Complete the registration form with your email address and a strong password. You may need to verify your email address through a confirmation link sent to your inbox.
  3. Log In to Your Dashboard: After successful registration and verification, log in to your JSON2Video account. This will take you to your personal dashboard.
  4. Locate API Keys: Within the dashboard, navigate to the section typically labeled "API Keys," "Settings," or "Developer." The exact location may vary, but it is usually prominently displayed for developers.
  5. Generate/Retrieve API Key: If an API key is not automatically provided, there will be an option to generate a new one. Copy this key immediately and store it securely. Treat your API key like a password, as it grants access to your account's video generation capabilities and associated usage limits.

Your API key is essential for authenticating all requests to the JSON2Video API. Without it, your requests will be rejected. For security best practices, consider using environment variables to store your API key in development and secure secret management services in production, as outlined in general API security guidelines like those provided by Google Developers on API key security.

Your first request

Once you have your API key, you can make your first request to the JSON2Video API. This example demonstrates how to create a simple video with text using cURL and Python. The core of the request is a JSON payload describing the video.

Example JSON Payload

This JSON defines a video with a single scene containing text:


{
  "width": 1280,
  "height": 720,
  "scenes": [
    {
      "elements": [
        {
          "type": "text",
          "text": "Hello, JSON2Video!",
          "font_size": 72,
          "color": "#FFFFFF",
          "x": "center",
          "y": "center"
        }
      ],
      "duration": 3
    }
  ],
  "output": {
    "format": "mp4"
  }
}

Using cURL

cURL is a command-line tool for making HTTP requests and is useful for quick API testing. Replace YOUR_API_KEY with your actual JSON2Video API key.


curl -X POST \
  https://api.json2video.com/v1/videos \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "width": 1280,
    "height": 720,
    "scenes": [
      {
        "elements": [
          {
            "type": "text",
            "text": "Hello, JSON2Video!",
            "font_size": 72,
            "color": "#FFFFFF",
            "x": "center",
            "y": "center"
          }
        ],
        "duration": 3
      }
    ],
    "output": {
      "format": "mp4"
    }
  }'

Upon successful execution, the API will return a JSON response containing a video_url where you can download or view your generated video. The response will also include a status field, which you can poll if the video generation is asynchronous.

Using Python

For programmatic interaction, Python is a common choice due to its extensive libraries. This example uses the requests library.


import requests
import json

API_KEY = "YOUR_API_KEY"  # Replace with your actual API key
API_ENDPOINT = "https://api.json2video.com/v1/videos"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

payload = {
    "width": 1280,
    "height": 720,
    "scenes": [
        {
            "elements": [
                {
                    "type": "text",
                    "text": "Hello, JSON2Video!",
                    "font_size": 72,
                    "color": "#FFFFFF",
                    "x": "center",
                    "y": "center"
                }
            ],
            "duration": 3
        }
    ],
    "output": {
        "format": "mp4"
    }
}

try:
    response = requests.post(API_ENDPOINT, headers=headers, data=json.dumps(payload))
    response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)
    
    response_data = response.json()
    print("Video generation initiated successfully!")
    print(f"Response: {json.dumps(response_data, indent=2)}")
    
    if 'video_url' in response_data:
        print(f"Generated Video URL: {response_data['video_url']}")
    elif 'id' in response_data: # For asynchronous processing
        print(f"Video ID for polling: {response_data['id']}")
        print("You may need to poll the status endpoint with this ID.")

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err}")
    print(f"Response body: {response.text}")
except requests.exceptions.ConnectionError as conn_err:
    print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
    print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
    print(f"An error occurred: {req_err}")

This Python script sends the video definition to the API and prints the response. For more complex video definitions, consult the JSON2Video API documentation on video creation.

Common next steps

After successfully generating your first video, you can explore more advanced features and integrations:

  1. Explore Advanced Video Features: The JSON2Video API supports a variety of elements beyond simple text, including images, audio, and more complex scene transitions. Experiment with different JSON structures to create dynamic and engaging videos. The API reference provides comprehensive details on all available parameters.
  2. Integrate with Your Application: Integrate the API into your existing applications, websites, or content management systems. This could involve dynamically generating videos for marketing campaigns, personalized content, or automated social media updates.
  3. Handle Asynchronous Operations: Video generation can be a time-consuming process. Understand how to handle asynchronous API responses, typically by polling a status endpoint with a video ID or by setting up webhooks for callback notifications when a video is ready.
  4. Manage and Monitor Usage: Keep track of your API usage through the JSON2Video dashboard to stay within your plan's limits. Monitor for errors and implement robust error handling in your code.
  5. Review Pricing and Scaling: As your needs grow, review the JSON2Video pricing page to understand different tiers and features. Plan for scaling your video generation capabilities as your application's demands increase.
  6. Explore SDKs and Libraries: While JSON2Video does not list official SDKs, community-contributed libraries or wrappers might exist, or you can build your own to simplify API interactions in your preferred language. The official documentation provides code examples in several languages.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting steps:

  • Check API Key: Ensure your API key is correct and included in the Authorization: Bearer YOUR_API_KEY header. A common mistake is a typo or an expired key. Double-check it against the key in your JSON2Video dashboard.
  • Verify Endpoint URL: Confirm that the API endpoint URL (https://api.json2video.com/v1/videos) is spelled correctly and matches the one specified in the JSON2Video API reference.
  • Content-Type Header: The Content-Type header must be set to application/json for requests with a JSON payload. Incorrect headers can lead to 4xx errors.
  • JSON Payload Validity: Use a JSON linter or validator to ensure your request body is well-formed JSON. Syntax errors, missing commas, or unclosed brackets are frequent causes of API rejections. The MDN Web Docs on HTTP 400 Bad Request explains common causes for such errors.
  • Required Parameters: Review the API documentation to ensure all mandatory parameters are present in your JSON payload. For instance, width, height, and scenes are typically required for video creation.
  • Network Connectivity: Confirm your internet connection is stable. Network issues can prevent requests from reaching the API.
  • Review API Error Messages: The JSON2Video API provides descriptive error messages in its responses. Read these carefully, as they often pinpoint the exact problem. Common HTTP status codes include 400 Bad Request (invalid JSON or parameters), 401 Unauthorized (invalid API key), and 403 Forbidden (insufficient permissions or rate limits).
  • Check Rate Limits: If you are making many requests in a short period, you might hit API rate limits. Check the API documentation for information on rate limiting and implement appropriate backoff strategies.
  • Consult Documentation and Support: If you've exhausted these steps, refer to the comprehensive JSON2Video documentation or contact their support for further assistance.