Usage
U2I SDK

U2I SDK

Using the SDK is the recommended way to interact with the Url2Image. It allows us to manage utilities and what-not for you in the background, without you needing to worry about anything.

We are working to bring the SDK to other languages in the near future.

Installation

npm install @url2image/sdk

Importing

import { Url2Image } from '@url2image/sdk'
 
// or
 
import Url2Image from '@url2image/sdk'

Usage

api/routes/screenshot.ts
    const { success, data, message } = await Url2Image({
        url: 'URL_TO_SCREENSHOT',
        token: 'YOUR_API_KEY'
        options: {}
    })
 
    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
    }

SDK 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.