WellNuo/docs/LEGACY_API_BUG_REPORT.md
Sergei 9cb51c13c0 Add Legacy API integration for sensors system
- Add legacyAPI.js service for authentication and deployment management
- Add deployments.js routes for device listing
- Add FEATURE-SENSORS-SYSTEM.md spec
- Add bug report: set_deployment missing deployment_id in response
- Add test scripts for Legacy API (create_deployment, find_deployments)
- Update beneficiaries.js to return deploymentId

BUG: Legacy API set_deployment returns {"ok": 1} but does NOT return
deployment_id. Waiting for Robert to fix this before we can auto-create
deployments for new beneficiaries.
2026-01-20 15:13:44 -08:00

2.8 KiB

Legacy API Bug Report: set_deployment Missing deployment_id

Summary

The set_deployment function successfully creates a deployment but does not return the deployment_id in the response. This prevents automated integration.

Current Behavior

# Request
curl -X POST "https://eluxnetworks.net/function/well-api/api" \
  -d "function=set_deployment" \
  -d "user_name=robster" \
  -d "token=$TOKEN" \
  -d "deployment=NEW" \
  -d "beneficiary_name=Test User" \
  # ... other required fields

# Response
{"ok": 1, "status": "200 OK"}

Expected Behavior

{"ok": 1, "deployment_id": 78, "status": "200 OK"}

Impact

WellNuo app needs to:

  1. Create deployment in Legacy API when beneficiary is created
  2. Save deployment_id to beneficiary_deployments.legacy_deployment_id
  3. Use this ID to fetch sensors via device_list_by_deployment

Without deployment_id in response, we cannot link the systems.

Workaround Attempted

Tried to find newly created deployment by searching recent IDs:

curl -X POST "..." -d "function=find_deployments" -d "well_ids=70,71,72,73,74,75"

This is unreliable because:

  • Race conditions with concurrent deployments
  • No guaranteed sequential IDs
  • Additional API call required

Full Working Request

#!/bin/bash
TOKEN="<robster_token>"
TS=$(date +%s)
PHOTO=$(base64 -i /tmp/no-photo.jpg | tr -d '\n')

curl -s -X POST "https://eluxnetworks.net/function/well-api/api" \
  -d "function=set_deployment" \
  -d "user_name=robster" \
  -d "token=$TOKEN" \
  -d "deployment=NEW" \
  -d "beneficiary_name=WellNuo Test" \
  -d "beneficiary_email=wellnuo-test-${TS}@wellnuo.app" \
  -d "beneficiary_user_name=wellnuo_test_${TS}" \
  -d "beneficiary_password=wellnuo123" \
  -d "beneficiary_address=WellNuo App" \
  -d "caretaker_username=anandk" \
  -d "caretaker_email=anandk@wellnuo.app" \
  -d "firstName=WellNuo" \
  -d "lastName=Test" \
  -d "first_name=WellNuo" \
  -d "last_name=Test" \
  -d "new_user_name=wellnuo_test_${TS}" \
  -d "phone_number=+10000000000" \
  -d "key=wellnuo123" \
  -d "signature=WellNuo" \
  -d "persons=1" \
  -d "pets=0" \
  -d "gender=0" \
  -d "race=0" \
  -d "born=1960" \
  -d "lat=0" \
  -d "lng=0" \
  -d "gps_age=0" \
  -d "wifis=[]" \
  -d "devices=[]" \
  -d "reuse_existing_devices=0" \
  --data-urlencode "beneficiary_photo=$PHOTO"

Required Fix

Modify set_deployment to return created deployment ID:

{"ok": 1, "deployment_id": <newly_created_id>, "status": "200 OK"}

Notes

  • User robster (max_role=-1, installer) is required for creating deployments
  • User anandk (max_role=2, caretaker) can only view assigned deployments
  • Credentials function works correctly for authentication
  • device_list_by_deployment works correctly once deployment_id is known

Date

2025-01-20