> ## Documentation Index
> Fetch the complete documentation index at: https://mixpanel-edb78807-fix-callout.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom JQL Query

<Danger>
  JQL is currently in maintenance mode. We recommend discontinuing use of JQL and using an [alternate method](/docs/export-methods) to get the data you need. Below are alternatives for common use cases and you need help deciding the best method for you, reach out to [support](https://mixpanel.com/get-support).

  * Raw Event export: [Export API](/reference/raw-data-export-api) or [Data Pipelines](/docs/data-pipelines)
  * User Profile export: [Engage Query API](/reference/engage-query) or [Data Pipelines](/docs/data-pipelines)
  * Other reporting: [Query API](/reference/query-api) or in-app [Core Reports](/docs/reports)
</Danger>

The HTTP API is the lowest-level way to use JQL. At its core, the API is very simple: you write a script, and you post it to an API endpoint with some authentication parameters.

For longer scripts, you will likely want to keep the code in a file. If you had your script in a file called my\_query.js, you could run it using the following cURL command:

```sh theme={null}
curl https://mixpanel.com/api/query/jql \
     -u YOUR_API_SECRET: \
     --data-urlencode script@my_query.js
```

Example curl with the script directly inside of the curl:

```sh theme={null}
curl --request POST \
     --url https://mixpanel.com/api/query/jql \
     --header 'accept: application/json' \
     --header 'content-type: application/x-www-form-urlencoded' \
     --data 'script=function main(){
  return Events(params)
    .groupBy(
      ["name"],
      mixpanel.reducer.count()
    )
}
' \
     --data 'params={
  "scriptParam": "paramValue"
}
'
```

Note

* The Query API has a rate limit of 60 queries per hour and a maximum of 5 concurrent queries.
* Queries will timeout after 2 minutes of run-time.
* You cannot make remote network requests (using XMLHttpRequest) from JavaScript.
* Queries to the JQL endpoint contribute to Query API rate limit and have their own individual limit as well. There is a maximum of 5 concurrent queries and of 60 queries per hour. There is also a 5 GB limit on data that can be processed in a single query, and a 2 GB limit on the resulting output data.


## OpenAPI

````yaml openapi/query.openapi.yaml POST /jql
openapi: 3.0.3
info:
  title: Query API
  description: query api
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
  contact:
    url: https://mixpanel.com/get-support
  version: 1.0.0
servers:
  - url: https://{regionAndDomain}.com/api/query
    description: Mixpanel's calculated data API
    variables:
      regionAndDomain:
        default: mixpanel
        enum:
          - mixpanel
          - eu.mixpanel
          - in.mixpanel
        description: |
          The server location to be used:
            * `mixpanel` - The default (US) servers used for most projects
            * `eu.mixpanel` - EU servers if you are enrolled in EU Data Residency
            * `in.mixpanel` - India servers if you are enrolled in India Data Residency
security:
  - ServiceAccount: []
  - ProjectSecret: []
tags:
  - name: Activity Feed
    description: See a profiles recent events history
  - name: Cohorts
    description: Understand what defines a cohort and how many profiles qualify
  - name: Engage
    description: Query for profile information
  - name: Event Breakdown
    description: Breakdowns on the most common events in your project
  - name: Funnels
    description: Query data shown in your Funnels reports
  - name: Insights
    description: Query data shown in your Insights reports
  - name: JQL
    description: Write a custom query on your data
  - name: Retention
    description: Query data shown in your Retention reports
  - name: Segmentation
    description: Query data shown in your Segmenation reports
paths:
  /jql:
    post:
      tags:
        - JQL
      summary: Custom JQL Query
      operationId: query-jql
      parameters:
        - in: query
          name: project_id
          schema:
            type: integer
          description: Required if using service account to authenticate request.
          required: true
        - $ref: '#/components/parameters/workspaceId'
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              required:
                - script
              example:
                script: |
                  function main(){
                    return Events(params)
                      .groupBy(
                        ["name"],
                        mixpanel.reducer.count()
                      )
                  }
                params: |
                  {
                    "from_date": 2016-01-01T00:00:00.000Z,
                    "to_date": 2016-01-07T00:00:00.000Z
                  }
              properties:
                script:
                  type: string
                  default: |
                    function main(){
                      return Events(params)
                        .groupBy(
                          ["name"],
                          mixpanel.reducer.count()
                        )
                    }
                  description: The script to run.
                params:
                  type: string
                  format: blob
                  default: |
                    {
                      "scriptParam": "paramValue"
                    }
                  description: >-
                    A JSON-encoded object that will be made available to the
                    script as the params global variable.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
components:
  parameters:
    workspaceId:
      in: query
      name: workspace_id
      schema:
        type: integer
      description: The id of the workspace if applicable.
  securitySchemes:
    ServiceAccount:
      type: http
      scheme: basic
      description: Service Account
    ProjectSecret:
      type: http
      scheme: basic
      description: Project Secret

````