# Generating codes for your program

Generate a creator code through the API before the creator has a Nexus account, for programs that issue codes from their own product.

This page covers generating codes automatically for your players, which the creator then claims to their own Nexus account. You can issue a code from inside your own product without requiring the creator to have a Nexus account first. Nexus cannot pay that creator until they register and link their account to the member you generated.

<Aside type="note">
Most programs do not generate codes automatically. Creators usually join on their own, through the onboarding landing page Nexus sets up for your program, where they submit an application or receive a creator code directly. If your program is invite-only, Nexus provides custom invite links they use to onboard themselves.

Your "Creator Invite Links" live in your [Publisher Dashboard settings](https://www.nexus.gg/publisher/dashboard/settings). From that dashboard you can also add existing Nexus accounts to your group by their Nexus storefront URL or Support-a-Creator code.
</Aside>

## Generating a code

POST to the `/manage/members` route with your internal id for a player (`playerId`).

<Aside type="note">
The `playerId` associated with a generated or linked Nexus is not displayed to the player.
</Aside>

If the `playerId` you send already belongs to a member, Nexus adds the generated code to that member's existing Nexus account. Their member information flags the code `isGenerated` but not `isManaged`, because it is already associated with a Nexus account.

If no member matches that `playerId`, Nexus creates a new Support-a-Creator Nexus that you manage and adds it to your program. Once you [link that `playerId` to an existing Nexus](#linking-to-an-existing-nexus), the Nexus user has claimed the generated code and you no longer manage it. You can also send players to Nexus with an auth code for a Support-a-Creator Nexus you manage, which prompts them to register and claim the generated code. See [Claiming a generated code](/creator-code-api/program-management/adding-codes-to-your-program/claiming-a-generated-code/) for more details.

The Nexus Creator Dashboard does not show the generated code to the Nexus user. You can disclose it to them yourself at your discretion.

<ApiMethod method="POST" path="/manage/members" />
<LinkCard title="View full reference" description="Parameters, responses, and status codes." href="/api/operations/generatemember/" />

```bash
curl -X 'POST' \
  'https://api.nexus.gg/v1/manage/members' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -H 'X-SHARED-SECRET: nexus_sk_your_key_here' \
  -d '{
    "playerId": "userUniqueIdentifier1",
    "playerMetadata": {
      "displayName": "Unique User 1"
    }
  }'
```

The status should be `200 OK` with a JSON response body that looks something like this:

```json
{
  "groupId": "CsRKC8uD0NLtyQ0LOt8Ru",
  "groupName": "Test Group",
  "playerId": "userUniqueIdentifier1",
  "playerMetadata": {
    "displayName": "Unique User 1"
  },
  "code": "abcd123"
}
```

## Linking to an existing Nexus

To link an existing Nexus account to your program, use an Authentication Code that the user generates in the [Nexus Dashboard](https://www.nexus.gg/dashboard/settings).

<ApiMethod method="POST" path="/manage/members/link" />
<LinkCard title="View full reference" description="Parameters, responses, and status codes." href="/api/operations/nexuslink/" />

```bash
curl -X 'POST' \
  'https://api.nexus.gg/v1/manage/members/link' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -H 'X-SHARED-SECRET: nexus_sk_your_key_here' \
  -d '{
  "playerId": "userUniqueIdentifier1",
  "playerMetadata": {
    "displayName": "Unique User 1"
  },
  "authCode": "035-536"
}'
```

The status should be `200 OK` with a JSON response body that looks something like this:

```json
{
  "groupId": "CsRKC8uD0NLtyQ0LOt8Ru",
  "groupName": "Test Group",
  "playerId": "userUniqueIdentifier1",
  "playerMetadata": {
    "displayName": "Unique User 1"
  },
  "codes": [
    {
      "code": "samzorz",
      "isPrimary": true,
      "isGenerated": false,
      "isManaged": false
    },
    {
      "code": "abcd123",
      "isPrimary": false,
      "isGenerated": true,
      "isManaged": false
    }
  ]
}
```

If you previously generated a code for this player, their code list includes it too. That code stays flagged `isGenerated`, but you no longer manage it.

After the link succeeds, you can retrieve this member's details for your group using that `playerId` as the reference.

<LinkCard title="Retrieving your members" description="Look up a member by their playerId, code, or member ID." href="/creator-code-api/program-management/retrieving-your-members/" />
