# `GraphApi.Subscriptions`
[🔗](https://github.com/keenmate/microsoft_graph/blob/v1.0.0-rc.1/lib/graph_api/subscriptions.ex#L1)

Operations on the `/subscriptions` resource.

Subscriptions allow your application to receive webhook notifications when
data changes in Microsoft Graph. You create a subscription for a specific
resource (e.g., users, messages, events) and Microsoft Graph sends POST
requests to your notification URL when changes occur.

## Examples

    # Create a subscription
    {:ok, sub} = GraphApi.Subscriptions.create(%{
      "changeType" => "created,updated,deleted",
      "notificationUrl" => "https://example.com/webhook",
      "resource" => "users",
      "expirationDateTime" => "2025-04-01T00:00:00Z",
      "clientState" => "my-secret-state"
    })

    # List active subscriptions
    {:ok, %{"value" => subs}} = GraphApi.Subscriptions.list()

    # Renew before expiration
    {:ok, renewed} = GraphApi.Subscriptions.renew(sub["id"], %{
      "expirationDateTime" => "2025-05-01T00:00:00Z"
    })

    # Clean up
    :ok = GraphApi.Subscriptions.delete(sub["id"])

# `create`

```elixir
@spec create(
  map(),
  keyword()
) :: {:ok, map()} | {:error, term()}
```

Creates a new subscription.

## Required fields

* `"changeType"` — Comma-separated: `"created"`, `"updated"`, `"deleted"`
* `"notificationUrl"` — HTTPS endpoint that will receive notifications
* `"resource"` — Resource path to watch (e.g., `"users"`, `"me/messages"`)
* `"expirationDateTime"` — ISO 8601 datetime for subscription expiry

## Optional fields

* `"clientState"` — Secret string included in each notification for validation
* `"latestSupportedTlsVersion"` — Minimum TLS version

# `create_query`

```elixir
@spec create_query(
  map(),
  keyword()
) :: GraphApi.Batch.Request.t()
```

Batch query variant of `create/2`.

# `delete`

```elixir
@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, term()}
```

Deletes a subscription.

# `delete_query`

```elixir
@spec delete_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()
```

Batch query variant of `delete/2`.

# `get`

```elixir
@spec get(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}
```

Gets a subscription by ID.

# `get_query`

```elixir
@spec get_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()
```

Batch query variant of `get/2`.

# `list`

```elixir
@spec list(keyword()) :: {:ok, map()} | {:error, term()}
```

Lists active subscriptions.

# `list_query`

```elixir
@spec list_query(keyword()) :: GraphApi.Batch.Request.t()
```

Batch query variant of `list/1`.

# `renew`

```elixir
@spec renew(String.t(), map(), keyword()) :: {:ok, map()} | :ok | {:error, term()}
```

Renews (updates) a subscription, typically to extend its expiration.

## Examples

    GraphApi.Subscriptions.renew("sub-id", %{
      "expirationDateTime" => "2025-05-01T00:00:00Z"
    })

# `renew_query`

```elixir
@spec renew_query(String.t(), map(), keyword()) :: GraphApi.Batch.Request.t()
```

Batch query variant of `renew/3`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
