lads_add_segment_users
LinkedIn Ads write high risk
Part of the LinkedIn Audience Agent.
What it does
Add hashed user identifiers to a USER-type DMP segment (contact/retargeting list upload) via streaming. POST /rest/dmpSegments/{id}/users with the HEADER X-RestLi-Method: BATCH_CREATE and body {elements:[{action:'ADD', userIds:[{idType, idValue}], firstName?, lastName?, ...}]}. Each element MUST carry action:'ADD'. Up to 5000 users per batch request. idType is restricted to SHA256_EMAIL (email lowercased, whitespace-stripped, then SHA-256 HEX, max 64 chars), SHA512_EMAIL, or GOOGLE_AID — any other value (e.g. 'GOOGLE') is rejected before sending. Each element must supply at least one valid userId OR both firstName and lastName. Preview->approve->execute->log: show the user the segment, record count, and that data is consented PII; on approval, batch-upload. The identifiers must arrive hashed: Scalix never hashes, and refuses a plain email address at preview. Returns a per-element batch response array (201 success / 400 with batchIndex on failure) — surface partial failures, never assume all-or-nothing. Membership is additive; uploaded count != matched count, and the segment must reach >=300 MATCHED members to serve. /users is rate-limited to 600 requests/member/minute. Batch cap: at most 5,000 rows per call (rejected pre-API above that). LinkedIn returns PER-ELEMENT statuses — a success envelope does not mean every row landed; failed rows are surfaced as warnings referencing their batchIndex. Without rw_dmp_segments, which Scalix requests only once LinkedIn approves its Audiences program (SCALIX_LINKEDIN_EXTRA_SCOPES), the call is refused at preview (access_gated), after the arguments are checked. Two-phase (parity with Google, ADR-028/029): the first call (no preview_id) reads the segment from LinkedIn (a missing segment, one in an ad account the user has not enabled, or a COMPANY segment is refused), builds the request locally and returns a preview_id — nothing is changed on LinkedIn; re-call with that preview_id and identical arguments to COMMIT (single-use, 30-min; a changed/forged/replayed token fails closed).
When to use it
Use to populate a freshly created USER segment with a consented, pre-hashed contact list so it can serve. Push the user to confirm consent and review the record count, then upload. Do NOT upload lists without consent, with plaintext emails, with idType outside {SHA256_EMAIL, SHA512_EMAIL, GOOGLE_AID}, or into a COMPANY-type segment.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
segment_id | string | yes | Numeric DMP segment id, or its urn:li:dmpSegment URN (read as the id). At preview the segment is read: it must be a USER segment in an ad account the user has enabled. |
users | array | yes | List of users (max 5000 per batch). Each user is a hashed id of id_type, an {idType, idValue}, or {userIds: [{idType, idValue}, ...], firstName?, lastName?, title?, company?, country?}, and becomes ONE element (action ADD) carrying that user's ids. Normalize emails (lowercase+trim) BEFORE SHA-256/SHA-512 HEX; never send plaintext email. At preview Scalix refuses, naming users[i] but never the value: a plain email address anywhere, a SHA256_EMAIL that is not 64 hex characters (SHA512_EMAIL: 128), an idType outside SHA256_EMAIL|SHA512_EMAIL|GOOGLE_AID, a user with no id and not both firstName and lastName, a name over 35 characters, a title over 100, a company over 50, or a country that is not a two-letter code. GOOGLE_AID values are lower-cased, as LinkedIn requires. |
id_type | enum(SHA256_EMAIL|SHA512_EMAIL|GOOGLE_AID) | no | Default identifier type when not per-user. Restricted to SHA256_EMAIL | SHA512_EMAIL | GOOGLE_AID; any other value is rejected with a validation error before sending. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Only upload identifiers the client has documented consent/lawful basis to use; emails MUST be lowercased+trimmed then SHA-256 (or SHA-512) HEX-hashed before transmission; treat as sensitive PII; honor retention limits and never commingle across accounts. Wait ~5s after segment creation before adding users.
Reminder
Hash and consent every identifier; never log raw PII or pool uploaded lists across clients; member-derived data purged per policy and the segment serves only at >=300 matches.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
PARTIAL_FAILURE | Some batch elements failed (per-element 400 with batchIndex) while others succeeded (201). | Return per-row results; report which batchIndex values failed and why; retry only failed rows after fixing. | no |
INVALID_ARGUMENT | Bad payload (e.g. unhashed email, idType outside {SHA256_EMAIL, SHA512_EMAIL, GOOGLE_AID}, missing action:'ADD', element lacking both a userId and firstName+lastName, >5000 users, or segment not type USER) — surface LinkedIn message. | Normalize+hash identifiers, restrict idType to the allowed enum, ensure each element has action:'ADD' and a valid id or firstName+lastName, chunk to <=5000, or target a USER segment; do not retry blindly. | no |
PERMISSION_DENIED | No write access to the account or missing rw_dmp_segments (403). | Verify role/scope; re-auth if scope missing (needs_reauth). | no |
RESOURCE_EXHAUSTED | Exceeded 600 req/member/min or daily quota (429). | Backoff 5/10/20s cap 60s; chunk the upload and throttle; alert at 75% quota. | yes |
TOKEN_REVOKED | Token expired/revoked (401). | Refresh and retry once; else re-auth. | yes |
NOT_FOUND | Segment id not found (404). | Confirm numeric id and that the segment exists. | no |
Edge cases
- Segment created <5s ago may reject users -> wait and retry once.
- Each element must carry action:'ADD' and at least one valid userId OR both firstName and lastName, else the element is rejected.
- idType outside {SHA256_EMAIL, SHA512_EMAIL, GOOGLE_AID} (e.g. 'GOOGLE') -> reject locally with a clear validation error before sending.
- Match rate is partial: uploaded count != matched count; segment won't serve below 300 MATCHES — warn explicitly.
- Lists >5000 must be chunked into multiple BATCH_CREATE calls and throttled under the 600/min limit.
- Plaintext email passed -> reject before sending (must SHA-256/SHA-512 HEX of lowercased/trimmed email).
- COMPANY-type segment -> users endpoint is wrong; route to lads_create_company_list.
- Idempotency: re-adding the same hashed id is a no-op match; safe to retry only the failed rows.