# Export an NQL

## Export an NQL

> Starts the execution of a query that will finish with the export of the results to a file in S3. The service response contains an identifier that can be used in the "status" operation to obtain the URL of the file with the results.

```json
{"openapi":"3.0.1","info":{"title":"NQL API","version":"1.2.0"},"tags":[{"name":"Export"}],"servers":[{"url":"https://instance.api.region.nexthink.cloud"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"NqlApiExportResponse":{"type":"object","properties":{"exportId":{"type":"string","description":"Export identifier to be used in the \"status\" operation to know the state of the export and to retrieve the URL of the file with the results."}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string","description":"Message with the description of the error."},"code":{"type":"integer","description":"Error code","format":"int32"},"source":{"type":"string","description":"Source of the error, if any."}}}}},"paths":{"/api/v1/nql/export":{"get":{"tags":["Export"],"summary":"Export an NQL","description":"Starts the execution of a query that will finish with the export of the results to a file in S3. The service response contains an identifier that can be used in the \"status\" operation to obtain the URL of the file with the results.","operationId":"export-get","parameters":[{"name":"queryId","in":"query","description":"Identifier of the query which is going to be executed.","required":true,"schema":{"type":"string"}},{"name":"parameters","in":"query","description":"Key and value of the parameters to be replaced within the NQL query in order to compose a final query for execution. Example: {\\\"alert_name\\\": \\\"my_alert\\\", \\\"alert_status\\\": \\\"Open\\\"}\"","required":false,"schema":{"type":"object","additionalProperties":{"type":"string"}}},{"name":"compression","in":"query","description":"The compression algorithm for the export. If not set, no compression is applied. Allowed values: `NONE`, `ZSTD`, `GZIP`.","required":false,"schema":{"type":"string"}},{"name":"Authorization","in":"header","schema":{"type":"string","nullable":false}}],"responses":{"200":{"description":"OK - Successful execution.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NqlApiExportResponse"}}}},"401":{"description":"Unauthorized - No valid authentication credentials."},"403":{"description":"No permission - Not authorized to execute queries.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Not found - No query associated with that ID."},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Service unavailable."}}}}}}
```

## Export an NQL

> Starts the execution of a query that will finish with the export of the results to a file in S3. The service response contains an identifier that can be used in the "status" operation to obtain the URL of the file with the results.

```json
{"openapi":"3.0.1","info":{"title":"NQL API","version":"1.2.0"},"tags":[{"name":"Export"}],"servers":[{"url":"https://instance.api.region.nexthink.cloud"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"NqlApiExportRequest":{"required":["queryId"],"type":"object","properties":{"queryId":{"maxLength":255,"minLength":1,"pattern":"^#[a-z0-9_]{2,255}$","type":"string","description":"Identifier of the query which is going to be executed."},"parameters":{"type":"object","additionalProperties":{"type":"string"},"description":"Key and value of the parameters to be replaced within the NQL query in order to compose a final query for execution. Example: {\\\"alert_name\\\": \\\"my_alert\\\", \\\"alert_status\\\": \\\"Open\\\"}\""},"compression":{"type":"string","description":"The compression algorithm for the export. If not set, no compression is applied.","enum":["ZSTD","GZIP","NONE"],"nullable":true}}},"NqlApiExportResponse":{"type":"object","properties":{"exportId":{"type":"string","description":"Export identifier to be used in the \"status\" operation to know the state of the export and to retrieve the URL of the file with the results."}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string","description":"Message with the description of the error."},"code":{"type":"integer","description":"Error code","format":"int32"},"source":{"type":"string","description":"Source of the error, if any."}}}}},"paths":{"/api/v1/nql/export":{"post":{"tags":["Export"],"summary":"Export an NQL","description":"Starts the execution of a query that will finish with the export of the results to a file in S3. The service response contains an identifier that can be used in the \"status\" operation to obtain the URL of the file with the results.","operationId":"export-post","parameters":[{"name":"Authorization","in":"header","schema":{"type":"string","nullable":false}}],"requestBody":{"description":"The configuration of the execution","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NqlApiExportRequest"}}},"required":true},"responses":{"200":{"description":"OK - Successful execution.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NqlApiExportResponse"}}}},"401":{"description":"Unauthorized - No valid authentication credentials."},"403":{"description":"No permission - Not authorized to execute queries","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Not found - No query associated with that ID."},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Service unavailable."}}}}}}
```

## Status of an export

> Retrieve the status of an export given its identifier.

```json
{"openapi":"3.0.1","info":{"title":"NQL API","version":"1.2.0"},"tags":[{"name":"Export"}],"servers":[{"url":"https://instance.api.region.nexthink.cloud"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"NqlApiStatusResponse":{"type":"object","properties":{"status":{"type":"string","description":"Status of the export","enum":["SUBMITTED","IN_PROGRESS","ERROR","COMPLETED"],"nullable":false},"resultsFileUrl":{"type":"string","description":"URL of the file with the content once the export has been completed.","nullable":true},"errorDescription":{"type":"string","description":"Message with the description of the error.","nullable":true}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string","description":"Message with the description of the error."},"code":{"type":"integer","description":"Error code","format":"int32"},"source":{"type":"string","description":"Source of the error, if any."}}}}},"paths":{"/api/v1/nql/status/{exportId}":{"get":{"tags":["Export"],"summary":"Status of an export","description":"Retrieve the status of an export given its identifier.","operationId":"status","parameters":[{"name":"exportId","in":"path","description":"Export identifier","required":true,"schema":{"type":"string","nullable":false}},{"name":"Authorization","in":"header","schema":{"type":"string","nullable":false}}],"responses":{"200":{"description":"OK - Successful execution.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NqlApiStatusResponse"}}},"headers":{}},"206":{"description":"Partial Content - The query results were truncated because the maximum number of results allowed by the license was reached","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NqlApiStatusResponse"}}},"headers":{}},"401":{"description":"Unauthorized - No valid authentication credentials."},"403":{"description":"No permission - Not authorized to execute queries.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Not found - No export associated with that ID."},"429":{"description":"Too many requests - The user has reached the daily request limit.","headers":{"retry-after":{"schema":{"type":"string"},"description":"The date and time the client should wait before retrying the request."}}},"500":{"description":"Internal server error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Service unavailable."}}}}}}
```
