İçeriğe geç
Doğrulandı

Projeleri ve dağıtımları listeleyin

Bir hesabın sahip olduğu her çalışma alanı, sonra gerçekten çalışan her uygulama: iki CouchDB görünümü okuması olarak.

"Projeler" ve "dağıtımlar" iki farklı soruyu yanıtlar. Proje, hesaptaki bir çalışma alanıdır: proje değiştiricide gördüğünüz şey, içinde bir şey hiç yayına girmiş olsun olmasın. Dağıtım ise gerçekten bir yerde çalışan bir uygulamadır, kendi belgesinde is_deployment: true olur. Bir hesabı listelemek genellikle ikisini de içerir: önce çalışma alanları, sonra her birinde çalışanlar.

Yöntemler

POST/cpi/get_account_projects
user

Get Account Projects

Returns the projects owned by the account (or all projects for superuser and support accounts) from the user_projects master view.

POST/cpi/get_account_deployments
user

Get Account Deployments

Returns the deployments associated with the account from the user_deployments master view.

Anlatım

Hesabın projelerini listeleyin

Anahtarınız dışında alan yok: iki yöntem de CouchDB görünümünü kimlik bilginizin zaten çözdüğü uid'ye göre anahtarlar.

curl -s https://xuda.ai/cpi/get_account_projects \
  -H 'content-type: application/json' \
  -d '{"api_key":"YOUR_API_KEY"}'
const res = await fetch('https://xuda.ai/cpi/get_account_projects', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ api_key: 'YOUR_API_KEY' }),
});
const { code, data } = await res.json();
if (code > 0) {
  for (const row of data.rows) console.log(row.id, row.value.app_name, row.value.app_status_code);
}
import requests

res = requests.post(
    'https://xuda.ai/cpi/get_account_projects',
    json={'api_key': 'YOUR_API_KEY'},
)
body = res.json()
if body['code'] > 0:
    for row in body['data']['rows']:
        print(row['id'], row['value']['app_name'], row['value']['app_status_code'])

2. Gerçekten dağıtılmış olanları listeleyin

Aynı yapı, farklı bir görünüm: user_deployments yalnızca is_deployment doğru olduğunda bir belge yayar. Bu yüzden bu liste, hesabın şimdiye kadar oluşturduğu tüm uygulamaların bir alt kümesidir: canlı bir erişim URL'si olanlar.

curl -s https://xuda.ai/cpi/get_account_deployments \
  -H 'content-type: application/json' \
  -d '{"api_key":"YOUR_API_KEY"}'
const res = await fetch('https://xuda.ai/cpi/get_account_deployments', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ api_key: 'YOUR_API_KEY' }),
});
const { code, data } = await res.json();
if (code > 0) {
  for (const row of data.rows) console.log(row.id, row.value.app_hosting, row.value.app_status_code);
}
import requests

res = requests.post(
    'https://xuda.ai/cpi/get_account_deployments',
    json={'api_key': 'YOUR_API_KEY'},
)
body = res.json()
if body['code'] > 0:
    for row in body['data']['rows']:
        print(row['id'], row['value']['app_hosting'], row['value']['app_status_code'])

Yanıt

İki yöntem de bir CouchDB görünüm sonucunu sarmalamadan olduğu gibi aktarır: code değeri 871dir (get_couch_view'nin her zaman döndürdüğü sabit başarı kodu, olağan 1 değil) ve data ham nano görünüm yanıtıdır: total_rows, offset ve { id, key, value } öğelerinden oluşan bir rows dizisi. id, projenin (veya dağıtımın) _id değeridir; bu bölümdeki diğer her çağrıya app_id olarak verdiğiniz değer.

json
{
  "code": 871,
  "data": {
    "total_rows": 3,
    "offset": 0,
    "rows": [
      {
        "id": "app_5d9e21",
        "key": "acc_8f2a1c",
        "value": {
          "_id": "app_5d9e21",
          "app_name": "Marketing site",
          "app_type": "master",
          "app_status_code": 3,
          "app_access_type": "private",
          "docDate": 1735689600000,
          "app_icon_prop": { "app_icon_background_color": "#4f46e5", "app_icon_size": "md" }
        }
      }
    ]
  }
}

get_account_deployments satırları aynı alanları artı app_hosting_server, app_datacenter_id, app_hosting ve is_deployment: true taşır, çünkü user_deployments bunları ortak kümenin üstüne yayar. Bu görünümün ya da user_projects'in size göstereceği tek durum app_status_code < 4'tür: iki map işlevi de 4 ve üstündeki her şeyi süzer. Bu yüzden silinmiş bir proje kontrol edilecek bir durumla görünmek yerine yalnızca listeden kaybolur.

Bir çalışma alanının satırı ad geçersiz kılma taşıyabilir

get_account_projects, bir çalışma alanının adlandırılmış bir profili olduğunda hesabın kendi çalışma alanı satırına main_profile_name ekler. Bu yüzden "sizin" proje olarak gösterdiğiniz satır, saklanan app_name değerinden farklı okunabilir. Varsa main_profile_name değerini tercih edin.

Hatalar

İki yöntem de yalnızca her çağrının başarısız olabileceği şekilde başarısız olur: eksik ya da yetkisiz bir api_key (-401, bkz. Hatalar). İkisi de app_id veya başka bir girdiye göre dallanmaz, çünkü hiçbiri girdi almaz. O listede henüz hiçbir şeyi olmayan bir hesap için boş bir rows dizisi hata değil, gerçek ve başarılı bir yanıttır.

Sonraki