Documentação API REST
API REST Legacy para controle de VMs no Google Cloud
Autenticação
Bearer Token
A autenticação é feita via Bearer Token no header HTTP. Todas as requisições devem incluir sua API Key no header Authorization.
Formato do Header
Use o header Authorization: Bearer YOUR_API_KEY
Exemplo de Header
// Headers necessáriosconst headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer sua-api-key-aqui'};Segurança
Nunca compartilhe sua API Key publicamente. Armazene-a em variáveis de ambiente e use HTTPS em produção.
Endpoints Disponíveis
API REST para Google Cloud
Base URL
https://nebulagg.com/api/legacy/gcpLista de Endpoints
| Método | Endpoint | Descrição |
|---|---|---|
| GET | /getall | Listar todos os discos e assinaturas |
| POST | /status | Consultar status da VM |
| POST | /start | Iniciar VM |
| POST | /stop | Parar VM (deleta instância) |
| POST | /restart | Reiniciar VM |
| POST | /connect | Conectar ao Moonlight |
| POST | /format | Formatar disco (deleta todos os dados) |
⚠️ Operações Destrutivas
Os endpoints /stop e /format são irreversíveis. O stop deleta a instância (mantém o disco) e o format apaga todos os dados do disco.
Exemplos de Uso
Exemplos em Diferentes Linguagens
const API_KEY = 'sua-api-key';const BASE_URL = 'https://nebulagg.com'; async function callAPI(endpoint, method = 'POST', body = null) { const options = { method, headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` } }; if (body && method !== 'GET') { options.body = JSON.stringify(body); } const response = await fetch(`${BASE_URL}${endpoint}`, options); return await response.json();} // Listar discosconst disks = await callAPI('/api/legacy/gcp/getall', 'GET'); // Ver statusconst status = await callAPI('/api/legacy/gcp/status', 'POST', { diskName: 'disk-abc123'}); // Iniciar VMconst start = await callAPI('/api/legacy/gcp/start', 'POST', { diskName: 'disk-abc123'}); // Conectar ao Moonlightconst connect = await callAPI('/api/legacy/gcp/connect', 'POST', { diskName: 'disk-abc123', pin: '1234'});Formato das Respostas
Resposta de Sucesso (getall)
{ "success": true, "data": { "user": { "id": "user_123", "email": "usuario@example.com", "name": "João" }, "disks": [ { "id": "disk_123", "name": "disk-abc123", "provider": "google", "isActive": true, "vCpus": 4, "sizeGB": 128, "validUntil": "2024-12-31T23:59:59.000Z" } ], "summary": { "totalDisks": 1, "activeDisks": 1 } }}Resposta de Erro
{ "error": "Disco não encontrado ou você não tem permissão para acessá-lo"}Códigos de Erro
Referência de Erros
A API retorna mensagens de erro descritivas. Use o status HTTP para tratamento programático.
Erros Comuns
| Status | Erro | Descrição |
|---|---|---|
| 401 | Unauthorized | API Key inválida ou não fornecida |
| 403 | Forbidden | Sem permissão para acessar este recurso |
| 404 | Not Found | Disco ou VM não encontrada |
| 429 | Too Many Requests | Rate limit excedido |
| 500 | Internal Server Error | Erro interno do servidor |
Rate Limiting
Máximo de 30 requisições por minuto.
Segurança
Use sempre HTTPS em produção. Nunca exponha sua API Key no código cliente.