{"revision":"25c04798c52757c2","language":"en","entry":{"id":"discord-roles-complete","kind":"endpoint","group":"manage","title":"Finish a linked roles connection","method":"POST","path":"/v1/discord/linked-roles/{state}/complete","paths":[],"summary":"Signed by the key that started, with the return code. The server trades Discord's code, checks that the Discord account is a verified account of the card, keeps the tokens encrypted and sends the facts.","response":"The connection, with what Discord now shows.","parameters":[{"name":"state","in":"path","required":true,"description":"The state start returned."},{"name":"returnCode","in":"body","required":true,"description":"The 32 hex characters the callback page got."}],"sample":"/v1/discord/linked-roles/0000000000000000000000000000000000000000000000000000000000000000/complete","access":"signed","base":"directory","notes":[],"errors":["400 invalid_nonce","400 invalid_parameter","400 invalid_signature_alg","400 invalid_timestamp","401 invalid_signature","401 missing_signature","401 stale_timestamp","403 key_banned","403 key_mismatch","403 veil_suspended","404 linked_roles_off","404 not_found","409 discord_account_alert","409 discord_not_linked","409 not_in_good_standing","409 not_returned","409 replayed_nonce","410 erased","410 session_expired","422 discord_refused","422 not_for_organizations","422 scope_missing","422 wrong_return_code","429 rate_limited","429 too_many_attempts","500 internal_error","503 busy","503 discord_unavailable"],"related":["discord-app"],"sections":[{"kind":"code","language":"shell","code":"curl -fsS -X POST \\\n  -H \"X-Public-Key: $PUBLIC_KEY\" -H \"X-Signature: $REQUEST_SIGNATURE\" \\\n  --json @request.json \"https://veil.pub/v1/discord/linked-roles/{state}/complete\""}],"live":false,"responses":[{"status":200,"contentType":"application/json","description":"The connection, with what Discord now shows.","fields":[{"name":"discord","type":"object","description":"{id, username}: the Discord account."},{"name":"state","type":"string","description":"active or retired."},{"name":"connectedAt","type":"string","description":"When it was connected."},{"name":"lastPushAt","type":"string | null","description":"When Discord last accepted the facts."},{"name":"lastCheckedAt","type":"string | null","description":"When the facts were last worked out."},{"name":"nextPushAt","type":"string | null","description":"When the next push is due (null once retired)."},{"name":"shown","type":"object | null","description":"{platform_name, platform_username, metadata}: what Discord holds."},{"name":"widget","type":"boolean","description":"The grant carries the profile widget."},{"name":"widgetPushedAt","type":"string | null","description":"When the widget's data last reached Discord."},{"name":"retiredAt","type":"string | null","description":"When it ended."},{"name":"reason","type":"string | null","description":"Why it ended: discord_refused, removed_on_discord, discord_not_linked, suspended, unreachable, token_unreadable."}]}],"responseObjects":[],"errorFormat":"json","errorDetails":[{"status":400,"code":"invalid_nonce","description":"The signed-request nonce has an invalid format.","action":"Generate a fresh 16 to 128-character nonce using letters, digits, _ or -.","scope":"common"},{"status":400,"code":"invalid_parameter","description":"A parameter is missing or malformed.","action":"Send n as the card's number, or returnCode as the 32 hex characters the page got.","scope":"endpoint"},{"status":400,"code":"invalid_signature_alg","description":"`X-Signature-Alg` is unsupported.","action":"Use a supported signing algorithm and matching key/signature encoding.","scope":"common"},{"status":400,"code":"invalid_timestamp","description":"The signed-request timestamp is not Unix milliseconds.","action":"Use an integer Unix timestamp in milliseconds and sign the corrected request.","scope":"common"},{"status":401,"code":"invalid_signature","description":"The HTTP request signature does not verify.","action":"Sign the exact method, path and body bytes, without changing them afterwards.","scope":"common"},{"status":401,"code":"missing_signature","description":"The request requires a device signature and its headers are missing or unreadable.","action":"Send `X-Public-Key`, `X-Signature` and the signed-request metadata. An API key does not replace a device signature.","scope":"common"},{"status":401,"code":"stale_timestamp","description":"The signed timestamp is outside the accepted clock window.","action":"Compare the server Date header with your clock, then generate a fresh nonce, timestamp and signature.","scope":"common"},{"status":403,"code":"key_banned","description":"The device signing key is suspended by Veil staff.","action":"Use an authorised active key or ask staff to review the restriction.","scope":"common"},{"status":403,"code":"key_mismatch","description":"The key is not an active device key of the card, or not the key that started this connection.","action":"Sign with the device key of the browser that started.","scope":"endpoint"},{"status":403,"code":"veil_suspended","description":"The Veil staff suspended the card.","action":"A suspended card gives no roles until the suspension ends.","scope":"endpoint"},{"status":404,"code":"linked_roles_off","description":"This server does not offer Discord linked roles.","action":"Ask the server's operator, or check GET /v1/discord/linked-roles.","scope":"endpoint"},{"status":404,"code":"not_found","description":"No such card or connection, or the connection is over.","action":"Start again from /discord/linked-roles.","scope":"endpoint"},{"status":409,"code":"discord_account_alert","description":"The card declared this Discord account stolen, moved or no longer used, and has not declared it regained. On complete, the grant was revoked.","action":"Declare the account regained on the card, then connect.","scope":"endpoint"},{"status":409,"code":"discord_not_linked","description":"The Discord account that authorised is not a verified account of the card. Its grant was revoked; error.discord.username names it.","action":"Sign in to Discord with the account on the card, or link that account to the card first.","scope":"endpoint"},{"status":409,"code":"not_in_good_standing","description":"The card is closing, has a takeover open or its name is hidden.","action":"Settle that first, then connect.","scope":"endpoint"},{"status":409,"code":"not_returned","description":"Discord has not sent the browser back yet.","action":"Finish on Discord first.","scope":"endpoint"},{"status":409,"code":"replayed_nonce","description":"The signing key already used this nonce.","action":"Check whether the previous request succeeded before making a fresh signed request.","scope":"common"},{"status":410,"code":"erased","description":"The card was closed.","action":"A closed card has no connections.","scope":"endpoint"},{"status":410,"code":"session_expired","description":"The connection took more than 10 minutes.","action":"Start again.","scope":"endpoint"},{"status":422,"code":"discord_refused","description":"Discord answered invalid_grant for the code: used, expired or not for this app. The message is fixed and repeats nothing Discord said.","action":"Start again.","scope":"endpoint"},{"status":422,"code":"not_for_organizations","description":"Linked roles are for a person's card.","action":"Use a person's card.","scope":"endpoint"},{"status":422,"code":"scope_missing","description":"Discord did not grant role_connections.write.","action":"Start again and allow the connection.","scope":"endpoint"},{"status":422,"code":"wrong_return_code","description":"The return code is not this connection's.","action":"Send the code the page got back, from the browser that started.","scope":"endpoint"},{"status":429,"code":"rate_limited","description":"An anonymous, signed-request or API-key allowance was exceeded.","action":"Wait at least `Retry-After` seconds. Share a queue and retry budget across your workers.","scope":"common"},{"status":429,"code":"too_many_attempts","description":"Too many wrong return codes.","action":"Start again.","scope":"endpoint"},{"status":500,"code":"internal_error","description":"An unexpected server error occurred. Internal details are not returned.","action":"Retry reads with bounded backoff. Check write results before sending a new signed operation.","scope":"common"},{"status":503,"code":"busy","description":"The application has reached a temporary concurrency or database limit.","action":"Wait `Retry-After` seconds and retry with bounded backoff.","scope":"common"},{"status":503,"code":"discord_unavailable","description":"Discord did not answer, answered something unexpected or refused the app itself. A grant already received was revoked.","action":"Try again in a few minutes.","scope":"endpoint"}],"responseHeaders":[{"name":"Content-Type","value":"application/json","description":"JSON, also for errors."},{"name":"Cache-Control","value":"no-store","description":"Private: never cached."}],"documentationUrl":"https://veil.pub/docs/discord-roles-complete","supportsBrowserFetch":false,"browserMode":"local-or-server"}}