Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

psn-api

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

psn-api

A low-level API for getting data from the PlayStation Network.

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
441
increased by54.2%
Maintainers
1
Weekly downloads
 
Created
Source

PSN API

A low-level API for getting data from the PlayStation Network.

Styled with Prettier Semantic Release

PSN API is a reference implementation of a community effort to document Sony's APIs for PlayStation authorization and trophy metadata. It saves you the hassle of implementing this community reference yourself by offering a strongly-typed, well-tested, and lightweight package.


Features

✅  Modular by design, and supports tree-shaking.
✅  Aligns with the community PSN API documentation.
✅  Supports Node environments (14 and above).
✅  Supports browsers.
✅  Ships with TypeScript support and types.
✅  Tiny, <2Kb.


Getting started

Install

npm install --save psn-api

OR

yarn add psn-api

Usage with Node

Node 14 and above are officially supported. The package can be imported via:

const psn = require("psn-api");

Usage with TypeScript

You can use import syntax to utilize the package in your app. This library provides its own type definitions. "It just works", no need to install anything from @types.

import { getTrophiesEarnedForTitle } from "psn-api";

Understanding the Promise-based API

All methods in the API are async and return a native Promise.

These methods can be used with the native Promise API or the more modern async/await syntax.

// Native Promise API.
exchangeCodeForAccessToken("myCode").then((accessTokenResponse) => {
  console.log({ accessTokenResponse });
});

// async/await syntax.
const accessTokenResponse = await exchangeCodeForAccessToken("myCode");
console.log({ accessTokenResponse });

How to obtain an authentication token

To use any endpoint function in the API, you must first be authorized by PSN. Fortunately, this is a fairly straightforward process.

  1. In your web browser, visit https://my.playstation.com/ and log in with a PSN account.

  2. In the same browser (due to a persisted cookie), visit https://ca.account.sony.com/api/v1/ssocookie. You will see a JSON response that looks something like:

{"npsso":"Hwl9Vq..."}

Copy your NPSSO. Do not expose it anywhere publicly, it is equivalent to your password.

  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 = "Hwl9Vq...";

// 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 should now be all set to use any endpoint provided by this package. Each function requires as its first argument an object containing your access token. ex:
const authorization = await exchangeCodeForAccessToken(accessCode);

// This returns a list of all the games you've earned trophies for.
const trophyTitlesResponse = await getTrophyTitlesForUser(
  { accessToken: authorization.accessToken },
  "me"
);

API

Click the function names for complete docs.

Authentication

Trophies

Examples

Contributors


Wes Copeland

💻 💡 📖

xelnia

🤔 📓

andshrew

📖

FAQs

Package last updated on 14 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc