Skip to content

Bits için CRUD İşlemleri

Bu öğreticide bir Bit'in tam yaşam döngüsünü gerçekleştireceksiniz: oluşturun, ayrıntılarını okuyun, güncelleyin, tamamlama olaylarını kaydedin ve silin. Bits, Chainabit'teki atomik izlenebilir görevlerdir.

Önkoşullar

  • Geçerli bir erişim belirteci olan bir Chainabit hesabı
  • Terminalinizde curl'un mevcut olması
  • Bits eklemek için mevcut bir Chain (Productivity API aracılığıyla bir tane oluşturun)

Ortam değişkenlerinizi ayarlayın:

bash
export TOKEN="your-access-token"
export CHAIN_ID="chain_01HQA..."

Bit Yaşam Döngüsü


Adım 1: Bir Bit Oluşturun

Chain'inize izlenebilir bir görev ekleyin:

bash
curl -s -X POST "https://api.chainabit.com/api/v1/bits" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": "'"$CHAIN_ID"'",
    "title": "Read 20 pages",
    "description": "Read at least 20 pages of the current book"
  }'
javascript
const res = await fetch(`https://api.chainabit.com/api/v1/bits`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    chainId: CHAIN_ID,
    title: 'Read 20 pages',
    description: 'Read at least 20 pages of the current book',
  }),
});
const data = await res.json();
console.log(data);
python
import requests

res = requests.post(
    f"{BASE}/bits",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        "chainId": CHAIN_ID,
        "title": "Read 20 pages",
        "description": "Read at least 20 pages of the current book",
    },
)
print(res.json())

Yanıt:

json
{
  "data": {
    "id": "bit_01HQA...",
    "chainId": "chain_01HQA...",
    "title": "Read 20 pages",
    "description": "Read at least 20 pages of the current book",
    "createdAt": "2026-03-17T10:00:00.000Z",
    "updatedAt": "2026-03-17T10:00:00.000Z"
  }
}

Bit ID'sini kaydedin:

bash
export BIT_ID="bit_01HQA..."

Adım 2: Bir Bit'i Okuyun

ID'sine göre bit ayrıntılarını alın:

bash
curl -s "https://api.chainabit.com/api/v1/bits/$BIT_ID" \
  -H "Authorization: Bearer $TOKEN"
javascript
const res = await fetch(`https://api.chainabit.com/api/v1/bits/${BIT_ID}`, {
  headers: { Authorization: `Bearer ${TOKEN}` },
});
const data = await res.json();
console.log(data);
python
res = requests.get(
    f"{BASE}/bits/{BIT_ID}",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
print(res.json())

Yanıt:

json
{
  "data": {
    "id": "bit_01HQA...",
    "chainId": "chain_01HQA...",
    "title": "Read 20 pages",
    "description": "Read at least 20 pages of the current book",
    "createdAt": "2026-03-17T10:00:00.000Z",
    "updatedAt": "2026-03-17T10:00:00.000Z"
  }
}

Adım 3: Bir Bit'i Güncelleyin

Bit'in başlığını veya açıklamasını değiştirin:

bash
curl -s -X PATCH "https://api.chainabit.com/api/v1/bits/$BIT_ID" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Read 30 pages",
    "description": "Read at least 30 pages of the current book"
  }'
javascript
const res = await fetch(`https://api.chainabit.com/api/v1/bits/${BIT_ID}`, {
  method: 'PATCH',
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: 'Read 30 pages',
    description: 'Read at least 30 pages of the current book',
  }),
});
const data = await res.json();
console.log(data);
python
res = requests.patch(
    f"{BASE}/bits/{BIT_ID}",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        "title": "Read 30 pages",
        "description": "Read at least 30 pages of the current book",
    },
)
print(res.json())

Yanıt:

json
{
  "data": {
    "id": "bit_01HQA...",
    "title": "Read 30 pages",
    "description": "Read at least 30 pages of the current book",
    "updatedAt": "2026-03-17T10:05:00.000Z"
  }
}

Adım 4: Bir Tamamlama Olayını Kaydedin

Bit'in tamamlandığını izleyin:

bash
curl -s -X POST "https://api.chainabit.com/api/v1/bits/$BIT_ID/completions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "completedAt": "2026-03-17T08:00:00.000Z",
    "notes": "Finished chapters 5 and 6"
  }'
javascript
const res = await fetch(`https://api.chainabit.com/api/v1/bits/${BIT_ID}/completions`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    completedAt: '2026-03-17T08:00:00.000Z',
    notes: 'Finished chapters 5 and 6',
  }),
});
const data = await res.json();
console.log(data);
python
res = requests.post(
    f"{BASE}/bits/{BIT_ID}/completions",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Content-Type": "application/json",
    },
    json={
        "completedAt": "2026-03-17T08:00:00.000Z",
        "notes": "Finished chapters 5 and 6",
    },
)
print(res.json())

Yanıt:

json
{
  "data": {
    "id": "event_01HQB...",
    "bitId": "bit_01HQA...",
    "completedAt": "2026-03-17T08:00:00.000Z",
    "notes": "Finished chapters 5 and 6",
    "createdAt": "2026-03-17T08:01:00.000Z"
  }
}

Adım 5: Bir Bit'i Silin

Artık gerekli olmayan bir bit'i kaldırın:

bash
curl -s -X DELETE "https://api.chainabit.com/api/v1/bits/$BIT_ID" \
  -H "Authorization: Bearer $TOKEN"
javascript
const res = await fetch(`https://api.chainabit.com/api/v1/bits/${BIT_ID}`, {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${TOKEN}` },
});
console.log(res.status); // 204
python
res = requests.delete(
    f"{BASE}/bits/{BIT_ID}",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
print(res.status_code)  # 204

Başarılı bir silme işlemi gövdesi olmayan bir 204 No Content durumu döndürür.


Özet

Bu öğreticide şunları yaptınız:

  1. Mevcut bir Chain altında bir Bit Oluşturdunuz
  2. Bit ayrıntılarını ID'ye göre Okudunuz
  3. Bit'in başlığını ve açıklamasını Güncellediniz
  4. İlerlemeyi izlemek için bir tamamlama olayını kaydettiniz
  5. Bit'i Sildiniz

Sonraki Adımlar

Built with purpose.