SDK Examples
Ready-to-use code examples for integrating DevUtils API in your preferred programming language.
JavaScript / Node.js
Examples using native fetch API (Node.js 18+). For older versions, use node-fetch or axios.
Screenshot API
// Using fetch (Node.js 18+)
async function captureScreenshot(url) {
const response = await fetch('https://api.devutils.io/v1/screenshot', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.DEVUTILS_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: url,
fullPage: true,
viewport: { width: 1920, height: 1080 }
})
});
const data = await response.json();
if (!data.success) {
throw new Error(data.error.message);
}
return data.data.image_url;
}
// Usage
const imageUrl = await captureScreenshot('https://example.com');
console.log('Screenshot:', imageUrl);HTML to PDF API
// Convert webpage to PDF
async function convertToPdf(url) {
const response = await fetch('https://api.devutils.io/v1/pdf', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.DEVUTILS_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: url,
pageSize: 'A4',
orientation: 'portrait'
})
});
const data = await response.json();
if (!data.success) {
throw new Error(data.error.message);
}
return data.data.pdf_url;
}
// Usage
const pdfUrl = await convertToPdf('https://example.com');
console.log('PDF:', pdfUrl);