EndpointsOrganization Branches

Organization Branches

Function-calling namespace: organizationBranches

  • Base URL: https://api.aivida.in
  • Engine endpoint: POST /api
  • Auth: Stack token middleware enabled in optional mode.
  • Send token in header: x-stack-access-token: <access_token> (or Authorization: Bearer <access_token>).
  • In optional mode: no token is allowed; invalid token is rejected with 401.

create

Source: backend/endpoints/organization-branches/create

Input Fields

FieldTypeRequiredConstraints
organizationIdstringYes-
branchNamestringYes-
branchCodestringYesunique per organization among non-deleted branches
branchTypestringYes-
descriptionstringNo-
managerNamestringNo-
managerContactstringNointernational phone format
streetAddressstringNo-
areastringNo-
citystringNo-
statestringNo-
postalCodestringNo-
countrystringNo-
coordinatesobjectNoobject with numeric latitude and longitude
contactPhonestringNointernational phone format
telephoneNumberstringNo-
contactEmailstringNo-
websitestringNo-
emergencyContactstringNointernational phone format
openingHoursobjectNoobject with schedule, timezone, and is24Hours
coverImageUrlstringNo-
statusstringYesoneof: active
isActivebooleanNo-
createdAtintegerNounix-ms timestamp; nullable
updatedAtintegerNounix-ms timestamp; nullable

Business Rules

  • organizationId, branchName, branchCode, branchType, and status are required.
  • The organization must exist, be active, and not be deleted.
  • branchCode must be unique among non-deleted branches for the same organization.
  • Supported status values are active, inactive, coming_soon, and temporarily_closed.

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "organizationBranches",
  "apiName": "create",
  "data": {
    "organizationId": "org_123",
    "branchName": "Anna Nagar Branch",
    "branchCode": "ANNA",
    "branchType": "clinic",
    "description": "Primary dental branch for Anna Nagar.",
    "managerName": "Priya Raman",
    "managerContact": "+919876543210",
    "streetAddress": "12, 2nd Avenue",
    "area": "Anna Nagar",
    "city": "Chennai",
    "state": "Tamil Nadu",
    "postalCode": "600040",
    "country": "India",
    "coordinates": {
      "latitude": 13.0405271553947,
      "longitude": 80.21238,
      "accuracy": 316,
      "capturedAt": 1779971037247
    },
    "contactPhone": "+914412345678",
    "contactEmail": "annanagar@example.com",
    "website": "https://example.com/anna-nagar",
    "emergencyContact": "+919123456789",
    "openingHours": {
      "schedule": {
        "monday": [
          {
            "start": "09:00",
            "end": "18:00"
          }
        ]
      },
      "timezone": "Asia/Kolkata",
      "is24Hours": false
    },
    "coverImageUrl": "https://example.com/images/anna-nagar.jpg",
    "status": "active",
    "isActive": true
  }
}'

Example Response

{
  "status": "ok",
  "data": "branch_123"
}

delete

Source: backend/endpoints/organization-branches/delete

Input Fields

FieldTypeRequiredConstraints
idstringYes-
organizationIdstringYes-

Business Rules

  • This API performs a soft delete only.
  • The branch is marked isDeleted: true, isActive: false, and deletedAt is set.
  • Deleted branches are hidden from get and list APIs.

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "organizationBranches",
  "apiName": "delete",
  "data": {
    "id": "branch_123",
    "organizationId": "org_123"
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "message": "Organization branch deleted successfully"
  }
}

getById

Source: backend/endpoints/organization-branches/get-by-id

Input Fields

FieldTypeRequiredConstraints
idstringYes-
organizationIdstringYes-

Response Data Format

FieldTypeNotes
_idstringBranch ID.
organizationIdstringParent organization ID.
branchNamestringDisplay name of the branch.
branchCodestringUnique active branch code within the organization.
branchTypestringBranch category/type.
descriptionstringOptional branch description.
managerNamestringOptional branch manager name.
managerContactstringOptional manager phone number.
streetAddressstringStreet address.
areastringArea/locality.
citystringCity.
statestringState.
postalCodestringPostal code.
countrystringCountry.
coordinatesobjectLocation object with latitude, longitude, optional accuracy, and optional capturedAt.
contactPhonestringBranch contact phone.
contactEmailstringBranch contact email.
websitestringBranch website.
emergencyContactstringEmergency contact phone.
openingHoursobjectSchedule object with schedule, timezone, and is24Hours.
coverImageUrlstringCover image URL.
statusstringactive, inactive, coming_soon, or temporarily_closed.
isActivebooleanActive flag.
isDeletedbooleanSoft delete flag.
deletedAtintegerUnix-ms timestamp when soft deleted; omitted when not deleted.
createdAtintegerUnix-ms creation timestamp.
updatedAtintegerUnix-ms update timestamp.

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "organizationBranches",
  "apiName": "getById",
  "data": {
    "id": "branch_123",
    "organizationId": "org_123"
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "_id": "branch_123",
    "organizationId": "org_123",
    "branchName": "Anna Nagar Branch",
    "branchCode": "ANNA",
    "branchType": "clinic",
    "description": "Primary dental branch for Anna Nagar.",
    "managerName": "Priya Raman",
    "managerContact": "+919876543210",
    "streetAddress": "12, 2nd Avenue",
    "area": "Anna Nagar",
    "city": "Chennai",
    "state": "Tamil Nadu",
    "postalCode": "600040",
    "country": "India",
    "coordinates": {
      "latitude": 13.0405271553947,
      "longitude": 80.21238,
      "accuracy": 316,
      "capturedAt": 1779971037247
    },
    "contactPhone": "+914412345678",
    "contactEmail": "annanagar@example.com",
    "website": "https://example.com/anna-nagar",
    "emergencyContact": "+919123456789",
    "openingHours": {
      "schedule": {
        "monday": [
          {
            "start": "09:00",
            "end": "18:00"
          }
        ]
      },
      "timezone": "Asia/Kolkata",
      "is24Hours": false
    },
    "coverImageUrl": "https://example.com/images/anna-nagar.jpg",
    "status": "active",
    "isActive": true,
    "isDeleted": false,
    "createdAt": 1779971037247,
    "updatedAt": 1779971037247
  }
}

