Skip to main content
Every method on *scraperapi.Client (Get, Post, Put, Scrape) returns a *scraperapi.Response on success. It wraps an underlying go-resty response, and also exposes the original *http.Response if you need it.

Commonly used methods

Reading ZenRows-specific headers

ZenRows adds monitoring headers to every response, useful for debugging and tracking usage:
If you ever contact ZenRows support about a failed request, include the X-Request-Id header value. It lets the team trace the exact request in the logs.
Headers coming from the target website itself are prefixed with Zr- (for example, Zr-Content-Encoding, Zr-Cookies). See the full list in the Universal Scraper API setup guide.
The SDK also exposes response.TargetHeaders() and response.TargetCookies() as shortcuts for reading target-site headers and cookies. If they return fewer headers than you expect for a given response, fall back to filtering response.Header() yourself for keys with the Zr- prefix shown above, that always works regardless of which prefix the shortcut methods look for internally.

Checking success before using the body

Because the SDK returns a response as-is rather than turning HTTP errors into a Go error, always confirm the request succeeded first:
response.Problem() parses a structured error body into a *problem.Problem when the response is an error and the Content-Type is JSON. response.Error() does the same thing but returns it as a plain Go error, so if err := response.Error(); err != nil { ... } works too.

Error Handling and Retries

More on this pattern, plus how to configure automatic retries.

Troubleshooting

  • json.Unmarshal fails on the response body: The body isn’t JSON. Confirm you requested JSONResponse: true (with JSRender: true) or that the target actually returns JSON.
  • Saved file (PDF, screenshot, image) is corrupted: You wrote response.String() instead of response.Body(). String() can mangle binary data; always use Body() for non-text responses.
  • response.TargetHeaders() or TargetCookies() return nothing: Fall back to reading response.Header() directly and filtering for the Zr- prefix, as noted above.
  • response.Problem() returns nil on a failed request: This method only parses a body when IsError() is true and the response Content-Type is JSON. A non-JSON error body (or a successful response) always returns nil.

Pricing

The response itself doesn’t add cost. ZenRows adds two headers to help you track usage:
  • X-Request-Cost: the dollar cost of the request (e.g., 0.001)
  • X-Request-Credits: the number of credits consumed by the request
Both values are based on the parameters used: See ZenRows Pricing.

FAQ (Frequently Asked Questions)

It’s a thin ZenRows-specific wrapper around a go-resty response, plus the original *http.Response exposed as the RawResponse field. You don’t need go-resty imported in your own code to use it.
Define a struct matching the expected JSON shape and pass a pointer to it in json.Unmarshal(response.Body(), &yourStruct), the same as unmarshaling any other JSON in Go.
Check the response headers: X-Request-Cost gives you the dollar cost (e.g., 0.001), read with response.Header().Get("X-Request-Cost"). X-Request-Credits gives you the number of credits consumed, read with response.Header().Get("X-Request-Credits").