# Sites

A **site** represents a group of buildings located within a contiguous area, such as a campus or city blocks, all within the same time zone. Organizations can manage one or multiple sites depending on their needs.

This page provides guidance on how to [**retrieve**](#get-all-sites), [**create**](#create-site-s), and [**update site information** ](#update-site-s)within an organization, enabling efficient management of site-related data and ensuring seamless operations across locations.

{% hint style="success" %}
First, obtain an access token to get started [here](/getting-started/authentication.md).
{% endhint %}

***

### Get all site(s)

```graphql
query allSites {
  sites {
      data {
        id
        name
        buildings {
          id
          name
          ...BuildingFragment
        }
        siteNumber
        customID
        timezone
    }
  }
}
```

#### Code Examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://api.butlr.io/api/v3/graphql' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer [insert access_token here]' \
--data '{"query":"query allSites {\n  sites {\n      data {\n        id\n        name\n        buildings {\n            id\n            name\n        }\n        siteNumber\n        customID\n        timezone\n    }\n  }\n}","variables":{}}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

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

func main() {

  url := "https://api.butlr.io/api/v3/graphql"
  method := "POST"

  payload := strings.NewReader("{\"query\":\"query allSites {\\n  sites {\\n      data {\\n        id\\n        name\\n        buildings {\\n            id\\n        name\\n        }\\n        siteNumber\\n        customID\\n        timezone\\n    }\\n  }\\n}\",\"variables\":{}}")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer [insert access_token here]")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v3/graphql"

payload = "{\"query\":\"query allSites {\\n  sites {\\n      data {\\n        id\\n        name\\n        buildings {\\n            id\\n        name\\n        }\\n        siteNumber\\n        customID\\n        timezone\\n    }\\n  }\\n}\",\"variables\":{}}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer [insert access_token here]'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}
{% endtabs %}

***

### Update site(s)

```graphql
mutation updateSiteInfo($input: UpdateSiteInfoInput!) {
  updateSiteInfo(input: $input) {
    site {
      id
      name
      siteNumber

      timezone
    }
  }
}

# Variables
{
    "input" :{
        "name": "example_site_updated_name",
        "id": "site_2mA7CiVpUluJ4rz5MxhfxNAH3PT"
    }
}
```

#### Code Examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://api.butlr.io/api/v3/graphql' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer [insert access_token here]' \
--data '{"query":"mutation updateSiteInfo($input: UpdateSiteInfoInput!) {\n  updateSiteInfo(input: $input) {\n    site {\n      id\n      name\n      siteNumber\n      timezone\n    }\n  }\n}","variables":{"input":{"name":"example_site_updated_name","id":"site_2mA7CiVpUluJ4rz5MxhfxNAH3PT"}}}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

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

func main() {

  url := "https://api.butlr.io/api/v3/graphql"
  method := "POST"

  payload := strings.NewReader("{\"query\":\"mutation updateSiteInfo($input: UpdateSiteInfoInput!) {\\n  updateSiteInfo(input: $input) {\\n    site {\\n      id\\n      name\\n      siteNumber\\n      timezone\\n    }\\n  }\\n}\",\"variables\":{\"input\":{\"name\":\"example_site_updated_name\",\"id\":\"site_2mA7CiVpUluJ4rz5MxhfxNAH3PT\"}}}")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer [insert access_token here]")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v3/graphql"

payload = "{\"query\":\"mutation updateSiteInfo($input: UpdateSiteInfoInput!) {\\n  updateSiteInfo(input: $input) {\\n    site {\\n      id\\n      name\\n      siteNumber\\n      timezone\\n    }\\n  }\\n}\",\"variables\":{\"input\":{\"name\":\"example_site_updated_name\",\"id\":\"site_2mA7CiVpUluJ4rz5MxhfxNAH3PT\"}}}"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer [insert access_token here]'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.butlr.io/asset-management/graphql-api-overview/sites.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
