# Save preferences

> Save preferences: PUT /v1/preferences. Changes the preferences. Partial (only what is sent changes) and strict (an unknown field or value returns 422 invalid_field). Returns the full preferences. With email true, the server emails postSent, postFailed, scheduledFail, the weeklySummary (Mondays at 08

Source: https://praeko.app/docs/en/api/preferences/save-preferences

`PUT /v1/preferences` · minimum scope: write

Changes the preferences. Partial (only what is sent changes) and strict (an unknown field or value returns 422 `invalid_field`). Returns the full preferences. With `email` true, the server emails `postSent`, `postFailed`, `scheduledFail`, the `weeklySummary` (Mondays at 08:00, `America/Sao_Paulo`) and `newComment` (batched, at most one email per hour); with `panel` true, the event goes to the notification center (`GET /v1/notifications`).

> **Headers** `Authorization: Bearer praeko_…` and `X-Praeko-Contract: en`. Always send both.

## Request body

JSON. Required fields must be sent; the others can be left out. A field that is not in the table is rejected. Strict: an unknown field or value returns 422 `invalid_field`. Partial: only what you send changes.

| Field | Type | Description |
|---|---|---|
| `theme` (optional) | string | Dashboard theme. Values: light, dark, system. |
| `language` (optional) | string | Dashboard language. Values: pt-BR, en. |
| `notifications` (optional) | object | Notifications per event. Only the events you send change. |
| `notifications.postSent` (optional) | object | Where to notify this event. |
| `notifications.postSent.email` (optional) | boolean | Notify by email. |
| `notifications.postSent.panel` (optional) | boolean | Notify in the dashboard. |
| `notifications.postFailed` (optional) | object | Where to notify this event. |
| `notifications.postFailed.email` (optional) | boolean | Notify by email. |
| `notifications.postFailed.panel` (optional) | boolean | Notify in the dashboard. |
| `notifications.scheduledFail` (optional) | object | Where to notify this event. |
| `notifications.scheduledFail.email` (optional) | boolean | Notify by email. |
| `notifications.scheduledFail.panel` (optional) | boolean | Notify in the dashboard. |
| `notifications.weeklySummary` (optional) | object | Where to notify this event. |
| `notifications.weeklySummary.email` (optional) | boolean | Notify by email. |
| `notifications.weeklySummary.panel` (optional) | boolean | Notify in the dashboard. |
| `notifications.newComment` (optional) | object | Where to notify this event. |
| `notifications.newComment.email` (optional) | boolean | Notify by email. |
| `notifications.newComment.panel` (optional) | boolean | Notify in the dashboard. |

**Body example**

```json
{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
}
```

## Example

**curl**

```bash
curl -X PUT "https://praeko.app/v1/preferences" \
  -H "Authorization: Bearer $PRAEKO_KEY" \
  -H "X-Praeko-Contract: en" \
  -H "Content-Type: application/json" \
  -d '{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
}'
```

**JavaScript**

```js
const res = await fetch("https://praeko.app/v1/preferences", {
  method: "PUT",
  headers: {
    "Authorization": `Bearer ${process.env.PRAEKO_KEY}`,
    "X-Praeko-Contract": "en",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "theme": "dark",
    "language": "pt-BR",
    "notifications": {
      "postFailed": {
        "email": true,
        "panel": true
      },
      "weeklySummary": {
        "email": false
      }
    }
  }),
});
console.log(res.status, await res.json());
```

**Node**

```js
import { Praeko } from "@praeko/sdk";

const praeko = new Praeko({ url: "https://praeko.app", key: process.env.PRAEKO_KEY });
const resultado = await praeko.preferences.put({
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
});
console.log(resultado);
```

**Python**

```python
import os
import requests

resp = requests.put(
    "https://praeko.app/v1/preferences",
    headers={
        "Authorization": f"Bearer {os.environ['PRAEKO_KEY']}",
        "X-Praeko-Contract": "en",
    },
    json={
        "theme": "dark",
        "language": "pt-BR",
        "notifications": {
            "postFailed": {
                "email": True,
                "panel": True,
            },
            "weeklySummary": {
                "email": False,
            },
        },
    },
)
print(resp.status_code, resp.json())
```

**PHP**

```php
<?php
$corpo = <<<'JSON'
{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
}
JSON;

$ch = curl_init('https://praeko.app/v1/preferences');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("PRAEKO_KEY"),
        'X-Praeko-Contract: en',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $corpo,
]);
$resposta = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $resposta, PHP_EOL;
curl_close($ch);
```

**Go**

```go
package main

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

func main() {
	body := strings.NewReader(`{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
}`)
	req, err := http.NewRequest("PUT", "https://praeko.app/v1/preferences", body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("PRAEKO_KEY"))
	req.Header.Set("X-Praeko-Contract", "en")
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	out, _ := io.ReadAll(resp.Body)
	fmt.Println(resp.Status, string(out))
}
```

**Ruby**

```ruby
require "net/http"
require "uri"

uri = URI("https://praeko.app/v1/preferences")
request = Net::HTTP::Put.new(uri)
request["Authorization"] = "Bearer #{ENV['PRAEKO_KEY']}"
request["X-Praeko-Contract"] = "en"
request["Content-Type"] = "application/json"
request.body = <<~'JSON'
  {
    "theme": "dark",
    "language": "pt-BR",
    "notifications": {
      "postFailed": {
        "email": true,
        "panel": true
      },
      "weeklySummary": {
        "email": false
      }
    }
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
puts response.code, response.body
```

**C#**

```csharp
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Put, "https://praeko.app/v1/preferences");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("PRAEKO_KEY"));
request.Headers.Add("X-Praeko-Contract", "en");
request.Content = new StringContent("""
    {
      "theme": "dark",
      "language": "pt-BR",
      "notifications": {
        "postFailed": {
          "email": true,
          "panel": true
        },
        "weeklySummary": {
          "email": false
        }
      }
    }
""", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String body = """
            {
              "theme": "dark",
              "language": "pt-BR",
              "notifications": {
                "postFailed": {
                  "email": true,
                  "panel": true
                },
                "weeklySummary": {
                  "email": false
                }
              }
            }
            """;
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://praeko.app/v1/preferences"))
            .header("Authorization", "Bearer " + System.getenv("PRAEKO_KEY"))
            .header("X-Praeko-Contract", "en")
            .header("Content-Type", "application/json")
            .method("PUT", HttpRequest.BodyPublishers.ofString(body))
            .build();
        HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

**HTTPie**

```bash
http PUT "https://praeko.app/v1/preferences" \
  "Authorization: Bearer $PRAEKO_KEY" \
  "X-Praeko-Contract: en" \
  "Content-Type: application/json" \
  --raw='{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postFailed": {
      "email": true,
      "panel": true
    },
    "weeklySummary": {
      "email": false
    }
  }
}'
```

> Official SDK for Node: Install it with `npm install @praeko/sdk` (see [SDK and CLI](https://praeko.app/docs/en/sdk)).

## Response

| Success status | When |
|---|---|
| `200` | Success. |

**Response 200**

```json
{
  "theme": "dark",
  "language": "pt-BR",
  "notifications": {
    "postSent": {
      "email": false,
      "panel": true
    },
    "postFailed": {
      "email": true,
      "panel": true
    },
    "scheduledFail": {
      "email": false,
      "panel": true
    },
    "weeklySummary": {
      "email": false,
      "panel": true
    },
    "newComment": {
      "email": false,
      "panel": true
    }
  }
}
```

## Errors

| Status | code | When |
|---|---|---|
| 400 | `empty_body` | The request body is empty. |
| 400 | `invalid_json` | The request body is not a JSON object. |
| 413 | `body_too_large` | The request body is larger than 1 MB. |
| 422 | `invalid_field` | Unknown field, event, channel or value. |

### Errors on any route

| Status | code | When |
|---|---|---|
| 401 | `unauthorized` | The `Authorization: Bearer …` header is missing. |
| 401 | `invalid_api_key` | The key does not exist. |
| 401 | `revoked_api_key` | The key has been revoked. |
| 401 | `expired_api_key` | The key has expired. |
| 403 | `forbidden` | The key's scope is not enough for this route (see the scope badge). |
| 429 | `rate_limited` | The per-minute request limit was exceeded. |

The body of every error is `{ "error": { "code", "message", "details"? } }`. See [all error codes](https://praeko.app/docs/en/guides/errors-and-limits).

## Try it

> **Try it**: the live test needs you to be signed in. It is switched off here.
