> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Link PSN Id

> Links the PlayStation™ Network account associated with the provided user id to the user's PlayFab account

## Error codes

This operation may return the following PlayFab errors:

| Error | Code |
| --- | --- |
| AccountAlreadyLinked | 1011 |
| AccountNotFound | 1001 |
| InvalidNamespaceMismatch | 1561 |
| InvalidPSNAuthCode | 1092 |
| InvalidPSNIssuerId | 1151 |
| LinkedAccountAlreadyClaimed | 1012 |
| PSNInaccessible | 1152 |




## OpenAPI

````yaml /services/playfab/api-references/rest/server/server.openapi.json post /Server/LinkPSNId
openapi: 3.0.0
info:
  version: '260922'
  title: PlayFab Server API
  description: >-
    Provides functionality to allow external (developer-controlled) servers to
    interact with user inventories and data in a trusted manner, and to handle
    matchmaking and client connection orchestration
  termsOfService: https://playfab.com/terms/
  contact:
    url: https://community.playfab.com/index.html
  license:
    name: Apache 2.0
    url: https://github.com/PlayFab/API_Specs/blob/master/LICENSE
servers:
  - url: https://{titleId}.playfabapi.com
    description: PlayFab title endpoint
    variables:
      titleId:
        default: your_title_id
        description: Your PlayFab title ID (hex).
security: []
tags:
  - name: Account Management
    description: Account Management APIs
  - name: Analytics
    description: Analytics APIs
  - name: Authentication
    description: Authentication APIs
  - name: Character Data
    description: Character Data APIs
  - name: Characters
    description: Characters APIs
  - name: Content
    description: Content Service APIs
  - name: Friend List Management
    description: Friend List Management APIs
  - name: Matchmaking
    description: Matchmaking APIs
  - name: Platform Specific Methods
    description: Platform Specific Methods APIs
  - name: Player Data Management
    description: Player Data Management APIs
  - name: Player Item Management
    description: Player Item Management APIs
  - name: PlayStream
    description: PlayStream Management APIs
  - name: Server-Side Cloud Script
    description: Server-Side Cloud Script APIs
  - name: Shared Group Data
    description: Shared Group Data APIs
  - name: Title-Wide Data Management
    description: Title-Wide Data Management APIs
paths:
  /Server/LinkPSNId:
    post:
      tags:
        - Account Management
      summary: Link PSN Id
      description: >
        Links the PlayStation™ Network account associated with the provided user
        id to the user's PlayFab account


        ## Error codes


        This operation may return the following PlayFab errors:


        | Error | Code |

        | --- | --- |

        | AccountAlreadyLinked | 1011 |

        | AccountNotFound | 1001 |

        | InvalidNamespaceMismatch | 1561 |

        | InvalidPSNAuthCode | 1092 |

        | InvalidPSNIssuerId | 1151 |

        | LinkedAccountAlreadyClaimed | 1012 |

        | PSNInaccessible | 1152 |
      operationId: LinkPSNId
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LinkPSNIdRequest'
      responses:
        '200':
          $ref: '#/components/responses/LinkPSNIdResponse'
        '400':
          $ref: '#/components/responses/ApiErrorWrapper'
      security:
        - SecretKey: []
components:
  schemas:
    LinkPSNIdRequest:
      type: object
      properties:
        CustomTags:
          description: >-
            The optional custom tags associated with the request (e.g. build
            number, external trace identifiers, etc.).
          type: object
        ForceLink:
          description: >-
            If another user is already linked to the account, unlink the other
            user and re-link.
          type: boolean
        IssuerId:
          description: >-
            Id of the PlayStation™ Network issuer environment. If null, defaults
            to the production environment. This must match the issuer the
            account signs in under, otherwise the link will not be resolved by
            that sign in.
          type: number
          x-actualtype: int32
        PlayFabId:
          description: >-
            Unique PlayFab assigned ID of the user on whom the operation will be
            performed.
          type: string
        PSNUserId:
          description: >-
            Id of the PlayStation™ Network user. Also known as the PSN Account
            Id.
          type: string
        SandboxId:
          description: >-
            The PlayStation™ Network sandbox to key the link under. Sandbox
            membership is per account, not per title: supply this only when the
            account signs in from a sandbox, and omit it otherwise, including
            for all retail accounts. This must match the sandbox the account
            signs in from, otherwise the link will not be resolved by that sign
            in.
          type: string
      required:
        - PlayFabId
        - PSNUserId
      example:
        PlayFabId: 1234FA342
        PSNUserId: LKJDG7DDE
    LinkPSNIdResponse:
      type: object
      properties: {}
    ApiErrorWrapper:
      description: The basic wrapper around every failed API response
      type: object
      properties:
        code:
          description: Numerical HTTP code
          type: integer
        status:
          description: String HTTP code
          type: string
        error:
          description: Playfab error code
          type: string
        errorCode:
          description: Numerical PlayFab error code
          type: integer
        errorMessage:
          description: Description for the PlayFab errorCode
          type: string
        errorDetails:
          description: Detailed description of individual issues with the request object
          type: object
      required:
        - code
        - errorCode
  responses:
    LinkPSNIdResponse:
      description: ''
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: integer
                description: >-
                  The Http status code. If X-ReportErrorAsSuccess header is set
                  to true, this will report the actual http error code.
              status:
                type: string
                description: The Http status code as a string.
              data:
                $ref: '#/components/schemas/LinkPSNIdResponse'
    ApiErrorWrapper:
      description: This is the outer wrapper for all responses with errors
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorWrapper'
  securitySchemes:
    SecretKey:
      type: apiKey
      in: header
      name: X-SecretKey
      description: >-
        This API requires a title secret key, available to title admins, from
        PlayFab Game Manager.

````

## Related topics

- [Link PSN Id](/services/playfab/api-references/rest/server/account-management/link-psn-id.md)
- [Link PSN Account](/api-reference/account-management/link-psn-account.md)
- [PFAccountManagementServerLinkPSNIdAsync](/services/playfab/api-references/c/pfaccountmanagement/functions/pfaccountmanagementserverlinkpsnidasync.md)
- [PFAccountManagementLinkPSNIdRequest](/services/playfab/api-references/c/pfaccountmanagementtypes/structs/pfaccountmanagementlinkpsnidrequest.md)
- [Link Xbox Id](/services/playfab/api-references/rest/server/account-management/link-xbox-id.md)
