APIRequestContext
Added in: v1.16This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test.
Each Playwright browser context has an associated APIRequestContext, accessible via BrowserContext.APIRequest or Page.APIRequest (these return the
same instance — page.request is a shortcut for page.context().request). You can also create a standalone, isolated instance with ApiRequest.NewContextAsync().
Cookie management
The APIRequestContext returned by BrowserContext.APIRequest and
Page.APIRequest uses the same cookie jar as its BrowserContext:
If you want API requests that do not share cookies with the browser, create an isolated context via ApiRequest.NewContextAsync(). Such APIRequestContext object will have its own isolated cookie storage.
Methods
ApiRequestContext.AddCookiesAsync()
Added in: v1.64Adds cookies into this request context. They will be sent with matching subsequent requests. For BrowserContext.APIRequest and Page.APIRequest, this is equivalent to calling BrowserContext.AddCookiesAsync() on the corresponding browser context.
Usage
await request.AddCookiesAsync(new[] { cookie1, cookie2 });Arguments
namestringvaluestringurlstring(optional)Either
urlor bothdomainandpathare required. Optional.domainstring(optional)For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com". Either
urlor bothdomainandpathare required. Optional.pathstring(optional)Either
urlor bothdomainandpathare required. Optional.expiresfloat(optional)Unix time in seconds. Optional.
httpOnlyboolean(optional)Optional.
secureboolean(optional)Optional.
sameSite"Strict" | "Lax" | "None"(optional)Optional.
partitionKeystring(optional)For partitioned third-party cookies (aka CHIPS), the partition key. Optional.
ApiRequestContext.ClearCookiesAsync()
Added in: v1.64Removes cookies from this request context. Accepts optional filter. For BrowserContext.APIRequest and Page.APIRequest, this is equivalent to calling BrowserContext.ClearCookiesAsync() on the corresponding browser context.
Usage
await request.ClearCookiesAsync();
await request.ClearCookiesAsync(new() { Name = "session-id" });
await request.ClearCookiesAsync(new() { Domain = "my-origin.com" });
await request.ClearCookiesAsync(new() { Path = "/api/v1" });
await request.ClearCookiesAsync(new() { Name = "session-id", Domain = "my-origin.com" });Arguments
Only removes cookies with the given domain.
Only removes cookies with the given domain.
domainStringstring(optional)Only removes cookies with the given domain.
Only removes cookies with the given name.
Only removes cookies with the given name.
Only removes cookies with the given name.
Only removes cookies with the given path.
Only removes cookies with the given path.
Only removes cookies with the given path.
ApiRequestContext.CookiesAsync()
Added in: v1.64If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned. For BrowserContext.APIRequest and Page.APIRequest, this is equivalent to calling BrowserContext.CookiesAsync() on the corresponding browser context.
Arguments
Returns
Array<Object>
ApiRequestContext.CreateFormData()
Added in: v1.23Creates a new FormData instance which is used for providing form and multipart data when making HTTP requests.
Returns
FormData
ApiRequestContext.DeleteAsync()
Added in: v1.16Sends HTTP(S) DELETE request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Arguments
Target URL.
datastring(optional) Added in: v1.17Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataByteBuffer(optional) Added in: v1.17Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional) Added in: v1.17Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataStringstring(optional) Added in: v1.17Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
formFormData(optional) Added in: v1.17Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.multipartFormData(optional) Added in: v1.17Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.DisposeAsync()
Added in: v1.16All responses returned by ApiRequestContext.GetAsync() and similar methods are stored in the memory, so that you can later call ApiResponse.BodyAsync().This method discards all its resources, calling any method on disposed APIRequestContext will throw an exception.
Arguments
ApiRequestContext.FetchAsync()
Added in: v1.16Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Usage
JSON objects can be passed directly to the request:
var data = new Dictionary<string, object>() {
{ "title", "Book Title" },
{ "body", "John Doe" }
};
await Request.FetchAsync("https://example.com/api/createBook", new() { Method = "post", DataObject = data });The common way to send file(s) in the body of a request is to upload them as form fields with multipart/form-data encoding, by specifiying the multipart parameter:
var file = new FilePayload()
{
Name = "f.js",
MimeType = "text/javascript",
Buffer = System.Text.Encoding.UTF8.GetBytes("console.log(2022);")
};
var multipart = Context.APIRequest.CreateFormData();
multipart.Set("fileField", file);
await Request.FetchAsync("https://example.com/api/uploadScript", new() { Method = "post", Multipart = multipart });Arguments
Target URL or Request to get all parameters from.
Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional)Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.
Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.GetAsync()
Added in: v1.16Sends HTTP(S) GET request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Usage
Request parameters can be configured with params option, they will be serialized into the URL search parameters:
var queryParams = new Dictionary<string, object>()
{
{ "isbn", "1234" },
{ "page", 23 },
};
await request.GetAsync("https://example.com/api/getText", new() { Params = queryParams });Arguments
Target URL.
datastring(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataByteBuffer(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataStringstring(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
formFormData(optional) Added in: v1.26Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.multipartFormData(optional) Added in: v1.26Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.HeadAsync()
Added in: v1.16Sends HTTP(S) HEAD request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Arguments
Target URL.
datastring(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataByteBuffer(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataStringstring(optional) Added in: v1.26Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
formFormData(optional) Added in: v1.26Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.multipartFormData(optional) Added in: v1.26Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.PatchAsync()
Added in: v1.16Sends HTTP(S) PATCH request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Arguments
Target URL.
Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional)Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.PostAsync()
Added in: v1.16Sends HTTP(S) POST request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Usage
JSON objects can be passed directly to the request:
var data = new Dictionary<string, object>() {
{ "firstName", "John" },
{ "lastName", "Doe" }
};
await request.PostAsync("https://example.com/api/createBook", new() { DataObject = data });To send form data to the server use form option. Its value will be encoded into the request body with application/x-www-form-urlencoded encoding (see below how to use multipart/form-data form encoding to send files):
var formData = Context.APIRequest.CreateFormData();
formData.Set("title", "Book Title");
formData.Set("body", "John Doe");
await request.PostAsync("https://example.com/api/findBook", new() { Form = formData });The common way to send file(s) in the body of a request is to upload them as form fields with multipart/form-data encoding. Use FormData to construct request body and pass it to the request as multipart parameter:
var file = new FilePayload()
{
Name = "f.js",
MimeType = "text/javascript",
Buffer = System.Text.Encoding.UTF8.GetBytes("console.log(2022);")
};
var multipart = Context.APIRequest.CreateFormData();
multipart.Set("fileField", file);
await request.PostAsync("https://example.com/api/uploadScript", new() { Multipart = multipart });Arguments
Target URL.
Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional)Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.PutAsync()
Added in: v1.16Sends HTTP(S) PUT request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.
Arguments
Target URL.
Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.dataObjectSerializable(optional)Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
content-typeheader will be set toapplication/jsonif not explicitly set. Otherwise thecontent-typeheader will be set toapplication/octet-streamif not explicitly set.failOnStatusCodeboolean(optional)Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
Provides an object that will be serialized as html form using
application/x-www-form-urlencodedencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set toapplication/x-www-form-urlencodedunless explicitly provided.An instance of FormData can be created via
ApiRequestContext.CreateFormData().headersObject<string, string>(optional)Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.
ignoreHTTPSErrorsboolean(optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.maxRedirectsint(optional) Added in: v1.26Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to
20. Pass0to not follow redirects.maxRetriesint(optional) Added in: v1.46Maximum number of times network errors should be retried. Currently only
ECONNRESETerror is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to0- no retries.Provides an object that will be serialized as html form using
multipart/form-dataencoding and sent as this request body. If this parameter is specifiedcontent-typeheader will be set tomultipart/form-dataunless explicitly provided. File values can be passed as file-like object containing file name, mime-type and its content.An instance of FormData can be created via
ApiRequestContext.CreateFormData().paramsObject<string, Serializable>(optional)Query parameters to be sent with the URL.
paramsStringstring(optional) Added in: v1.47Query parameters to be sent with the URL.
Request timeout in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout.
Returns
APIResponse
ApiRequestContext.StorageStateAsync()
Added in: v1.16Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to the constructor.
Arguments
indexedDBboolean(optional) Added in: v1.51Set to
trueto include IndexedDB in the storage state snapshot.opfsboolean(optional) Added in: v1.63Set to
trueto include the origin private file system in the storage state snapshot.The file path to save the storage state to. If
pathis a relative path, then it is resolved relative to current working directory. If no path is provided, storage state is still returned, but won't be saved to the disk.
Returns
string
Properties
ApiRequestContext.Tracing
Added in: v1.60Tracing recorder for requests made through this API request context.
Type
Tracing