URL Encoding
OpenGraph.io endpoints accept target URLs in the path. These URLs must be properly encoded to avoid parsing errors.
Why Encoding is Required
Our API endpoints follow the pattern /api/1.1/endpoint/{encoded_url}. Because URLs contain special characters like :, /, ?, and &, they must be encoded to be safely passed in the URL path.
Common mistake: Passing unencoded URLs will result in parsing errors or unexpected behavior.
Example Transformation
| Original URL | Encoded URL |
|---|---|
https://github.com | https%3A%2F%2Fgithub.com |
https://example.com/path?query=value | https%3A%2F%2Fexample.com%2Fpath%3Fquery%3Dvalue |
Encoding by Language
const targetUrl = 'https://github.com/openai';
const encodedUrl = encodeURIComponent(targetUrl);
// Result: https%3A%2F%2Fgithub.com%2Fopenai
console.log(encodedUrl);
// Full API call
const apiUrl = `https://opengraph.io/api/1.1/site/${encodedUrl}?app_id=YOUR_APP_ID`;Note: In Python, use safe='' to ensure all special characters are encoded, including /.
Special Characters Reference
| Character | Encoded | Notes |
|---|---|---|
| : | %3A | Protocol separator |
| / | %2F | Path separator |
| ? | %3F | Query string start |
| & | %26 | Parameter separator |
| = | %3D | Key-value separator |
| # | %23 | Fragment identifier |
| space | %20 | Whitespace |