Url2Image API
We recommend using the API only when the SDK cannot be used in your environment due to language constraints or other factors. Below is an example of how to interact with our API.
Usage
const url = 'https://url2image.dev/api/screenshots/create'
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'URL_TO_SCREENSHOT',
token: 'YOUR_API_KEY',
options: {}
})
}
const req = await fetch(url, options)
const res = await req.json()
if (res) {
const { success, data, message } = res
if (success && data) {
const { scrUrl, scrBase64 } = data
// Do something with the data
}
else {
console.error(message)
// Handle the error case, you can use our message to show the user
}
}
API is designed to work only in server environments because of the token we provide. This token must not be exposed, as it would allow other people to access your account.
Request
url
is the URL of the site you want to capture.
token
is the token we provide you.
options?
is an object that contains the options you want to use for the screenshot.
Response
success
is a boolean that tells you if the request was successful.
message
is a string that tells you what happened.
data
is an object that contains the data you requested if the request was successful.
data?.scrUrl
is the URL of the generated screenshot, this never expires.
data?.scrBase64
is the base64 format of the screenshot, you can use this as you wish.