Skip to main content

Contact Discovery — API

Author: Josh S. Sakweli, Backend Lead Team
Last Updated: 2026-11-21
Version: v1.0

Base URL: http://localhost:8765/api/v1 (local) · https://dev.api.nexgate.co/api/v1 (staging)

Short Description: "Find friends from your contacts". With permission, the app sends the phone numbers in the person's contacts (never names); the server answers which of them are on NexGate, tells people when a contact joins, suggests people they may know, and makes two people who saved each other's number chat contacts. Design and the 12 storage rules: CONTACT_DISCOVERY_SPEC.md; build decisions: CONTACT_DISCOVERY_BUILD_PLAN.md §0a.

Hints:

  • Every call uses the person's normal login: Authorization: Bearer <access token>.
  • Feature switch app.contacts.enabled: off → every endpoint here answers 404, and chat "contacts" means follow each other only (as before).
  • Only numbers leave the phone. Names, photos, emails and notes stay on the phone; the app puts the saved name back next to each answer using the number it sent.
  • Normalise on the phone to full international form: 0712 345 678 → +255712345678. Anything else is skipped (counted in skipped, never echoed back).
  • The server keeps only a locked fingerprint of each number (a keyed hash); the number itself is never stored or logged.
  • Refusals are HTTP 409 with data.code and data.reason (show the reason as it is).

Contents

  • Part 1 — How it works
  • Part 2 — Contacts (1–6)
  • Part 3 — People you may know (7–8)
  • Part 4 — Chat
  • Part 5 — Admin (9–10)
  • Part 6 — Notifications
  • Part 7 — Refusal codes
  • Part 8 — App notes and screens checklist

Part 1 — How it works

1.1 Sync and match

 ASHA'S PHONE                                   SERVER                                        STORED
 ────────────                                   ──────                                        ──────
 permission ✅
 normalise numbers (names stay here)
 POST /contacts/sync ["+255712345678", …] ──► each number → fingerprint (Vault key)  ──► contact_links: Asha → fp…
                                                number thrown away                          (no names, no numbers)
                                                fingerprints ∩ people on NexGate
                                                − "find me" off − blocked either way
 "On NexGate (12)" ◄─────────────────────────── [{ number, accountId, name, … }]
 puts the saved name back by number
 later: PATCH /contacts/sync { added, removed } (changes only)

1.2 What happens with the stored fingerprints

Used for Never used for
"On NexGate" for the person who uploaded them ads, messages, analytics, shops
"Juma joined NexGate" when someone whose number Asha saved signs up telling Juma who has his number
"In your contacts" in people you may know (between users only) suggesting someone because they have your number
Chat contacts when both saved each other's number any admin screen (no endpoint shows anyone's contacts)

Numbers of people not on NexGate are deleted after 12 months without a full re-sync, when sync is turned off, or on "Delete uploaded contacts".

1.3 Examples

Situation Result
Asha saved Juma's number; Juma is on NexGate Juma in Asha's "On NexGate" ✅
Juma turned "Let people who have my number find me" off not in anyone's list, nobody gets "joined" about him ❌
Juma blocked Asha (or she blocked him) never shown either way ❌
Asha and Juma saved each other's number, both sync on mutual: true: chat contacts, can chat directly ✅
Only Asha saved Juma's number mutual: false: "On NexGate" only; chat contact only if they follow each other
Rehema got Juma's old number and joined Asha's alert says "Rehema Said joined NexGate" (her own NexGate name), so Asha sees it isn't Juma

Standard Response Format

{ "success": true, "httpStatus": "OK", "message": "Contacts synced", "action_time": "2026-11-21T10:30:45", "data": { } }
{ "success": false, "httpStatus": "CONFLICT", "message": "Too many new contacts today; the rest will sync tomorrow", "action_time": "2026-11-21T10:30:45",
  "data": { "code": "CONTACTS_DAILY_LIMIT", "reason": "Too many new contacts today; the rest will sync tomorrow" } }

Part 2 — Contacts

1. Sync (the whole list)

Purpose: The first upload after permission, and an occasional full re-sync. The stored list becomes exactly these numbers (numbers missing from it are removed). Turns sync on.

Endpoint: POST {base_url}/contacts/sync

Access Level: 🔒 Protected

Request JSON Sample:

{ "numbers": ["+255712345678", "+255754000111", "+254722000333"] }
Parameter Type Required Validation
numbers string[] Yes at most 5,000; each +<country code><number>; others are skipped

Success Response JSON Sample:

