Skip to main content

Go library

github.com/urlquery/urlquery-api-go is the Go client for the v2 API. Every operation is a method, every response is a Go type generated from the API's OpenAPI description, down to a report's HTTP transactions, scripts and artifacts, and the API reference on pkg.go.dev documents each one.

The source is at github.com/urlquery/urlquery-api-go, under the MIT license. It replaces the earlier client for the deprecated v1 API, under the same module path; its calls, names and types are new.

Install​

go get github.com/urlquery/urlquery-api-go

It needs Go 1.25 or later, and an API key.

import (
"context"
"fmt"
"os"
"time"

urlquery "github.com/urlquery/urlquery-api-go"
)

c := urlquery.New(os.Getenv("URLQUERY_APIKEY"))

Options: WithUserAgent("my-tool/1.2") names your tool in the User-Agent, WithHTTPClient sets your own http.Client (for a proxy, say), WithBaseURL points elsewhere, and WithMaxRetryWait bounds retries. A client is safe for concurrent use. Every call takes a context.Context; use it for timeouts and cancellation.

Quick start​

ctx := context.Background()

// Analyze a URL as a restricted report and wait for it.
access := urlquery.SubmissionRequestAccessRestricted
s, err := c.Submit(ctx, urlquery.SubmissionRequest{URL: "https://example.com/login", Access: &access})
if err != nil {
return err
}
if s, err = c.WaitForSubmission(ctx, s.QueueID, 5*time.Minute); err != nil {
return err
}

// The full report: every HTTP transaction, script and artifact.
r, err := c.Report(ctx, s.ReportID)
if err != nil {
return err
}
for _, alert := range r.Detection.URLQuery {
fmt.Println(alert.Severity, alert.Alert)
}

:::caution Choose the visibility Without Access, a submission is public: every account can see the report. See Report visibility. :::

Common tasks​

TaskMethods
Submit and follow an analysisSubmit, Submission, WaitForSubmission
Read a reportReportOverview, Report, Screenshot, ResourceContent
Compare two scansCompareReports
Find reportsRecentReports, RelatedReports, SearchReports, and their All… iterators
ReputationLookupReputation, ExportReputation
Host ProfileHost, ListHosts, SearchHosts, HostRelations, Relations, and their All… iterators
YARAYARASets, CreateYARASet, CreateYARARule, UpdateYARARule, ValidateYARA, TestYARA, YARARuleStats, AllYARARuleMatches
MonitoringCreateWatchlist, AddWatchlistIndicators, AllWatchlistReports, WatchlistStats, CreatePageMonitor, PageMonitorRuns, SetPageMonitorBaseline

These continue from the quick start's c and ctx, with values from a report you are investigating:

sha256 := "<a script's sha256 from the report>"
certSHA256 := "<a certificate's fingerprint.sha256>"
indicators := []string{"login.example.com", "192.0.2.10", "*/gate.php"}

// Every report that loaded the same script.
for hit, err := range c.AllSearchResults(ctx, "javascript.script.sha256:"+sha256, urlquery.SearchOptions{}) {
if err != nil {
return err
}
fmt.Println(hit.ReportID, hit.URL.Addr)
}

// Hosts sharing a certificate.
page, err := c.ListHosts(ctx, urlquery.HostPivot{Certificate: certSHA256}, urlquery.HostOrder{}, urlquery.PageOptions{Limit: 50})

// A watchlist from a list of indicators; more than 500 are sent in batches.
created, err := c.CreateWatchlist(ctx, "Kit X", indicators)
for _, s := range created.Skipped {
fmt.Println("skipped", s.Input, s.Code)
}

The workflows and CLI workflows show complete investigations; the calls map one to one.

How it behaves​

  • Paging. List methods return one page. Their All… methods are Go iterators over every item that follow cursors for you; stop with break when you have enough. A page can hold fewer items than its limit, or none, while more remain, and search returns at most the first 10,000 results.
  • Rate limits and retries. A rate-limit answer (429, or 503 RATE_LIMIT_UNAVAILABLE) comes before the request is processed, so any call is retried after its Retry-After. A GET is also retried after a server error or a network failure, three times. All waiting is bounded by WithMaxRetryWait (two minutes by default; zero turns retries off). A submission is never retried once it may have been queued.
  • Waiting. WaitForSubmission polls every five seconds until the analysis is done or has failed; a failed analysis is not an error, so check Status. When it gives up, it returns the last state it saw, so you keep the queue and report IDs, with ErrWaitTimeout when its timeout passed or your context's error when the context ended first.
  • Errors. API errors are *urlquery.APIError with the API's error code; urlquery.IsNotFound(err) tells a missing or hidden resource.
  • Optional fields. Optional request fields are pointers, so an omitted value is different from false or empty: enabled := false; req.Enabled = &enabled.
  • Hostile content. Report content comes from the analyzed sites. Treat titles, scripts and downloads as untrusted data; ResourceContent writes captured content as it is, so don't open or run it outside an isolated environment.

Versions​

The library follows the v2 API and is versioned with Go module tags, starting at v0.8.0 in step with the command-line client; v0.x releases may still change names. Report bugs in the issues.