### Go: Make HTTP POST Request for URLBox API Source: https://urlbox.com/docs/screenshots/full-page-screenshots This Go snippet demonstrates how to construct an HTTP POST request to an API endpoint, suitable for interacting with services like URLBox. It includes setting up the package, imports, and the main function to initiate the request. This example focuses on the request setup rather than specific payload or header construction. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { } ``` -------------------------------- ### Ruby: Basic HTTP request setup for URLBox Source: https://urlbox.com/docs/screenshots/full-page-screenshots This Ruby code snippet shows the basic setup for making an HTTP request, likely intended for interacting with a service like URLBox. It includes requiring the 'uri' and 'net/http' libraries. The code initializes a URI object and prepares for making a request, though the full request logic (method, headers, body) is not completed in the provided snippet. ```ruby require 'uri' require 'net/http' url = URI("https://a ``` -------------------------------- ### Urlbox Code Samples Source: https://urlbox.com/docs Ready-to-use code examples in Python, Node.js, PHP, and more to get you screenshotting fast. ```APIDOC ## GET /docs/examplecode ### Description Provides ready-to-use code examples for interacting with the Urlbox API in various programming languages. ### Method GET ### Endpoint /docs/examplecode ### Parameters None ### Request Example None ### Response #### Success Response (200) - Code snippets for Python, Node.js, PHP, and other languages. #### Response Example Code examples in various programming languages. ``` -------------------------------- ### Ruby URLBox API Request Setup Example Source: https://urlbox.com/docs/guides/setting-the-user-agent This Ruby snippet demonstrates how to set up an HTTP POST request to the URLBox API. It includes requiring necessary libraries, constructing the URI, and setting request headers. It's a foundational example for making API calls in Ruby. ```ruby require 'uri' require 'net/http' url = URI("https://api.urlbox.io/v1/render/sync") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' ``` -------------------------------- ### URLBox API Initialization and Request Setup Source: https://urlbox.com/docs/screenshots/full-page-screenshots This snippet shows how to initialize a request object for the URLBox API. It configures the target URL, specifies whether to use SSL, and sets up essential headers such as Content-Type and Authorization. It also demonstrates how to construct the JSON body for the request, including parameters like 'url', 'full_page', 'hide_cookie_banners', and 'click_accept'. ```javascript const url = require('url'); const urlObj = url.parse('https://api.urlbox.io/v1/render/sync'); const http = Net.HTTP; http.use_ssl = true; let request = Net.HTTP.Post.new(urlObj); request["Content-Type"] = 'application/json'; request["Authorization"] = 'Bearer YOUR_URLBOX_SECRET'; request.body = "{ \"url\": \"https://urlbox.com\", \"full_page\": true, \"hide_cookie_banners\": true, \"click_accept\": true}"; ``` -------------------------------- ### Urlbox API Request Examples in Multiple Languages Source: https://urlbox.com/docs/screenshots/full-page-screenshots This snippet showcases how to make requests to the Urlbox API using different programming languages: Node.js, Ruby, PHP, Python, and Go. Each example demonstrates a basic synchronous rendering request with common options. Ensure you have the respective SDKs or libraries installed and replace placeholder secrets. ```javascript // Node.js example (requires urlbox npm package) const urlbox = require('urlbox'); const client = new urlbox.Client('YOUR_URLBOX_SECRET'); client.render({ url: 'https://urlbox.com', full_page: true, hide_cookie_banners: true, click_accept: true, block_ads: true, block_urls: [ '*.optimizely.com', 'everesttech.net', 'userzoom.com', 'doubleclick.net', 'googleadservices.com', 'adservice.google.com/*' ] }).then(result => { console.log(result); }).catch(err => { console.error(err); }); ``` ```ruby # Ruby example (requires urlbox gem) require 'urlbox' client = Urlbox.new('YOUR_URLBOX_SECRET') result = client.render( url: 'https://urlbox.com', full_page: true, hide_cookie_banners: true, click_accept: true, block_ads: true, block_urls: [ '*.optimizely.com', 'everesttech.net', 'userzoom.com', 'doubleclick.net', 'googleadservices.com', 'adservice.google.com/*' ] ) puts result ``` ```php // PHP example (requires urlbox/urlbox composer package) require 'vendor/autoload.php'; use Urlbox\Urlbox; $urlbox = new Urlbox('YOUR_URLBOX_SECRET'); $result = $urlbox->render([ 'url' => 'https://urlbox.com', 'full_page' => true, 'hide_cookie_banners' => true, 'click_accept' => true, 'block_ads' => true, 'block_urls' => [ '*.optimizely.com', 'everesttech.net', 'userzoom.com', 'doubleclick.net', 'googleadservices.com', 'adservice.google.com/*' ] ]); print_r($result); ``` ```python # Python example (requires urlbox package) from urlbox import Urlbox client = Urlbox('YOUR_URLBOX_SECRET') result = client.render( url='https://urlbox.com', full_page=True, hide_cookie_banners=True, click_accept=True, block_ads=True, block_urls=[ '*.optimizely.com', 'everesttech.net', 'userzoom.com', 'doubleclick.net', 'googleadservices.com', 'adservice.google.com/*' ] ) print(result) ``` ```go // Go example (requires go get github.com/urlbox/go-urlbox) package main import ( "fmt" "github.com/urlbox/go-urlbox" ) func main() { client := urlbox.NewClient("YOUR_URLBOX_SECRET") options := urlbox.RenderOptions{ Url: "https://urlbox.com", FullPage: true, HideCookieBanners: true, ClickAccept: true, BlockAds: true, BlockUrls: []string{ "*.optimizely.com", "everesttech.net", "userzoom.com", "doubleclick.net", "googleadservices.com", "adservice.google.com/*", }, } result, err := client.Render(options) if err != nil { fmt.Println("Error:", err) return } fmt.Println(result) } ``` -------------------------------- ### Basic Go Program Structure Source: https://urlbox.com/docs/screenshots/full-page-screenshots This snippet provides the basic structure of a Go program, including the package declaration. It's a minimal example to show how a Go file typically begins. ```go package main ``` -------------------------------- ### Go: Render Web Page with URLbox API (Partial Example) Source: https://urlbox.com/docs/screenshots/full-page-screenshots This Go snippet is a partial example for interacting with the URLbox API. It shows the beginning of defining necessary structures or variables for making the API call. Further implementation would be required to complete the request, including defining the payload, headers, and making the HTTP request. ```go import ( "bytes" "encoding/json" "fmt" "net/http" ) // ... (structure definitions for payload and response would go here) func main() { // Example of defining a URL, further code to construct payload and make request is omitted url := "https://api.urlbox.io/v1/render/sync" ``` -------------------------------- ### C# Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using C#. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```csharp using Urlbox; using System; using System.Collections.Generic; public class UrlboxExample { public static void Main(string[] args) { // Replace with your API key and secret key string apiKey = "YOUR_API_KEY"; string apiSecret = "YOUR_API_SECRET"; var urlboxClient = new Urlbox(apiKey, apiSecret); // Example: Render a screenshot of a webpage var renderOptions = new Dictionary { { "url", "https://example.com" }, { "format", "png" }, { "width", "1200" }, { "height", "800" } }; try { string renderedUrl = urlboxClient.Render(renderOptions); Console.WriteLine($"Rendered URL: {renderedUrl}"); } catch (Exception ex) { Console.WriteLine($"Error rendering: {ex.Message}"); } } } ``` -------------------------------- ### Ruby Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using Ruby. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```ruby require 'urlbox' # Replace with your API key and secret key api_key = 'YOUR_API_KEY' api_secret = 'YOUR_API_SECRET' urlbox_client = Urlbox.new(api_key, api_secret) # Example: Render a screenshot of a webpage render_options = { url: 'https://example.com', format: 'png', width: 1200, height: 800 } rendered_url = urlbox_client.render(render_options) puts "Rendered URL: #{rendered_url}" rescue Urlbox::Error => e puts "Error rendering: #{e.message}" end ``` -------------------------------- ### Java Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using Java. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```java import com.urlbox.Urlbox; import com.urlbox.UrlboxException; public class UrlboxExample { public static void main(String[] args) { // Replace with your API key and secret key String apiKey = "YOUR_API_KEY"; String apiSecret = "YOUR_API_SECRET"; Urlbox urlboxClient = new Urlbox(apiKey, apiSecret); // Example: Render a screenshot of a webpage Map renderOptions = new HashMap<>(); renderOptions.put("url", "https://example.com"); renderOptions.put("format", "png"); renderOptions.put("width", "1200"); renderOptions.put("height", "800"); try { String renderedUrl = urlboxClient.render(renderOptions); System.out.println("Rendered URL: " + renderedUrl); } catch (UrlboxException e) { System.err.println("Error rendering: " + e.getMessage()); } } } ``` -------------------------------- ### Node.js: Synchronous URL Rendering with URLBox API Source: https://urlbox.com/docs/screenshots/full-page-screenshots This snippet demonstrates how to use the `node-fetch` module in Node.js to make a synchronous rendering request to the URLBox API. It includes setting up the API endpoint, request options (method, headers, body), and handling the JSON response. Ensure you have `node-fetch` installed (`npm install node-fetch`). ```js const fetch = require('node-fetch'); const url = 'https://api.urlbox.io/v1/render/sync'; const options = { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer YOUR_URLBOX_SECRET' }, body: '{"url":"https://www.stripe.com","full_page":true,"full_page_mode":"native"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch ``` -------------------------------- ### Python Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using Python. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```python from urlbox import Urlbox # Replace with your API key and secret key api_key = 'YOUR_API_KEY' api_secret = 'YOUR_API_SECRET' urlbox_client = Urlbox(api_key, api_secret) # Example: Render a screenshot of a webpage render_options = { 'url': 'https://example.com', 'format': 'png', 'width': 1200, 'height': 800 } try: rendered_url = urlbox_client.render(render_options) print(f'Rendered URL: {rendered_url}') except Exception as e: print(f'Error rendering: {e}') ``` -------------------------------- ### PHP Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using PHP. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```php 'https://example.com', 'format' => 'png', 'width' => 1200, 'height' => 800 ]; try { $renderedUrl = $urlboxClient->render($renderOptions); echo "Rendered URL: " . $renderedUrl . "\n"; } catch (Exception $e) { echo "Error rendering: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Node.js Example for POST /v1/render/sync Source: https://urlbox.com/docs/pdfs/rendering-pdfs Example demonstrating how to use the POST /v1/render/sync endpoint with Node.js and the 'node-fetch' library. ```APIDOC ## Node.js Example for POST /v1/render/sync ### Description Example demonstrating how to use the POST /v1/render/sync endpoint with Node.js and the 'node-fetch' library. ### Method POST ### Endpoint https://api.urlbox.io/v1/render/sync ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. - **Content-Type** (string) - Required - Specifies the request body format, should be 'application/json'. #### Request Body - **html** (string) - Required - The HTML content to render. - **format** (string) - Optional - The desired output format (e.g., 'pdf'). Defaults to 'png'. ### Request Example ```javascript const fetch = require('node-fetch'); const url = 'https://api.urlbox.io/v1/render/sync'; const options = { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer YOUR_URLBOX_SECRET' }, body: JSON.stringify({ html: '

