Skip to main content

URL to Markdown Conversion API

Overview

The URL to Markdown API allows you to convert any webpage into clean, formatted markdown content. It also extracts metadata like titles, descriptions, and OpenGraph tags.

Convert URL to Markdown

POST
/url-to-markdown

Request Body

ParameterTypeRequiredDescription
urlstringYesThe URL of the webpage to convert to markdown
curl -X POST https://api.scrapeloop.com/v1/url-to-markdown \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/article"}'

Response Fields

Markdown Content

The markdown field contains the converted content with:

  • Preserved heading structure
  • Formatted lists and tables
  • Code blocks with syntax highlighting
  • Images and links
  • Block quotes and emphasis

Metadata Fields

FieldTypeDescriptionExample
titlestringPage title"Example Article"
faviconstringURL of the page favicon"https://example.com/favicon.ico"
languagestringPage language"en"
ogTitlestringOpenGraph title"Example Article - Example Site"
ogDescriptionstringOpenGraph description"A great article about examples"
ogUrlstringOpenGraph URL"https://example.com/article"
ogImagestringOpenGraph image URL"https://example.com/article-image.jpg"
ogSiteNamestringOpenGraph site name"Example Site"
publishedTimestringArticle published time"2024-01-24T12:00:00Z"
modifiedTimestringArticle last modified time"2024-01-24T14:30:00Z"

Response Codes

CodeDescriptionPossible Cause
200SuccessURL was successfully converted
400Bad RequestInvalid or missing URL
429Rate LimitToo many requests
500Server ErrorConversion failed

Best Practices

1. URL Validation

Ensure URLs are:

  • Properly encoded
  • Include protocol (http/https)
  • Publicly accessible
function validateUrl(url) {
try {
new URL(url);
return true;
} catch {
return false;
}
}

2. Error Handling

Handle common error scenarios:

async function convertToMarkdown(url) {
try {
if (!validateUrl(url)) {
throw new Error('Invalid URL format');
}

const response = await fetch('/url-to-markdown', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
body: JSON.stringify({ url })
});

if (!response.ok) {
throw new Error(`Conversion failed: ${response.statusText}`);
}

return await response.json();
} catch (error) {
console.error('Conversion error:', error);
throw error;
}
}

3. Rate Limiting

Implement rate limit handling:

  • Use exponential backoff
  • Cache results when possible
  • Batch conversions when needed

Examples

Basic Usage

const result = await convertToMarkdown('https://example.com/article');
console.log(result.markdown);

With Metadata

const { markdown, metadata } = await convertToMarkdown('https://example.com/article');

// Use metadata for preview cards
const preview = `
<div class="preview-card">
<img src="${metadata.ogImage}" alt="${metadata.title}">
<h2>${metadata.title}</h2>
<p>${metadata.ogDescription}</p>
</div>
`;