{
  "success": true, "httpStatus": "OK", "message": "Contacts synced", "action_time": "2026-11-21T10:30:45",
  "data": {
    "onNexGate": [
      { "number": "+255712345678", "accountId": "3213c20e-…", "name": "Juma Mwalimu", "userName": "jumamw",
        "userProfileMedia": { "fileId": "…", "status": "READY", "thumbUrl": "https://…", "mimeType": "image/jpeg" },
        "following": false, "mutual": true }
    ],
    "received": 3, "skipped": 0, "saved": 3
  }
}
Field Description
onNexGate[].number exactly as the app sent it: look up the saved name on the phone with it. Only in sync answers
name, userName, userProfileMedia the person's own NexGate name and photo (show small, under the saved name)
following the caller already follows them → "Following ✓"
mutual both saved each other's number → chat contacts ("Contacts on NexGate" in new chat)
received / skipped / saved numbers sent / not in international form / now stored for this person

After the first sync, a full sync may add at most 300 new numbers a day (CONTACTS_DAILY_LIMIT); prefer endpoint 2.

Errors (409): CONTACTS_DAILY_LIMIT, CONTACTS_STOPPED.


2. Sync changes

Purpose: Only what changed on the phone since the last sync.

Endpoint: PATCH {base_url}/contacts/sync

Access Level: 🔒 Protected

{ "added": ["+255688000222"], "removed": ["+255754000111"] }
Parameter Type Required Validation
added string[] No at most 1,000; counts toward 300 new numbers a day
removed string[] No at most 5,000

Answer: same shape as endpoint 1; onNexGate holds matches among added only.

Errors (409): CONTACTS_SYNC_OFF (sync first), CONTACTS_DAILY_LIMIT, CONTACTS_STOPPED.


3. On NexGate

Purpose: The "On NexGate" list from what is stored (no upload). Opening Find friends again.

Endpoint: GET {base_url}/contacts/on-nexgate

Access Level: 🔒 Protected

