PlayStation-Trophies icon indicating copy to clipboard operation
PlayStation-Trophies copied to clipboard

player's accountId

Open rafaelfgyn opened this issue 2 years ago • 9 comments

hey andshrew,

congratulations for this amazing project.

I wonder if you know some route in the playstation api to get player's accountId of any player non related to the npsso key. For example, to get accountId of all player's friends.

rafaelfgyn avatar Mar 15 '22 15:03 rafaelfgyn

Hi @rafaelfgyn

Thanks for your comment. I know of the following endpoints you can use. You should be able to authenticate to these in the same way which is mentioned here.


https://m.np.playstation.net/api/userProfile/v1/internal/users/me/friends

This returns a list of the accountIds on the friends list of the account you used to authenticate with. You can also swap me for another accountId and you will get their friends list back (assuming the authenticating account has permission to view the other accounts friends list).


https://m.np.playstation.net/api/userProfile/v1/internal/users/{accountId}/profiles

This returns the basic profile details for an account so you can discover the onlineId (their PSN name) from an accountId.


https://m.np.playstation.net/api/userProfile/v1/internal/users/me/friends/{accountId}/summary

This gives you a relationship summary between the accountId and the authenticating account (are they a friend, a close friend, how many mutual friends you have etc).


It would be nice if there was a way to get the accountId and onlineId in a single request but I've not come across such an endpoint for doing that.

andshrew avatar Mar 16 '22 11:03 andshrew

man, thank you so much for all the hard work that you put in discovering some much about Sony's API. I'm about to launch a webpage so players can see their accounts, all thanks to your work, I have been work on this for about 2 years lol, so thank you again. That been said, I have to ask: How did you manage to discover so much about Sony' API? How did you find the endpoints, etc... I would like to help investigating the API, I believe there're more useful endpoints to be found.

rafaelfgyn avatar Jun 17 '22 00:06 rafaelfgyn

Hi @rafaelfgyn

You're welcome, I'm glad it's been a useful resource for developing your web site.

Regarding discovery, as Sony have reduced the amount of services which are available via a regular web browser the majority of the current APIs come from inspecting the mobile PS App. You could discover a lot just by inspecting the files within the app package. They were originally visible in the plain text Javascript file (or at least visible enough that you could work out what they would be). You can still do this, but current versions of the app have these files compiled into Hermes bytecode so you have to disassemble it with a tool like https://github.com/bongtrop/hbctool.

The other way is capturing and inspecting the traffic that the app is generating as you use it but that's not straight forward now due to the lengths developers go to try prevent this (eg. SSL certificate pinning), although it is still possible.

andshrew avatar Jun 20 '22 22:06 andshrew

I did manage to get the endpoints via regular web browser, after the launch of ps5 with the new api, they ended the old api and I lost all my job, it was a sad day to me (lol), now that everything turns around the mobile app, I'm lost. I know too little about mobile =/. I've tried to use some app the inspects the traffic but with no success.

rafaelfgyn avatar Jun 20 '22 23:06 rafaelfgyn

Hey man, do we have any endpoints to get the Id of a specific user?

rafaelfgyn avatar Jun 26 '22 09:06 rafaelfgyn

Hi @rafaelfgyn

The closest thing I'm aware of which can effectively do a username to id lookup is their search API (so whether someone appears in this is going to depend on their privacy settings relative to the account you are using to perform the request).

The endpoint URL is: https://m.np.playstation.com/api/search/v1/universalSearch

You need to POST an application/json request with the following content:

{
  "searchTerm": "rafaelfgyn",
  "domainRequests": [
    {
      "domain": "SocialAllAccounts",
      "socialSearchParams": {
        "strictGrouping": true
      },
      "pagination": {
        "cursor": "",
        "pageSize": 20
      },
      "featureFlags": {
        "isSpartacusEnabled": true
      }
    }
  ],
  "countryCode": "gb",
  "languageCode": "en",
  "age": 99
}

You'll get a response like:

{
  "domainResponses": [
    {
      "domain": "SocialAllAccounts",
      "domainTitle": "Results for SocialAllAccounts with search term \"rafaelfgyn\"",
      "domainTitleMessageId": "msgid_null",
      "domainTitleHighlight": [
        "Results for SocialAllAccounts with search term \"",
        "rafaelfgyn",
        "\""
      ],
      "zeroState": false,
      "next": "",
      "totalResultCount": 1,
      "results": [
        {
          "id": "id",
          "type": "social",
          "score": 236.3765,
          "socialMetadata": {
            "accountId": "1234567890",
            "country": "BR",
            "language": "pt",
            "onlineId": "rafaelfgyn",
            "isPsPlus": false,
            "isOfficiallyVerified": false,
            "avatarUrl": "http://static-resource.np.community.playstation.net/avatar/3RD/UP00011308076_37E14E48D0E885B75F69_L.png",
            "verifiedUserName": "",
            "highlights": {
              "onlineId": [
                "",
                "rafaelfgyn"
              ]
            }
          }
        }
      ]
    }
  ],
  "fallbackQueried": false
}

You can use the same method of authentication as all of the trophy endpoints.

andshrew avatar Jul 04 '22 19:07 andshrew

Hi @Sakreetos

You need to authenticate the request for it to work - see obtaining an authentication token from the documentation here for an example of how you can do that. Continuing the example using Powershell 7 after you've got your $token you would then run the following:

$body = '{
  "searchTerm": "rafaelfgyn",
  "domainRequests": [
    {
      "domain": "SocialAllAccounts",
      "socialSearchParams": {
        "strictGrouping": true
      },
      "pagination": {
        "cursor": "",
        "pageSize": 20
      },
      "featureFlags": {
        "isSpartacusEnabled": true
      }
    }
  ],
  "countryCode": "gb",
  "languageCode": "en",
  "age": 99
}'

Invoke-RestMethod -ContentType "application/json" -body $body -Uri "https://m.np.playstation.com/api/search/v1/universalSearch" -Method Post -Authentication Bearer -Token $token

andshrew avatar Jul 05 '22 09:07 andshrew

Yeah, already figured that out. Thank you)

Sakreetos avatar Jul 05 '22 09:07 Sakreetos

Man, thanks again for that. this endpoint is extremely useful. If you have any endpoints still to share please don't hesitate, or just update your documentation. If there's anything I can do to help just reach me out.

Changing of topic... did you see this? https://blog.playstation.com/2022/07/14/introducing-playstation-stars-an-all-new-loyalty-program/

rafaelfgyn avatar Jul 14 '22 13:07 rafaelfgyn