Skip to main content

Go Code Samples

ScreenshotMAX with Go

Use Go to interact with the ScreenshotMAX API via net/http. Below are examples for simple and signed screenshot requests.

Basic GET Screenshot

package main

import (
"fmt"
"io"
"net/http"
"net/url"
"os"
)

func main() {
endpoint := "https://api.screenshotmax.com/v1/screenshot"
params := url.Values{}
params.Add("access_key", "YOUR_ACCESS_KEY")
params.Add("url", "https://example.com")
params.Add("format", "png")

fullURL := endpoint + "?" + params.Encode()

resp, err := http.Get(fullURL)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()

out, err := os.Create("screenshot.png")
if err != nil {
fmt.Println("File error:", err)
return
}
defer out.Close()

io.Copy(out, resp.Body)
fmt.Println("Image saved to screenshot.png")
}

HMAC-Signed GET Screenshot

package main

import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"net/url"
"os"
)

func main() {
accessKey := "YOUR_ACCESS_KEY"
secretKey := "YOUR_SECRET_KEY"

baseURL := "https://api.screenshotmax.com/v1/screenshot"

query := url.Values{}
query.Set("access_key", accessKey)
query.Set("url", "https://example.com")
query.Set("format", "png")

qs := query.Encode()
signature := signHMAC(qs, secretKey)

// Add signature to query
query.Set("signature", signature)

fullURL := baseURL + "?" + query.Encode()

resp, err := http.Get(fullURL)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()

out, _ := os.Create("screenshot.png")
io.Copy(out, resp.Body)
fmt.Println("Image saved to screenshot.png")
}

func signHMAC(message, secret string) string {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(message))
return hex.EncodeToString(mac.Sum(nil))
}

Next Steps

  • Explore other API options like HTML to PDF, animated screenshots, or web scraping.
  • Create scheduled recurring screenshots via Scheduled Tasks API

Support

For questions, issues, or feature requests, please contact our support team at support@screenshotmax.com.