OpenGraph.io

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 URLEncoded URL
https://github.comhttps%3A%2F%2Fgithub.com
https://example.com/path?query=valuehttps%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

CharacterEncodedNotes
:%3AProtocol separator
/%2FPath separator
?%3FQuery string start
&%26Parameter separator
=%3DKey-value separator
#%23Fragment identifier
space%20Whitespace

Related