Hello World

', format: 'pdf' }) }; fetch(url, options) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error(err)); ``` ### Response #### Success Response (200) - **data** (string) - The rendered content in the specified format. #### Response Example ```json { "data": "...base64 encoded image or PDF..." } ``` ``` -------------------------------- ### Node.js Example Code Source: https://urlbox.com/docs/getting-started Provides example code for integrating Urlbox rendering capabilities using Node.js. This snippet likely demonstrates how to make API requests to render web pages into images or PDFs. ```javascript const urlbox = require('urlbox'); // Replace with your API key and secret key const apiKey = 'YOUR_API_KEY'; const apiSecret = 'YOUR_API_SECRET'; const urlboxClient = new urlbox(apiKey, apiSecret); // Example: Render a screenshot of a webpage const renderOptions = { url: 'https://example.com', format: 'png', width: 1200, height: 800 }; urlboxClient.render(renderOptions).then(function(url) { console.log('Rendered URL:', url); }).catch(function(err) { console.error('Error rendering:', err); }); ``` -------------------------------- ### Webhook Payload Examples Source: https://urlbox.com/docs/webhooks Examples of webhook payloads sent by Urlbox, covering both successful renders and render failures. ```APIDOC ## Webhook Payload Examples ### Description These are examples of the JSON payloads that Urlbox will send to your specified `webhook_url`. #### Success Payload This payload is sent when a render job completes successfully. ```json { "event": "render.succeeded", "renderId": "19a59ab6-a5aa-4cde-86cb-d2b23302fd84", "result": { "renderUrl": "https://renders.urlbox.com/urlbox1/renders/6215a3df94d7588f7d910513/2024/1/11/19a59ab6-a5aa-4cde-86cb-d2b23302fd84.png", "size": 34097 }, "meta": { "startTime": "2024-01-11T17:49:18.593Z", "endTime": "2024-01-11T17:49:21.103Z" } } ``` #### Failure Payload This payload is sent when an error occurs during the render job. ```json { "event": "render.failed", "renderId": "30044645-cfa3-45d6-b7c1-3c6dc3272af6", "error": { "message": "Page returned 400 and fail_on_4xx was true" }, "meta": { "startTime": "2024-01-11T22:57:34.265Z", "endTime": "2024-01-11T22:57:36.328Z" } } ``` ``` -------------------------------- ### Generate Render Link - C# Example Source: https://urlbox.com/docs/api/rest-api-vs-render-links This C# example demonstrates generating a render link using the Urlbox C# SDK. You'll need to initialize the Urlbox client with your API key and secret, then use it to create the render URL with specified options. ```csharp using Urlbox; public class RenderLinkGenerator { public static void Main(string[] args) { // Replace with your actual API key and secret string apiKey = "YOUR_API_KEY"; string apiSecret = "YOUR_API_SECRET"; var urlbox = new Urlbox(apiKey, apiSecret); var renderUrl = urlbox.Url("https://example.com", new Dictionary { {"format", "png"}, {"width", "1024"}, {"height", "768"} }).Render(); System.Console.WriteLine($"Generated Render Link: {renderUrl}"); } } ``` -------------------------------- ### Generate Render Link - Python Example Source: https://urlbox.com/docs/api/rest-api-vs-render-links This Python example illustrates the process of generating a render link. It uses the 'urlbox' Python library, requiring you to initialize a client with your API key and secret to construct the desired render URL. ```python from urlbox import Urlbox # Replace with your actual API key and secret api_key = 'YOUR_API_KEY' api_secret = 'YOUR_API_SECRET' urlbox = Urlbox(api_key, api_secret) render_url = urlbox.url('https://example.com', { 'format': 'png', 'width': 1024, 'height': 768 }).render() print(f'Generated Render Link: {render_url}') ``` -------------------------------- ### Generate Render Link - Java Example Source: https://urlbox.com/docs/api/rest-api-vs-render-links This Java example shows how to generate a render link. It involves using the Urlbox Java SDK, where you create a Urlbox client with your API credentials and then construct the render URL with the desired parameters. ```java import io.urlbox.Urlbox; public class RenderLinkGenerator { public static void main(String[] args) { // Replace with your actual API key and secret String apiKey = "YOUR_API_KEY"; String apiSecret = "YOUR_API_SECRET"; Urlbox urlbox = new Urlbox(apiKey, apiSecret); String renderUrl = urlbox.url("https://example.com", Map.of( "format", "png", "width", "1024", "height", "768" )).render(); System.out.println("Generated Render Link: " + renderUrl); } } ``` -------------------------------- ### Urlbox Guides Source: https://urlbox.com/docs Step-by-step tutorials for common use cases like batch processing and webhook integration. ```APIDOC ## GET /docs/guides ### Description Offers step-by-step tutorials for common Urlbox API use cases, such as batch processing and webhook integration. ### Method GET ### Endpoint /docs/guides ### Parameters None ### Request Example None ### Response #### Success Response (200) - Tutorials covering various use cases. #### Response Example Tutorial content in markdown format. ``` -------------------------------- ### Basic Rendering Example Source: https://urlbox.com/docs/getting-started Demonstrates how to render a URL with specified width, height, and thumbnail dimensions. ```APIDOC ## GET /v1/api-key/png ### Description Renders a given URL into a PNG image with specified dimensions. ### Method GET ### Endpoint /v1/api-key/png ### Query Parameters - **url** (string) - Required - The URL to render. - **width** (number) - Optional - The width of the rendered image in pixels. - **height** (number) - Optional - The height of the rendered image in pixels. - **thumb_width** (number) - Optional - The width for a thumbnail version of the image. ### Request Example ``` https://api.urlbox.com/v1/api-key/png?url=github.com&width=390&height=844&thumb_width=200 ``` ### Response #### Success Response (200) - **image** (binary) - The rendered image. #### Response Example (Image data would be returned here) ``` -------------------------------- ### Hover Element Example Source: https://urlbox.com/docs/storage/configure-s3-private This example demonstrates how to hover over a specific element on a webpage before capturing a screenshot or PDF. The `hover` option takes a CSS selector to identify the target element. This is useful for interacting with dynamic content or elements that change appearance on hover. ```json { "url": "https://rubyonrails.org/", "hover": ".nav__logo" } ``` -------------------------------- ### Go URLbox API Request for Web Rendering Source: https://urlbox.com/docs/guides/setting-the-user-agent This Go snippet shows the initial setup for making a request to the URLbox API. It includes the necessary 'package main' declaration and imports the 'fmt' and 'net/http' packages, preparing for HTTP client operations. Further implementation details for the API call would follow. ```go package main import ( "fmt" "net/http" ) func main() { // API call implementation would go here } ``` -------------------------------- ### Execute Custom JavaScript Example Source: https://urlbox.com/docs/examplecode/csharp Provides an example of injecting and executing custom JavaScript code within the page's context before a screenshot is taken. This allows for dynamic content modification or interaction. The `js` option accepts a string containing JavaScript code, and supports `await` for promises. ```javascript urlbox.create({ url: "urlbox.com", js: "var now = new Date();\n var dateTimeDiv = document.createElement(\"div\");\n dateTimeDiv.innerText = now.toLocaleString();\n dateTimeDiv.style.cssText = \"position: absolute; top: 10px; right: 10px; padding: 10px; background-color: lightgray; border: 2px solid black; font-weight:semibold; font-family: Arial, sans-serif; font-size: 24px; z-index: 1000;\";\n document.body.appendChild(dateTimeDiv);" }); ``` ```javascript urlbox.create({ url: "urlbox.com", js: 'document.querySelector(\"h1\").textContent = \"I just overrode the headline, oops!!\";' }); ``` -------------------------------- ### Example cURL Request for Render Status Source: https://urlbox.com/docs/api This snippet demonstrates how to use cURL to request the status of a specific render job from the URLBox API. It shows the GET endpoint and a sample render ID. ```shell curl https://api.urlbox.io/v1/render/250ea007-552c-4555-ba2b-ef1c73e18be2 ``` -------------------------------- ### Python: POST Request to URLBox API Source: https://urlbox.com/docs/screenshots/full-page-screenshots This Python snippet demonstrates how to send a POST request to the URLBox API to render content. It utilizes the `requests` library for making HTTP requests. Ensure you have the `requests` library installed (`pip install requests`). The input includes the API URL, payload, and headers, with the output being the JSON response from the API. ```python import requests url = "https://api.urlbox.io/v1/render/sync" payload = { "url": "https://example.com" } headers = { "Authorization": "Bearer YOUR_URLBOX_SECRET" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Execute Custom JavaScript API Source: https://urlbox.com/docs/storage/configure-s3-private Execute custom JavaScript in the context of the page. The JS gets executed after the page's DOM has loaded, but before the screenshot is taken. No need to use `load` etc. event handlers to run code, as these events will already have fired by the time this JS gets executed. You can use `await` to wait for promises to resolve. ```APIDOC ## POST /screenshot ### Description Executes custom JavaScript code within the page's context before taking a screenshot. ### Method POST ### Endpoint /screenshot ### Parameters #### Request Body - **js** (string) - Optional - The JavaScript code to execute. Supports `await` for promises. ### Request Example ```json { "url": "urlbox.com", "js": "var now = new Date();\n var dateTimeDiv = document.createElement('div');\n dateTimeDiv.innerText = now.toLocaleString();\n dateTimeDiv.style.cssText = \"position: absolute; top: 10px; right: 10px; padding: 10px; background-color: lightgray; border: 2px solid black; font-weight:semibold; font-family: Arial, sans-serif; font-size: 24px; z-index: 1000;\";\n document.body.appendChild(dateTimeDiv);" } ``` ### Response #### Success Response (200) - **screenshot_url** (string) - The URL of the generated screenshot. #### Response Example ```json { "screenshot_url": "https://api.urlbox.io/v1/screenshots/abcdef123456.png" } ``` ``` -------------------------------- ### Check Render Status (cURL) Source: https://urlbox.com/docs/api This example shows how to check the status of an asynchronous render job using cURL. It makes a GET request to the `/v1/render/:renderId` endpoint, replacing `:renderId` with the actual ID obtained when the render was created. ```curl curl https://api.urlbox.com/v1/render/250ea007-552c-4555-ba2b-ef1c73e18be2 ``` -------------------------------- ### Secure Rendering Example Source: https://urlbox.com/docs/getting-started Illustrates how to create secure rendering links using a token generated from your secret key. ```APIDOC ## GET /v1/api-key/token/format ### Description Generates a secure rendering link by creating a signed token for the query parameters. ### Method GET ### Endpoint /v1/api-key/token/format ### Query Parameters - **url** (string) - Required - The URL to render. - **token** (string) - Required - A HMAC-SHA256 token of the query string options, signed by your secret key. ### Request Example ``` https://api.urlbox.com/v1/api-key/token/format?url=example.com ``` ### Response #### Success Response (200) - **link** (string) - The secure rendering link. #### Response Example (A secure URL would be returned here) ### Generating the Token (JavaScript Example) ```javascript import hmacSha256 from "crypto-js/hmac-sha256"; const secretKey = "your-secret-key"; const options = "url=github.com&width=390&height=844&thumb_width=200"; const token = hmacSha256(options, secretKey).toString(); ``` ``` -------------------------------- ### Certify Urlbox Render Source: https://urlbox.com/docs/screenshots/full-page-screenshots Enables certification of a render, which creates a hash of the rendered file, timestamp, and options. This provides proof of render integrity and timing. Refer to the Urlbox guide for detailed information. ```json { "options": { "certify": true } } ``` -------------------------------- ### Take Full Page Screenshot (JSON) Source: https://urlbox.com/docs/screenshots/full-page-screenshots This snippet demonstrates how to request a full page screenshot by setting the `full_page` option to true in a JSON configuration. It's a basic setup for capturing the entire webpage. ```json { "url": "https://urlbox.com", "full_page": true } ``` -------------------------------- ### LLM Schema for Structured Image Analysis (Object Output) Source: https://urlbox.com/docs/api/rest-api-vs-render-links This example demonstrates how to define a JSON schema to guide the LLM in extracting specific information from a webpage screenshot. The LLM is prompted to return an 'object' with fields for URL, title, and description. ```json { "title": "Screenshot of urlbox.com", "options": { "url": "urlbox.com", "use_llm": true, "llm_prompt": "Please analyse this image, respecting the structured output provided.", "llm_output": "object", "llm_schema": { "type": "object", "properties": { "url": { "type": "string", "format": "uri", "description": "The original URL of the webpage" }, "title": { "type": "string", "description": "The title of the webpage" }, "description": { "type": "string", "description": "A short summary of what is visible in the screenshot" } }, "required": [ "url", "title", "description" ] } } } ``` -------------------------------- ### Urlbox C# Screenshot Example Source: https://urlbox.com/docs/examplecode/csharp This snippet shows how to initialize Urlbox options, capture a screenshot of a given URL, and then print the resulting render URL. It assumes the Urlbox library is correctly set up. ```csharp UrlboxOptions options = new Urlbox.Options("https://urlbox.com"); // Take a screenshot - The default format is PNG AsyncUrlboxResponse response = await urlbox.TakeScreenshot(options); // This is the URL destination where you can find your finalized render. Console.WriteLine(response.RenderUrl); } ``` -------------------------------- ### Check Render Status with HTTP Source: https://urlbox.com/docs/api This example illustrates how to check the status of an asynchronous render using an HTTP GET request. It targets the /v1/render/:renderId endpoint, where :renderId is the unique identifier for the render. The response provides the render ID, status, and a status URL. ```http GET /v1/render/:renderId ``` -------------------------------- ### Node.js: Fetch URL Rendering Data from URLBox API Source: https://urlbox.com/docs/api This Node.js snippet demonstrates how to use the 'node-fetch' library to make a GET request to the URLBox API for rendering a URL. It includes error handling and parses the JSON response. Ensure 'node-fetch' is installed. ```javascript const fetch = require('node-fetch'); const url = 'https://api.urlbox.io/v1/render/250ea007-552c-4555-ba2b-ef1c73e18be2'; const options = {method: "GET"}; try { const response = fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Setting User Agent - JavaScript Source: https://urlbox.com/docs/storage/configure-s3-private Shows how to set the User-Agent string for a request. This can be a preset like 'random', 'mobile', or 'desktop', or a custom string. Examples include emulating Googlebot, Facebook crawler, and a custom desktop browser. ```javascript options.user_agent = "random"; ``` ```javascript options.user_agent = "mobile"; ``` ```javascript options.user_agent = "desktop"; ``` ```javascript options.user_agent = "Googlebot/2.1 (+http://www.google.com/bot.html)"; ``` ```javascript options.user_agent = "facebookexternalhit/1.1"; ``` ```javascript options.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"; ``` -------------------------------- ### Synchronous Rendering with Node.js Source: https://urlbox.com/docs/api This Node.js snippet shows how to perform a synchronous render request using the 'node-fetch' library. It defines the API endpoint and the necessary options, including the Authorization header and the JSON payload with rendering parameters. This example requires the 'node-fetch' package to be installed. ```javascript const fetch = require('node-fetch'); const url = 'https://api.urlbox.io/v1/render/sync'; const options = ``` -------------------------------- ### Ruby URLBox API Request Example Source: https://urlbox.com/docs/getting-started This Ruby code snippet illustrates how to construct and send a POST request to the URLBox API. It includes setting up the request URL, headers, and body, along with necessary library includes. ```ruby require 'uri' require 'net/http' url = URI("https://api.urlbox.io/v1/render/sync") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Authorization"] = 'Bearer YOUR_URLBOX_SECRET' request.body = "{ " } ] } ] } ``` ``` -------------------------------- ### Node.js: Fetch URLBox API with node-fetch Source: https://urlbox.com/docs/getting-started This snippet shows how to use the 'node-fetch' library in Node.js to make a request to the URLBox API. It demonstrates setting up the URL, request options (method, headers, body), and handling the JSON response. Ensure 'node-fetch' is installed (`npm install node-fetch`). The code is designed for synchronous rendering of a given URL with specified dimensions and format. ```js const fetch = require('node-fetch'); const url = 'https://api.urlbox.io/v1/render/sync'; const options = { method: 'POST', headers: {"Content-Type": "application/json", Authorization: "Bearer YOUR_URLBOX_SECRET"}, body: '{"url":"github.com","width":390,"height":844,"thumb_width":200,"format":"png"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Render Text with URLbox API (JavaScript) Source: https://urlbox.com/docs/guides/setting-the-user-agent This JavaScript snippet shows how to use the URLbox API to render text. It includes basic error handling for console logging. This example assumes the necessary URLbox client library is installed. ```javascript console.log("data"); } catch (error) { console.error(error); } ``` -------------------------------- ### Render Web Page with URLbox API (Go) Source: https://urlbox.com/docs/guides/setting-the-user-agent Demonstrates how to render a web page using the URLbox API in Go. It includes making an HTTP POST request, handling the response body, and printing the output. Dependencies include the 'net/http' and 'fmt' packages. ```go res, err := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println("string(body)") ``` -------------------------------- ### Configure PDF Header with Page Numbers Source: https://urlbox.com/docs/storage/configure-s3-private This example shows how to customize the PDF header to display the current page number and the total number of pages. It uses inline styles for color and margins along with CSS classes like 'pageNumber' and 'totalPages'. ```json { "url": "example.com", "format": "pdf", "pdf_header": "
This is page
of
" } ``` -------------------------------- ### PHP: Basic HTTP Request Configuration for URLBox Source: https://urlbox.com/docs/pdfs/rendering-pdfs This PHP snippet illustrates the fundamental setup for making an HTTP request using URLBox. It shows how to define the request type and potentially other parameters. This serves as a starting point for server-side URLBox integrations. ```php