Using the Wiz API
Using the Wiz API
With the Wiz API, you have the power to programmatically perform quite literally every task
and action available within Wiz. You can perform actions such as bulk add connectors, mimic
UI behavior in textual format, or perform complex data manipulation operations.
Authentication
To create a Service Account, you must be logged in as a Wiz user with Write (W) permission
on service accounts. Project-scoped roles can create Service Accounts only on their own
Projects.
To access the API, you must request an Access Token. To do so, POST to the token URL with
the required parameters.
2. Choose your IdP (identity provider) and add the relevant parameters:
Parameters
Parameter
Description
Name
Your application's Client ID. You can find this value on the Settings >
client_id
Service Accounts page.
Your application's Client Secret. You can find this value on the Settings
client_secret
> Service Accounts page.
Response
If successful, you'll receive a HTTP 200 response with a payload containing access_token ,
refresh_token , token_type , and expires_in values:
JSON
{
“access_token”: “eyJr….Eg”,
“refresh_token”: “eyJj….Bw”,
“expires_in”: 86400,
“token_type”: “Bearer”
}
For more details on generating access tokens and validation process, see the OAuth0 guide.
1. At the top right of your Wiz portal, click the user icon > User settings (direct link).
2. At the left side, click Tenant (direct link).
3. Copy your API Endpoint URL.
To query GraphQL using cURL, make a POST request with a JSON payload. The payload
must contain a string called query :
Shell
# Replace <YOUR_API_ENDPOINT_HERE> with your own Wiz API endpoint, e.g. https://api.us1.app.wiz.io/graphql
curl <YOUR_API_ENDPOINT_HERE> \
-H "Authorization: bearer YOUR_TOKEN_HERE" \
-H 'content-type: application/json' \
-X POST \
-d '{"query": "query { issues { totalCount }}"}'
The string value of "query" must escape newline characters or the schema will
not parse it correctly. For the POST body, use outer double quotes and escaped
inner double quotes.
These limits do not apply to service accounts of type Sensor or Complete K8s
Deployment. In these cases, a single service account can be used to cover your
entire production environment
To avoid excessive impact on its backend, Wiz implements the following rate limits and
timeout:
Limit Description
This limit is applied for each user and service account, so 5 service
10 API calls
accounts on the same tenant could each make 10 calls per second, or 50
per second
calls per second total
This limit is applied across all users and service accounts on a tenant, so
100 API
10 service accounts could each make 10 calls per second or 20 service
calls per
accounts could make 5 calls per second, but 11 service accounts
second
attempting 10 calls per second would trigger throttling
5 minute
API calls have a timeout of 5 minutes per query.
timeout
If you have an environment with large concurrency requirements for remote access to Wiz
(e.g. CI/CD pipelines with dozens of Wiz CLI scans per second, which is quite rare), then:
• Consider using different service accounts for each, or
• Embed a retry on throttle error mechanism in your scripts
In case you are encountering a timeout, consider optimizing the query by following our
optimizing queries guide.
Examples
Pagination
Each API query has a maximum output of 500 or 1,000 records. If you have more (and aren't
using quick search, which returns only 50 results), you can then paginate through up to 10,000
records. The hasNextPage attribute indicates whether there are more pages to load, and you
receive the next page endCursor as long as there is a next page. To receive these attributes
in the response, you must explicitly tell the API that you want the pageInfo response node
to populate in the responses.
As of August 1st, 2023, pagination for the query graphSearch is limited to 10,000
total results. Custom scripts created before then that paginated through tens or
hundreds of thousands of results should be updated to use more selective queries
and repeated calls, each of which returns fewer than 10,000 results.
Make sure the API query includes both the pageInfo parameter and a first variable
(where 0 < first ≤ 10,000) that determines the batch size of each iteration.
JSON
query {
issues(
first: 20
filterBy: { status: [OPEN, IN_PROGRESS] }
orderBy: { direction: DESC, field: SEVERITY }
) {
nodes {
id
severity
entity {
id
name
type
}
control {
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Adding a connector mutation
Programmatically adding a connector using the API is useful when you need to connect
several cloud accounts.
Request
mutation ExampleAddConnector {
createConnector(
input: {
name: "My new connector",
type: "aws",
authParams: {
customerRoleARN: "arn:aws:iam::123456:role/WizAccessSomeRoleName"
},
extraConfig: {}
}
) {
connector {
id
name
}
}
}
Response
{
"data": {
"createConnector": {
"connector": {
"id": "89db2cae-d047-43e0-b2fd-a7633b13283c",
"name": "My new connector"
}
}
}
}
Additional resources
There is a lot more you can do when forming GraphQL calls. Here are some places to look
next:
• Our Wizards have written and annotated numerous example scripts that you are free to
use and modify. Explore the Recipes.
• GraphQL basics guide
• Migrating from REST to GraphQL (Github docs)
• Wiz API Explorer & Docs
Updated 10 days ago