← All posts
Guide

X Username to User ID: Resolve a DM Recipient Safely

To resolve an X username for a UnifyPort message, use Get contact with the username without @ as contact_id. For X, the returned provider_user_id and conversation_id both contain the numeric user ID as a string. Use the returned provider_user_id when addressing a user. A successful lookup confirms that the profile was retrieved—not that the account can receive your message.

The identifier map comes before the Send button

The Get contact reference defines X-specific lookup behavior. Do not apply a different channel’s contact rules or assume that a username is already a sending destination.

ValueMeaning in this X workflowHandling
contact_id in the lookupUsername without @Query the intended profile through the selected messaging account
Returned idX username for this contactKeep as profile context, not a substitute for the numeric sending ID
Returned provider_user_idNumeric X user ID, represented as a stringUse for a single-user sending target
Returned conversation_idThe same numeric user ID in this X contact responseDo not mistake it for proof of an existing two-person conversation
to.id in a send requestA single user ID or a conversation ID containing a colonSelect the documented form appropriate to your actual target

The Send text message reference supports either a colon-containing X conversation ID or a single user ID and explicitly directs callers to provider_user_id from Get contact for the latter. Do not concatenate two user IDs to manufacture a conversation ID. For an existing conversation, preserve the identifier returned by the relevant conversation workflow.

Key takeaways:

  • Keep numeric identifiers as strings throughout storage, UI state, and request construction.
  • Retain the sending account with the resolved recipient.
  • Make lookup read-only; it must not silently send a test message.
  • Keep profile retrieval, send acceptance, and recipient-side outcomes separate.

This is not the same operation as an address-book search. The WhatsApp and LINE contact-picker guide describes listing contacts with q; it does not establish X support for that listing workflow.

What a successful profile lookup cannot tell you

X’s About Chat documentation describes recipient conditions separately from profile identity. For example, an unencrypted message request may be possible when the recipient opts to receive Chat messages from anyone, or under the documented verified-user settings. Those conditions are not fields that UnifyPort’s contact response promises to evaluate.

X also says message requests remain separate from other Chat messages until accepted. A recipient can accept, ignore, or block the sender, and requests remain unencrypted until accepted. Do not describe a newly resolved username as an established encrypted conversation.

The separation is especially clear in X’s DM-blocking documentation: blocking direct messages can stop one-to-one messaging while leaving public interactions available. Seeing or retrieving a profile therefore cannot establish private-message access.

These are platform boundaries, not a reason to probe recipients with repeated sends. Respect recipient preferences and your own communication-consent requirements. UnifyPort’s unofficial interface does not grant additional permission to contact someone.

Design a recipient review, not an automatic outreach trigger

Consider a hypothetical support console where an operator enters a customer’s X username. A safer application workflow is:

  1. Select the sending account first. Check the operator’s access to that account on your backend. Keep the workspace API key out of the browser.
  2. Perform the lookup. Submit the username in the documented format. Keep a failed request distinct from a successful profile result; do not label every error “user does not exist.”
  3. Show the returned profile for review. Use the available display name and avatar as context alongside the username. A display name alone is not a unique selection.
  4. Freeze the selection. Retain the account and returned numeric user ID together. If the account or username changes, clear the selection and ignore responses from the previous lookup.
  5. Require a separate send decision. Review the intended message and communication context. Do not treat finding a profile as consent or a successful eligibility check.

These are application safeguards, not extra API fields or a documented permission-check endpoint. Avoid inventing a can_dm flag from a successful HTTP response. If your UI needs a label, “Profile found” accurately states the evidence; “Ready for guaranteed delivery” does not.

Keep later failures in the right investigation

A failed send after a successful lookup does not make the numeric ID invalid by definition. Recipient settings, account connectivity, and conversation-specific conditions are separate questions. Record the operation, HTTP status, error code, request identifier when available, and the selected account in a restricted diagnostic record. Exclude session material and message content unless genuinely needed and appropriately protected.

If the symptom concerns encrypted-chat keys or signatures, use the X Chat troubleshooting guide. Repeating profile resolution does not repair a missing conversation key. Conversely, a generic send failure does not prove a cryptographic fault.

The send reference describes accepted as queued for delivery to the provider. It is not proof that a message request was accepted by the recipient or that the message appeared in their inbox. After a timeout, preserve an unknown outcome and reconcile available evidence before another deliberate send; do not automatically resend to test whether lookup was correct.

FAQ

Can I put an X username directly in to.id?

For this documented UnifyPort workflow, resolve the username first and use the returned provider_user_id for a user target. Do not substitute the lookup username for the numeric ID.

Why is conversation_id just one numeric ID?

The X contact contract explicitly returns the numeric user ID in both provider_user_id and conversation_id. That contact result does not prove a pre-existing conversation or authorize construction of a colon-separated ID.

Does HTTP success mean the recipient allows DMs?

No. Profile lookup proves profile retrieval. Sending eligibility, provider acceptance, and recipient acceptance are different observations.

Should I convert the returned ID to a number?

No. Preserve the returned string unchanged. No arithmetic is needed to route a message.

Next step and sources

Start with a read-only Get contact lookup. Confirm the account and returned recipient before adding a separate send action.

Sources checked on 2026-12-02:

UnifyPort API

Turn messaging integration into a stable product pipeline.

Start by sending through one API, then bring every inbound message back into your business system with standard events.