Using the Wiz API: A Comprehensive Guide
Using the Wiz API: A Comprehensive Guide
Wiz prevents excessive backend impact by enforcing rate limits, allowing up to 10 API calls per second per user or service account, with a cumulative tenant limit of 100 API calls per second . In high-concurrency environments, strategies such as using different service accounts for distributed call loads or embedding retry-on-throttle mechanisms in scripts are recommended . Managing backend impact also involves optimizing queries and leveraging pagination to handle large data outputs efficiently without overwhelming backend resources .
To create a GraphQL query to fetch issues, start by specifying your query criteria such as fetching the 20 highest severity issues with an open or in-progress status . This involves defining fields like status and orderBy for direction and field priority . For handling large result datasets, include the pageInfo node in your query to manage pagination, checking for hasNextPage and using endCursor for subsequent queries . A total of up to 10,000 results can be paginated through structured query batches .
Access tokens for the Wiz API are generated by making a POST request to the token URL with parameters including grant_type set to "client_credentials", along with the application's client_id and client_secret . The identity provider also determines specific parameter settings with either 'beyond-api' or 'wiz-api' specified as the audience . This process forms the basis for client credential authentication in the API's OAuth flow .
Migrating from REST to GraphQL involves transitioning from using HTTP verbs for operation specification to using structured JSON queries and mutations sent with a POST method . Wiz facilitates this transition by utilizing GraphQL, which combines data retrieval and modification through queries and mutations, analogous to REST's GET and POST but with more flexibility due to GraphQL's ability to specify multiple operations and tailored results in a single request . Resources like the GraphQL basics guide and Wiz API Explorer support this transition .
Constructing queries and mutations in Wiz's GraphQL requires structuring JSON-encoded bodies that specify query strings for data retrieval or modification . Essential elements include defining precise data fields required, operational directives such as filtering and ordering, and output nodes like pageInfo for data management . To aid in developing effective GraphQL operations, using the API Explorer, cURL, and available language libraries are recommended to test and optimize these queries and mutations .
Wiz imposes limits such as a rate of 10 API calls per second per user or service account, with an overall tenant limit of 100 API calls per second . Each API call has a 5-minute timeout. For environments with high concurrency requirements, it is recommended to use separate service accounts or embed retry mechanisms to prevent throttling . To manage these restrictions, using the optimizing queries guide is advised, and for pagination, having a clear structure for fetching results iteratively with the hasNextPage and endCursor attributes helps in efficiently managing data retrieval without breaching limits .
To set up and authenticate to the Wiz API, you must first create a Service Account. This requires you to be logged in as a Wiz user with Write (W) permission on service accounts . Service Accounts can only be created on the projects they are scoped to . After setting up the Service Account, an OAuth token must be generated, which involves making a POST request with the necessary parameters including grant_type set to "client_credentials", client_id, client_secret, and audience set depending on your identity provider (either "beyond-api" or "wiz-api"). You then receive an access token which is used for authenticating API requests .
The Wiz GraphQL API endpoint operates at a single endpoint format: https://api.<region>.app.wiz.io/graphql, which remains constant regardless of the operation . To perform GraphQL operations, queries are used to fetch data and mutations alter data, analogous to GET and POST requests in REST APIs, respectively . All requests must be POSTed with a JSON payload containing a string called query. This includes details of the data retrieval or alteration intended .
When using pagination with the Wiz API, ensure that the pageInfo node is included in queries to enable fetching successive pages with the hasNextPage and endCursor attributes . Pagination is limited to a total of 10,000 results beyond which queries need to be more selective or crafted with repeated calls yielding fewer results . This is part of optimizing data fetch without breaching system limits, adapted to not query excessively large datasets in single requests .
To connect APIs to multiple cloud accounts using Wiz, you can programmatically add a connector via a GraphQL mutation request. This involves using the createConnector mutation with necessary inputs like the connector's name, type (e.g., 'aws'), and authentication parameters such as a customerRoleARN . The response includes the connector's new id and name, confirming successful connection . Annotated example scripts for these operations are available in Wiz API Recipes .