# Create a variable

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://dashboard.alchemy.com/api/graphql/variables/{var_name}

Creates a GraphQL webhook variable, or adds items to it if it exists.
Items that the variable already has are not added again. The JSON body
takes `items`: at most 10,000 addresses, or 32-byte hex values such as
log topics. A GraphQL webhook query reads the variable as `$var_name`.
The name has at most 64 letters, numbers, and underscores, and starts
with a letter or an underscore.

Reference: https://www.alchemy.com/docs/data/webhooks/webhooks-api-endpoints/create-graphql-variable

## Headers

| Name | Type | Required | Description |
|------|------|----------|-------------|
| X-Alchemy-Token | string | Yes | Your team's auth token. Find it on the Webhooks page of the Alchemy dashboard. |

## Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| var_name | string | Yes | The variable name. |

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://dashboard.alchemy.com/api/graphql/variables/string \
  --header 'Content-Type: application/json' \
  --header 'X-Alchemy-Token: string' \
  --data '{
  "items": [
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', 'X-Alchemy-Token': 'string'},
  body: JSON.stringify({items: ['string']})
};

fetch('https://dashboard.alchemy.com/api/graphql/variables/string', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://dashboard.alchemy.com/api/graphql/variables/string"

payload = { "items": ["string"] }
headers = {
    "Content-Type": "application/json",
    "X-Alchemy-Token": "string"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://dashboard.alchemy.com/api/graphql/variables/string"

	payload := strings.NewReader("{\n  \"items\": [\n    \"string\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("X-Alchemy-Token", "string")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://dashboard.alchemy.com/api/graphql/variables/string")
  .header("Content-Type", "application/json")
  .header("X-Alchemy-Token", "string")
  .body("{\n  \"items\": [\n    \"string\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://dashboard.alchemy.com/api/graphql/variables/string");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("X-Alchemy-Token", "string");
request.AddJsonBody("{\n  \"items\": [\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /api/graphql/variables/{var_name}
method: POST
operation:
  operationId: CreateGraphqlVariable
  responses:
    '201':
      description: Created the variable or added the items
      content:
        application/json:
          schema:
            properties: {}
            type: object
            description: Construct a type with a set of properties K of type T
            additionalProperties: false
          examples:
            Example 1:
              value: {}
    '400':
      description: Invalid input
      content:
        application/json:
          schema:
            description: |-
              The error body. `name` is null for the statuses that have no name, such as
              404 and 429.
            properties:
              message:
                type: string
              name:
                type: string
                nullable: true
            required:
              - message
              - name
            type: object
            additionalProperties: false
          examples:
            Example 1:
              value:
                message: items must be a list of no more than 10,000 valid addresses or length 64 hex strings
                name: ValidationError
    '401':
      description: Requires authentication
      content:
        application/json:
          schema:
            description: |-
              The error body. `name` is null for the statuses that have no name, such as
              404 and 429.
            properties:
              message:
                type: string
              name:
                type: string
                nullable: true
            required:
              - message
              - name
            type: object
            additionalProperties: false
          examples:
            Example 1:
              value:
                message: Unauthenticated request.
                name: AuthError
    '503':
      description: Variable service unavailable
      content:
        application/json:
          schema:
            description: |-
              The error body. `name` is null for the statuses that have no name, such as
              404 and 429.
            properties:
              message:
                type: string
              name:
                type: string
                nullable: true
            required:
              - message
              - name
            type: object
            additionalProperties: false
          examples:
            Example 1:
              value:
                message: Error creating graphQL variable
                name: ServerError
  description: |-
    Creates a GraphQL webhook variable, or adds items to it if it exists.
    Items that the variable already has are not added again. The JSON body
    takes `items`: at most 10,000 addresses, or 32-byte hex values such as
    log topics. A GraphQL webhook query reads the variable as `$var_name`.
    The name has at most 64 letters, numbers, and underscores, and starts
    with a letter or an underscore.
  summary: Create a variable
  tags:
    - Webhooks
  security:
    - team_api_key: []
  parameters:
    - description: The variable name.
      in: path
      name: var_name
      required: true
      schema:
        type: string
  requestBody:
    required: true
    content:
      application/json:
        schema:
          type: object
          required:
            - items
          properties:
            items:
              type: array
              items:
                type: string
              maxItems: 10000
              description: Addresses, or 32-byte hex values such as log topics. Each one starts with "0x".
```
