> This page is for Trading.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.immix.xyz/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.immix.xyz/_mcp/server.

# Write a preference

PUT https://api.immix.xyz/v1/me/preferences/{key}
Content-Type: application/json

Writes the key's whole document, creating the key or replacing it. State what you computed the write against: `If-Match: "<version>"` from the read or the page, `If-None-Match: *` to write only while nothing is stored under the key, or `If-Match: *` to overwrite on purpose. Neither header is 428; a stale version is 412 with `currentVersion`: re-read and reapply.

Reference: https://docs.immix.xyz/trading/api-reference/rest-api/preferences/put

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `key` (string, required) — The key, matched exactly.

### Headers

- `If-Match` (string, optional) — The version you computed the write against, quoted or bare, or `*` to overwrite on purpose. One of this and `If-None-Match: *` is required.
- `If-None-Match` (enum, optional) — `*`: create the key only while nothing is stored under it, the write a client makes after a 404. Anything else is 400.
  - Allowed values: `*`
- `X-Request-Id` (string, optional) — Your own id for the request: 8 to 128 of `[A-Za-z0-9._-]`. It becomes the request's id and is echoed on the response. A value off that grammar is replaced with a fresh id, never refused.

### Body (application/json)

This endpoint expects an object.

- `value` (any, required)
- `tags` (list of string, optional) — Tags to list by: at most 50, each 1 to 64 characters of `[A-Za-z0-9:._-]`, lower-cased and de-duplicated on write. Absent or empty, the row carries none: a write restates the tags too.

## Response

### 200

The key was replaced. The `ETag` is its new version.

- `key` (string, required) — The key: 1 to 128 characters of `[A-Za-z0-9._:-]`, starting with a letter or digit, matched exactly.
- `value` (any, required)
- `tags` (list of string, required) — Tags to list by: at most 50, each 1 to 64 characters of `[a-z0-9:._-]`, lower-cased on write and unique.
- `version` (string, required) — The row's version, the `ETag`'s value: send it as `If-Match` on a write of the key. A decimal string from one sequence shared by every row, so it never repeats for a key, not even across a delete and a re-create.
- `createdAtNs` (string, required) — When the key was first written, in epoch nanoseconds; microsecond-exact, so it ends in `000`.
- `updatedAtNs` (string, required) — When the key was last written, in epoch nanoseconds; microsecond-exact, so it ends in `000`.

## Errors

### 400 Put Preferences Request Bad Request Error

The request is malformed: the key is off its grammar, the body is not the document, a tag is off its grammar or there are more than 50; or `INVALID_IF_MATCH`: a precondition header this write cannot read (weak, a list, both headers at once).

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 401 Put Preferences Request Unauthorized Error

The bearer token is missing or not valid.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 409 Put Preferences Request Conflict Error

`PREFERENCE_CEILING`: you hold 2,000 keys in this organisation; delete one first.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 412 Put Preferences Request Precondition Failed Error

`VERSION_CONFLICT`: the row's version is not the one `If-Match` named, or `If-None-Match: *` met a row. `currentVersion` and the `ETag` carry the row's version where there is one; a row that no longer exists carries none.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 413 Put Preferences Request Content Too Large Error

`PAYLOAD_TOO_LARGE`: the value is over 64 KiB serialised.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 428 Put Preferences Request Precondition Error

`PRECONDITION_REQUIRED`: neither `If-Match` nor `If-None-Match: *` was sent.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 501 Put Preferences Request Not Implemented Error

`NOT_IMPLEMENTED`: this deployment runs no user-state store, so it serves no preferences.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

### 503 Put Preferences Request Service Unavailable Error

`USER_STATE_UNAVAILABLE`: your preferences cannot be read or written now; retry. `USER_STATE_SCHEMA_BEHIND`: the store is behind this release; a retry does not help until the deployment catches up.

- `error` (ErrorBody, required)
- `currentVersion` (string, optional) — On a 412 `VERSION_CONFLICT` from a conditional write that met a row: the row's current version (the `ETag` carries the same token); re-read, reapply, retry. Absent from every other response, a 412 for a row that no longer exists included.

## Types

### ErrorBody

- `code` (string, required) — Machine-readable, UPPER_SNAKE and append-only; tolerate codes you don't know. Branch on this, never on the message.
- `message` (string, required) — For display only; its wording may change at any time.
- `retryable` (boolean, required) — Whether sending the identical request again, after `Retry-After` or a short pause, can succeed with nothing else changed. `false` where something must change first: the request, the caller's standing, or the platform's own records or deployment.
- `requestId` (string, required) — The request's id, also sent as X-Request-Id; quote it to support.

## Examples

**Request**

```json
{
  "value": {
    "key": "value"
  }
}
```

**Response**

```json
{
  "key": "key",
  "value": {
    "key": "value"
  },
  "tags": [
    "tags",
    "tags"
  ],
  "version": "version",
  "createdAtNs": "createdAtNs",
  "updatedAtNs": "updatedAtNs"
}
```

**SDK Code**

```python
import requests

url = "https://api.immix.xyz/v1/me/preferences/key"

payload = { "value": { "key": "value" } }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.immix.xyz/v1/me/preferences/key';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"value":{"key":"value"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.immix.xyz/v1/me/preferences/key"

	payload := strings.NewReader("{\n  \"value\": {\n    \"key\": \"value\"\n  }\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.immix.xyz/v1/me/preferences/key")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"value\": {\n    \"key\": \"value\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.immix.xyz/v1/me/preferences/key")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"value\": {\n    \"key\": \"value\"\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.immix.xyz/v1/me/preferences/key', [
  'body' => '{
  "value": {
    "key": "value"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.immix.xyz/v1/me/preferences/key");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"value\": {\n    \"key\": \"value\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["value": ["key": "value"]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.immix.xyz/v1/me/preferences/key")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```