---
title: GraphQL Tutorial
slug: graphql-tutorial
docTags: 
createdAt: 2023-03-22T17:19:00.000Z
---

# Apollo Studio GraphQL Setup

:::hint{type="info"}
The URL for the Xecta GQL endpoint is: [https://api.onxecta.com/api/gql](https://api.onxecta.com/api/gql)
:::

## Navigate to Apollo Studio

To navigate to Apollo Studio, open your web browser and navigate to [https://api.onxecta.com/api/gql](https://api.onxecta.com/api/gql)

::Image[]{src="https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/OgVSevL8W3oXoyuLB_6GL_image.png" size="50" width="1574" height="847" position="center" showCaption="false"}

## Generate Bearer Token and Configure Headers

### JWT Token

You can use a user-based JWT from the ProdX application or a bearer token from MTLS. For MTLS, please refer to the [Postman Tutorial](docId\:lGTlvIilHGLckN-0QA8mg) for instructions on obtaining a token. To obtain a user-based, navigate to ProdX at \[customer].app.onxecta.com, click on your initials in the top right corner of the screen to open the menu, and click directly on your name to copy a token to the clipboard.

Note: JWT tokens expire after a period of time. If queries stop functioning, generate a new token and update your query or shared header.

![](https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/DApSS39vY4sM2WuvG51pl_image.png)

### Headers

Add a Header with the key name "Authorization" and the value as "Bearer \{INSERT JWT TOKEN HERE}". Make sure you leave a space between bearer and the token itself.

Adding a header as shown below will only apply to the current query. If you click the link at the bottom right of the center column titled "Set Shared Headers", you can set a global header which will apply to all query tabs you have open.&#x20;

Note: JWT tokens expire after a period of time. If queries stop functioning, generate a new token and update your query or shared header.

![](https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/qhHNbMX18TTPsSYHecVTF_image.png "Setting Auth Header")

***

# Query Wells

For many of the GraphQL requests, you will need to run a query to get the XID's (Xecta's unique identifiers for your data entries) for the wells which you want to interact with. You can enter a query manually in the center "operation" section of apollo or you can use the navigation tree on the right side of the screen to interactively build a query. Hovering over items in the tree will launch a popup with additional documentation about the entity.

```graphql
query GetWellInfo {
  wells2 {
    xid
    uwi
    sourceId
    name
  }
}
```

Paste this query into Apollo Studio and click the "GetWellInfo" execution button

![](https://files.readme.io/7ba7636-image.png "Query pasted into Apollo Studio")

This will return all wells in the database in the response section on the right.

***

# Query Well Performance Analysis Results

One of the most common queries is for cleansed daily data supplemented with all daily output values from ProdX (like bottomhole pressure, productivity index, etc.). The sample below shows you how to query for this information.

```graphql
query WellPerformanceAnalysisResults($where: WellPerformanceAnalysisResultFilterInput, $wellsCriteria: WellsCriteria) {
  wells2(wellsCriteria: $wellsCriteria) {
    xid
    name
    wellPerformanceAnalysisResults(where: $where) {
      wellXid
      bottomholeDepth
      bottomholeDepthSource
      bottomholePressure
      bottomholeDepthReservoir
      bottomholeDepthSourceReservoir
      bottomholePressureReservoir
      bottomholePressureCorrelation
      reservoirPressure
      productivityIndexOil
      productivityIndexGas
      productivityIndexLiquid
      productivityIndexWater
      cumulativeOilProduction
      cumulativeWaterProduction
      cumulativeGasProduction
      cumulativeGasOilRatio
      timeOn
      gasOilRatio
      waterCut
      instantaneousRecoveryRatioTotal
      dynamicDrainageVolumeTotal
      productionMethod
      elapsedTime
      productionDelta
      current
      drawdown
      epochTime
      opportunity
      opportunityField
      recommendation
      recommendationField
      liquidRate
      boeRate
      cumulativeBoeProduction
      cumulativeLiquidProduction
      timeOnOil
      timeOnGas
      timeOnLiquid
      downtimeCorrectedOilRate
      downtimeCorrectedWaterRate
      downtimeCorrectedGasRate
      downtimeCorrectedGasLiftInjectionRate
      downtimeCorrectedWaterInjectionRate
      downtimeCorrectedGasInjectionRate
      espHeadDegradationPercent
      rateNormalizedDeltaPressureChoke
      pressureNormalizedRateLiquid
      pressureNormalizedRateOil
      pressureNormalizedRateGas
      gasLiquidRatio
      inSituRateGaugeNode
      criticalGasRateSurface
      criticalGasRateGaugeNode
      criticalGasRateTurnerGaugeNode
      criticalGasRateColemanGaugeNode
      criticalGasRateNagooGaugeNode
      totalGasRate
      espHead
      espGasSeparationEfficiency
      xid
      date
      oilRate
      gasRate
      waterRate
      tubingPressure
      choke
      gaugePressure
      wellheadTemperature
      gaugeTemperature
      casingPressure
      linePressure
      gasLiftInjectionRate
      espFrequency
      espIntakePressure
      espAmps
      espVolts
      espDischargePressure
      espMotorTemperature
      espVibration
      srpStrokesPerMin
      srpIntakePressure
      srpFluidLoad
      srpFillage
      downtimeHours
      downtimeCode
      waterInjectionRate
      gasInjectionRate
      isAnnularFlow
    }
  }
}
```

Paste the query above into the "Operation" panel of Apollo Studio.

![](https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/jBOespwdrJZwa51VsJ783_image.png)

For this query, you will have to add "Variables" for the start date, end date, and a list of XIDs (Xecta unique identifier for the well) that you want to query.

At the bottom of the Apollo Studio, click the "Variables" tab, and paste in the following code. Make sure the startDate and endDate are ISO8601 complaint date strings.

:::CodeblockTabs
Variables

```json
{
  "where": {
    "date": {
      "gte": "2000-01-01T06:00:00.000Z",
      "lte": "2024-01-01T06:00:00.000Z"
    }
  },
  "wellsCriteria": {
    "xids": ["96cbd395-a590-4573-b819-793e6a1bddc7"]
  }
}
```
:::

Press the blue "WellPerformanceAnalysisResults" Execution button in the top right of the "Operation" section of apollo studio. You will see your results for your listed wells on the right

![](https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/4Se322vAEfrlmafq8nbAC_image.png)

You can change from a JSON to Tabular view by switching between the icons below

![](https://api.archbee.com/api/optimize/-kIqrMCOJgmgBmRpzgKo2/BTeA8OXjon1WBe9sLuHT4_image.png "Switching results views")

