From c46af1ea1d17818110839f94ed16f01edd2a439a Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 19 Jan 2026 22:35:10 -0800 Subject: [PATCH] Add updateDeviceMetadata method to api.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add method to update device location and description via Legacy API device_form endpoint. Uses getLegacyWebViewCredentials for auth. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- services/api.ts | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/services/api.ts b/services/api.ts index c81f8ad..bed0e8f 100644 --- a/services/api.ts +++ b/services/api.ts @@ -1727,6 +1727,61 @@ class ApiService { } } + /** + * Update device metadata (location, description) in Legacy API + * Uses device_form endpoint + */ + async updateDeviceMetadata( + deviceId: string, + updates: { + location?: string; + description?: string; + } + ): Promise> { + try { + const creds = await this.getLegacyWebViewCredentials(); + if (!creds) { + return { ok: false, error: { message: 'Not authenticated with Legacy API', code: 'UNAUTHORIZED' } }; + } + + const formData = new URLSearchParams({ + function: 'device_form', + user_name: creds.userName, + token: creds.token, + device_id: deviceId, + }); + + // Add optional fields if provided + if (updates.location !== undefined) { + formData.append('location', updates.location); + } + if (updates.description !== undefined) { + formData.append('description', updates.description); + } + + const response = await fetch(API_BASE_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: formData.toString(), + }); + + if (!response.ok) { + return { ok: false, error: { message: 'Failed to update device' } }; + } + + const data = await response.json(); + + if (data.status !== '200 OK') { + return { ok: false, error: { message: data.message || 'Failed to update device' } }; + } + + return { ok: true, data: { success: true } }; + } catch (error: any) { + console.error('[API] updateDeviceMetadata error:', error); + return { ok: false, error: { message: error.message || 'Network error', code: 'NETWORK_ERROR' } }; + } + } + /** * Detach device from beneficiary */