listByOrganization

Source: backend/endpoints/organization-branches/list-by-organization

Input Fields

FieldTypeRequiredConstraints
organizationIdstringYes-
searchstringNo-
pageintegerNodefault: 1
pageSizeintegerNodefault: 20

List Rules

  • Lists non-deleted branches for one organization.
  • Supports page and pageSize; defaults are handled by the backend.

Response Data Format

FieldTypeNotes
itemsarray<OrganizationBranch>Non-deleted branches for the requested organization. Each item has the same shape as getById.
totalintegerTotal matching branch count before pagination.
pageintegerCurrent page number.
pageSizeintegerNumber of records requested per page.
totalPagesintegerTotal pages calculated from total and pageSize.

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "organizationBranches",
  "apiName": "listByOrganization",
  "data": {
    "organizationId": "org_123",
    "page": 1,
    "pageSize": 20
  }
}'

Example Response

{
  "status": "ok",
  "data": {
    "items": [
      {
        "_id": "branch_123",
        "organizationId": "org_123",
        "branchName": "Anna Nagar Branch",
        "branchCode": "ANNA",
        "branchType": "clinic",
        "description": "Primary dental branch for Anna Nagar.",
        "managerName": "Priya Raman",
        "managerContact": "+919876543210",
        "streetAddress": "12, 2nd Avenue",
        "area": "Anna Nagar",
        "city": "Chennai",
        "state": "Tamil Nadu",
        "postalCode": "600040",
        "country": "India",
        "coordinates": {
          "latitude": 13.0405271553947,
          "longitude": 80.21238,
          "accuracy": 316,
          "capturedAt": 1779971037247
        },
        "contactPhone": "+914412345678",
        "contactEmail": "annanagar@example.com",
        "website": "https://example.com/anna-nagar",
        "emergencyContact": "+919123456789",
        "openingHours": {
          "schedule": {
            "monday": [
              {
                "start": "09:00",
                "end": "18:00"
              }
            ]
          },
          "timezone": "Asia/Kolkata",
          "is24Hours": false
        },
        "coverImageUrl": "https://example.com/images/anna-nagar.jpg",
        "status": "active",
        "isActive": true,
        "isDeleted": false,
        "createdAt": 1779971037247,
        "updatedAt": 1779971037247
      }
    ],
    "total": 1,
    "page": 1,
    "pageSize": 20,
    "totalPages": 1
  }
}

update

Source: backend/endpoints/organization-branches/update

Input Fields

FieldTypeRequiredConstraints
idstringYes-
organizationIdstringYes-
branchNamestringNonullable
branchCodestringNounique per organization among non-deleted branches; nullable
branchTypestringNonullable
descriptionstringNonullable
managerNamestringNonullable
managerContactstringNointernational phone format; nullable
streetAddressstringNonullable
areastringNonullable
citystringNonullable
statestringNonullable
postalCodestringNonullable
countrystringNonullable
coordinatesobjectNoobject with numeric latitude and longitude; nullable
contactPhonestringNointernational phone format; nullable
telephoneNumberstringNonullable
contactEmailstringNonullable
websitestringNonullable
emergencyContactstringNointernational phone format; nullable
openingHoursobjectNoobject with schedule, timezone, and is24Hours; nullable
coverImageUrlstringNonullable
statusstringNooneof: active
isActivebooleanNonullable
createdAtintegerNounix-ms timestamp; nullable
updatedAtintegerNounix-ms timestamp; nullable

Business Rules

  • id and organizationId are required.
  • The branch must exist under the organization and must not be deleted.
  • If branchCode is changed, it must remain unique among non-deleted branches for the same organization.

Example Request

curl -X POST https://api.aivida.in/api \
  -H "Content-Type: application/json" \
  -H "x-stack-access-token: <access_token_optional>" \
  -d '{
  "namespace": "organizationBranches",
  "apiName": "update",
  "data": {
    "id": "branch_123",
    "organizationId": "org_123",
    "branchName": "Anna Nagar Branch",
    "branchCode": "ANNA",
    "status": "active",
    "contactPhone": "+914412345678",
    "coordinates": {
      "latitude": 13.0405271553947,
      "longitude": 80.21238,
      "accuracy": 316,
      "capturedAt": 1779971037247
    },
    "openingHours": {
      "schedule": {
        "monday": [
          {
            "start": "09:00",
            "end": "18:00"
          }
        ]
      },
      "timezone": "Asia/Kolkata",
      "is24Hours": false
    }
  }
}'

Example Response

{
  "status": "ok",
  "data": "branch_123"
}