API Documentation
Getting Started
OGenerate provides a simple API to generate Open Graph images for your web pages. To get started, you'll need an API key which you can obtain from your dashboard after signing up.
Base URL
All API requests should be made to:
Base URL
Authentication
All API requests require an API key which should be included in the URL path.
Authentication
Endpoints
Generate an Open Graph image for a specific URL.
HTTP Request
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
apiKey | Query Parameter | Yes | Your API key for authentication |
url | Query Parameter | Yes | The URL to generate an OG image for |
width | Query Parameter | No | Width of the screenshot in pixels (default: 1200) |
height | Query Parameter | No | Height of the screenshot in pixels (default: 630) |
theme | Query Parameter | No | Theme for the screenshot: "light" or "dark" (default: "light") |
Example Request
Basic Request
Advanced Examples
Custom Dimensions
Dark Theme
Full Example with All Parameters
Example Usage in HTML
index.html
Response
The API returns a PNG image if successful. In case of an error, it returns a JSON response with an error message.
Integration Examples
Next.js
This approach uses Next.js App Router with a custom API route that integrates with OGenerate. It provides automatic fallback to a custom image generator for pages that you want to handle yourself.
Step 1: Set up middleware to track current path
src/middleware.ts
Step 2: Configure Open Graph metadata in your layout
src/app/layout.tsx
Step 3: Create the OG image API route
src/app/api/og/route.tsx
Step 4: Environment Variables
Add these environment variables to your `.env.local` file:
.env.local
WordPress
There are two ways to integrate OGenerate with WordPress: using an SEO plugin or manually adding the code to your theme.
Method 1: Using an SEO Plugin
Add this code to your theme's functions.php file to integrate with Yoast SEO or Rank Math
functions.php
Security Tip: Add your API key to wp-config.php
wp-config.php
Method 2: Manual Integration
Add this code to your theme's header.php file within the <head> section
header.php
Shopify
Integrate OGenerate into your Shopify store by editing your theme.
Edit Your Theme's Layout File
- From your Shopify admin, go to Online Store > Themes
- Click Actions > Edit code for your active theme
- Under the Layout directory, open theme.liquid
- Find the <head> section and add the code below
theme.liquid
Store Your API Key Securely
For better security, use Shopify theme settings to store your API key
1. Create settings schema in your config file:
config/settings_schema.json
2. Update your Liquid code to use the theme setting:
theme.liquid
Best Practices
- Always URL encode the url parameter to ensure proper handling
- Consider caching the generated images on your end for better performance
- Test your OpenGraph images with the Facebook Sharing Debugger and Twitter Card Validator
- Ensure your platform is configured to use the proper meta tags
Error Codes
Error Code | Message |
---|---|
400 | Missing URL or API key or Insufficient credits |
401 | Invalid API key |
404 | Invalid URL or Domain not found |
500 | Internal server error |
Say Goodbye to og:image Headaches
Don't let the challenges of Open Graph image creation slow you down. With OGenerate, you can focus on growing your business while we take care of your social media presence.