Skip to main content

Get Started

You can use any of the functions as demonstrated in this documentation. Please refer to each function's docs page to see how they should be used.

psn-api functions work in isolation. They are tree-shakeable, and will only pull in the code they need to execute.

Quick Start

Install the package:

# with npm
npm install --save psn-api

# with yarn
yarn add psn-api

You will need to be authorized to use the PSN API. To authenticate manually, follow these steps:

  1. In your web browser, visit the PlayStation homepage, click the "Sign In" button, and log in with a PSN account.

  2. In the same browser (due to a persisted cookie), visit this page. You will see a JSON response that looks something like:

{ "npsso": "<64 character token>" }
  1. You can now obtain an authentication token using your NPSSO with the following function calls from this package.
// This is the value you copied from the previous step.
const myNpsso = "<64 character token>";

// We'll exchange your NPSSO for a special access code.
const accessCode = await exchangeNpssoForCode(npsso);

// ๐Ÿš€ We can use the access code to get your access token and refresh token.
const authorization = await exchangeCodeForAccessToken(accessCode);
  1. You now have all you need to use any function in the API. Each function takes this authorization object as its first argument. To be more precise, the functions are looking for your accessToken value. Here's an example:
// This returns a list of all the games you've earned trophies for.
const trophyTitlesResponse = await getUserTitles(
{ accessToken: authorization.accessToken },
"me"
);