Answer: a list of the same items as endpoint 1, without number (the server doesn't have it). The app matches them to saved names by the accountId it remembered from the last sync answer; an item it can't match is shown with the NexGate name.


4. Delete uploaded contacts

Endpoint: DELETE {base_url}/contacts

Access Level: 🔒 Protected

Deletes the whole list at once and turns sync off. Answer: the settings (endpoint 5). People who were chat contacts only through saved numbers stop being chat contacts (unless they follow each other).


5–6. Settings

GET {base_url}/contacts/settings · PUT {base_url}/contacts/settings (only the fields sent change)

{ "syncOn": true, "findMe": true, "joinedAlerts": true, "uploaded": 412, "stopped": false }
Field Default Does
syncOn off until the first sync PUT false = endpoint 4 (deletes the list). Turned on by syncing, not by PUT
findMe on "Let people who have my number find me": off → in nobody's "On NexGate", no "joined" about you, no chat contacts from numbers
joinedAlerts on "Tell me when contacts join"
uploaded — how many numbers are stored for you
stopped — sync stopped for unusual uploads; contact support

Part 3 — People you may know (also the whole Find friends page)

7. Suggested people

Endpoint: GET {base_url}/feed/people/suggested?page=0&size=10

Access Level: 🔒 Protected · size 1–50. One list for both places: the feed card row asks for page 0 with a small size; Find friends pages through it. The backend ranks, filters and words everything; show it as it comes.

{
  "items": [
    { "accountId": "…", "name": "Juma Mwalimu", "userName": "jumamw", "userProfileMedia": { … },
      "reasonKind": "CONTACTS", "reason": "In your contacts", "mutual": true, "action": "FOLLOW" },
    { "accountId": "…", "name": "Zawadi K", "userName": "zawadi", "userProfileMedia": { … },
      "reasonKind": "MUTUAL_FRIENDS", "reason": "3 mutual friends: Neema, Baraka and 1 other", "mutual": false, "action": "REQUEST" }
  ],
  "page": 0, "size": 10, "hasNext": true, "contactsToFollow": 12
}
Field Meaning
reason the line under the name, always shown
action the button: FOLLOW, or REQUEST for a private account (Follow sends a request)
contactsToFollow how many "In your contacts" people are not followed yet: show Follow all (12) when > 0
reasonKind (strongest first) reason
CONTACTS "In your contacts" (mutual true when both saved each other's number)
REFERRAL "Invited you to NexGate" / "Joined with your code"
MUTUAL_FRIENDS "1 mutual friend: Neema" / "3 mutual friends: Neema, Baraka and 1 other"
FOLLOWS_YOU "Follows you"
FOLLOWED_BY "Followed by Juma" / "Followed by Juma and 2 others"
GROUPS "In a group with you" / "In 2 groups with you"
SUGGESTED "Suggested for you" (the AI service)

How it ranks: every input adds points, so someone who is in your contacts and has mutual friends comes first. A mutual friend with a small circle counts much more than one with thousands of friends. Friends = follow each other, both saved each other's number, or an accepted message request. Never used: your friends' saved numbers, "they have your number" alone, purchases, location. Never shown: people you follow or asked to follow, blocked either way, dismissed. The list is worked out once a day and again after a contact sync, a follow or an accepted request.

8. Follow all

POST {base_url}/feed/people/suggested/follow-all (no body) → { "followed": 9, "requested": 3 }. Follows the "In your contacts" people from the backend's own list (at most 200); private accounts get a follow request; the usual follow notifications go out. Other suggestions are followed one by one.

8b. Dismiss

POST {base_url}/feed/people/suggested/{accountId}/dismiss → never suggested again. Calling twice is safe.


Part 4 — Chat

  • "Contacts" in chat = follow each other OR both saved each other's number (both with sync on and "find me" on, no block). It decides the chat contact list / presence and the group setting "Only my contacts can add me".
  • New chat: GET /chat/contacts gives the list ready to show (Contacts on NexGate, You follow each other, Accepted messages): see message_requests_api_doc.md.
  • Becoming mutual contacts adds the person to the chat contact list; deleting the number, turning sync off or "find me" off removes them (unless they follow each other). Takes effect a moment after the call.
  • Blocking wins over everything.
  • Message requests for everyone who isn't a chat contact, and private calls only between chat contacts: message_requests_api_doc.md.
  • Names in the chat list: the name saved on the phone, with the NexGate name small underneath when they differ ("Juma Mwalimu · ~Rehema Said"), worked out on the phone.

Part 5 — Admin

Base: {base_url}/admin/contacts. Who: staff + super admin. No endpoint shows anyone's contacts.

9. Stopped accounts

GET /admin/contacts/stopped

[ { "accountId": "…", "name": "Boot Harvester", "userName": "bootharvest1", "reason": "Numbers in sequence", "stoppedAt": "2026-11-21T09:12:00" } ]

Stopped when one upload holds 20+ numbers in sequence, or the daily limit was hit 5 times in 7 days. Stopping turns sync off and deletes the uploaded list.

10. Lift a stop

POST /admin/contacts/stopped/{accountId}/lift with { "reason": "Checked: a school contact list" } (required; audited as CONTACTS_STOP_LIFTED). The person can sync again from scratch.


Part 6 — Notifications

Type To When Text Opens
CONTACT_JOINED everyone who saved the new person's number (sync on, alerts on) 1 hour after sign-up; once per pair ever; max 3 a day, the rest in one notice at 19:00 👋 Juma Mwalimu joined NexGate · Say hi or follow them — grouped: "Juma Mwalimu and 4 other contacts joined NexGate" the person's profile (actorId); grouped (no actorId) → Find friends. Buttons: Follow, Say hi 👋 (opens a chat and sends a wave)
ADMIN_CONTACT_ABUSE staff + super admins 08:00, when anyone was stopped in the last day Contact sync stopped for 2 accounts · 1 for numbers in sequence, 1 for hitting the daily limit again and again admin stopped list

data.actor carries the person's own id, name, userName and userProfileMedia: show those, never the name saved on the phone (recycled numbers). Someone who joined through Asha's referral link gives Asha only REFERRAL_FRIEND_JOINED. No "you may know" pushes. CHAT_MESSAGE_REQUEST: see the message requests doc.


Part 7 — Refusal codes (409)

Code When
CONTACTS_DAILY_LIMIT more than 300 new numbers today: send the rest tomorrow
CONTACTS_SYNC_OFF changes sent before a first sync (or after sync was turned off)
CONTACTS_STOPPED sync stopped for unusual uploads: "contact support"

Part 8 — App notes and screens checklist

  • Permission text (Apple / Google, owner to confirm before launch): "NexGate uses your contacts' phone numbers to show which friends are on NexGate. Names never leave your phone. We never message your contacts."
  • Normalise every number to +<country><number> (Tanzania default for local numbers); drop duplicates.
  • After the first sync, keep a local copy of what was sent and send only changes (endpoint 2), e.g. when the app opens.
  • Never log numbers in the app's crash or analytics tools either.
Screen Calls
End of sign-up "Find your friends" [Allow contacts] [Skip] permission → 1
Feed / chat card "👥 Find friends from your contacts" [Allow] [Not now] permission → 1; "Not now" hides 30 days, twice = never (app side)
Find friends 7 paged (+ saved names from the phone for CONTACTS people); Follow all → 8 when contactsToFollow > 0; [Invite] opens WhatsApp / SMS with the referral link (GET /referrals/me)
Settings → Privacy → Contacts 5 / 6; Delete uploaded contacts → 4
New chat GET /chat/contacts
Feed card row "People you may know" 7 (page 0, small size), ✕ → 8b
Profile "In your contacts as Juma Mwalimu" phone only, never sent
Admin → Contacts 9, 10