API Documentation
Getting Started
SnapOG 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:
Authentication
All API requests require an API key which should be included in the URL path.
Endpoints
Generate an Open Graph image for a specific URL.
HTTP Request
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
url | Query Parameter | Yes | The URL to generate an OG image for |
Example Request
Example Usage in 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
For detailed instructions on setting up Open Graph images in Next.js, refer to the official documentation: Next.js Metadata
Step 1: Set up middleware to track current path
Step 2: Configure Open Graph metadata
WordPress
There are two ways to integrate SnapOG 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
Security Tip: Add your API key to wp-config.php
Method 2: Manual Integration
Add this code to your theme's header.php file within the <head> section
Shopify
Integrate SnapOG 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
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:
2. Update your Liquid code to use the theme setting:
Legacy Endpoint
For backward compatibility, the old endpoint /api/get
is still supported but we recommend using the new endpoint for new integrations.
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 keyorInsufficient credits |
401 | Invalid API key |
404 | Invalid URLorDomain not found |
500 | Internal server error |