*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
| Method | Returns | Use it when |
|---|---|---|
response.String() | Response body as a string | Reading HTML or plain text |
response.Body() | Response body as []byte | Handling binary data (PDFs, screenshots, images) |
response.StatusCode() | HTTP status code, e.g. 200 | Checking exactly what happened |
response.Status() | Status text, e.g. "200 OK" | Logging or display |
response.IsSuccess() | true if status is 200 to 299 | Quick success check |
response.IsError() | true if status is 400 or higher | Quick failure check |
response.Header() | http.Header of response headers | Reading ZenRows monitoring headers |
response.RawResponse | The original *http.Response | Anything the wrapper doesn’t expose |
- Text / HTML
- Binary (PDF, screenshot)
- JSON
Reading ZenRows-specific headers
ZenRows adds monitoring headers to every response, useful for debugging and tracking usage: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 Goerror, 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.Unmarshalfails on the response body: The body isn’t JSON. Confirm you requestedJSONResponse: true(withJSRender: true) or that the target actually returns JSON.- Saved file (PDF, screenshot, image) is corrupted: You wrote
response.String()instead ofresponse.Body().String()can mangle binary data; always useBody()for non-text responses. response.TargetHeaders()orTargetCookies()return nothing: Fall back to readingresponse.Header()directly and filtering for theZr-prefix, as noted above.response.Problem()returnsnilon a failed request: This method only parses a body whenIsError()is true and the responseContent-Typeis JSON. A non-JSON error body (or a successful response) always returnsnil.
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
| Configuration | Cost multiplier vs. basic |
|---|---|
| Basic request | 1x |
JSRender: true | 5x |
UsePremiumProxies: true | 10x |
JSRender: true + UsePremiumProxies: true | 25x |
FAQ (Frequently Asked Questions)
Is the Response type specific to ZenRows, or is it go-resty's type directly?
Is the Response type specific to ZenRows, or is it go-resty's type directly?
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.How do I get the response as a Go struct instead of a map?
How do I get the response as a Go struct instead of a map?
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.Where do I find how much a request cost?
Where do I find how much a request cost?
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").