Friends API
Overview
The Friends Service provides an HTTP API to manage user relationships of different types, and manage user
presence.
We currently support the following types of Relationships:
- FRIEND_REQUEST - an incoming or outgoing friend request.
- FRIEND - an active friendship between two users that has been mutually accepted.
- BLOCK - a one-way relationship that allows a user to block a different user in order to avoid game experiences with them.
Friends makes it quick and easy to create and update relationships and provides the tools needed to
efficiently integrate standard Friends functionality into your game. The Presence features provide your players
with the ability to advertise their current status in the game to other players, and support for custom presence
metadata allows games to easily support features like join-in-progress or spectating.
Built-in support for push notifications allows players to easily manage their friends lists and be quickly notified
when the presence of any user changes.
Download OpenAPI specification:
Retrieve a list of relationships.
Retrieves a list of all relationships a given user is involved in. Relationships of all types are returned in
a single array. It's up to the caller to use the of the relationship object to determine the appropriate
way to handle that relationship. For relationship types that allow it, additional presence and profile data
will be provided for each member of the relationship (unless excluded using the and
parameters).
typewithPresencewithProfileBy default, we limit the number of relationships that can be returned in a single request. You can make
subsequent requests to this API using the parameter to paginate through the remaining relationships.
offsetAuthorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X GET \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://social.services.api.unity.com/v1/relationships"
Response example
[ { "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": null, "type": "FRIEND", "members": [ { "id": "ce7a03c4-78a3-4b93-ab8a-ef066f5388bf" } ] }, { "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": null, "type": "FRIEND", "members": [ { "id": "89e04c88-7c08-4a46-abe9-5b2089083c5c" } ] }, { "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": "2021-12-07T20:34:58Z", "type": "FRIEND_REQUEST", "members": [ { "id": "ebe7db33-ee81-4b5a-b5e1-24fdad5bae72", "role": "TARGET" } ] }, { "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": "2021-12-07T20:34:58Z", "type": "FRIEND_REQUEST", "members": [ { "id": "ebe7db33-ee81-4b5a-b5e1-24fdad5bae73", "role": "SOURCE" } ] }, { "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": null, "type": "BLOCK", "members": [ { "id": "ebe7db33-ee81-4b5a-b5e1-24fdad5bae75" } ] }]
Create a new relationship.
Creates a relationship with one or more members. A relationship has a and a list of who are
the users involved in the relationship. The requirements for creating a relationship are different depending on
the of the relationship.
typememberstypeEach member of the relationship can also be given an optional which may indicate some semantic of the
the relationship. A member can be identified by their user id or profile name.
roleFor most relationships, if the caller is a user and is not included in the list, that user's membership
is inferred to exist using the appropriate role. For example, if you create a relationship
with one member, the caller is inferred to be the source of the relationship.
membersFRIEND_REQUESTRelationship Types
FRIEND_REQUEST
Relationship
FRIEND_REQUESTA relationship indicates that a user would like to create a friendship with another user. If
no relationship (i.e. friendship) exists between the two users then the receiving game client will be
notified that a relationship has been created, and the game can choose to notify the user and
provide a mechanism for them to accept the friend request. A friend request is accepted by creating a
reciprocal relationship targeting the originating user.
FRIEND_REQUESTFRIENDFRIEND_REQUESTFRIEND_REQUESTA relationship can ONLY have two members. The members have a role of either or
to indicate the sender and the receiver of the request. If not provided the caller of the API will be
inferred to be the and the other member will be the . A user cannot create a relationship with
themselves as the .
FRIEND_REQUESTSOURCETARGETSOURCETARGETTARGETFRIEND
Relationship
FRIENDA relationship cannot be directly created by a user, but is implicitly created when both users have
created relationships with each other (i.e. sent and accepted a friend request).
FRIENDFRIEND_REQUESTA relationship is not directed, so the of the relationships do not have an assigned .
FRIENDmembersroleBLOCK Relationship
A relationship is a one-way relationship that enables a user to indicate that another user should be prevented
from interacting with themselves for certain features and functionality (e.g. hiding presence, preventing the
user from sending messages to them, etc.).
BLOCKPresence blocking will be handled by the service to ensure that blocked users are unable to view the presence
details of the blocker. For other functionality it is up to the developer to consume the relationships
data and provide additional functionality. For example, a game client could filter out lobbies created by users
that have been blocked, or a game server could prevent a blocked user from joining a game instance.
BLOCKAuthorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "type": "FRIEND", "members": [ { "profileName": "string", "id": "string", "role": "TARGET" } ]}' \ "https://social.services.api.unity.com/v1/relationships"
Response example
{ "id": "<relationship_id>", "created": "2021-11-17T20:34:58Z", "expires": "2021-12-07T20:34:58Z", "type": "FRIEND_REQUEST", "members": [ { "id": "s89e04c88-7c08-4a46-abe9-5b2089083c5c", "profile": { "name": "ColorfulFlickeringHat#9" }, "role": "TARGET" } ]}
Delete a relationship.
Deletes a relationship with the given .
relationshipIdAuthorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X DELETE \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://social.services.api.unity.com/v1/relationships/{relationshipId}"
Response example
{ "type": "http://unity.com/relationships/invalid_relationship", "code": 24002, "requestID": "12345", "status": 400, "title": "Bad Request", "detail": "invalid relationship id"}
Send a message to a user.
Allows a user to send a message with a custom payload to another user. The Friends Service will only
allow a user to send a message to a user that they have an active FRIEND relationship with.
The content of the payload can be customized entirely by the client. It is up to the client to determine how to
best handle the message payload. For example, if the message payload contains a lobby ID, the client could show
an Accept Invite toast. If the message contains a trade request, the client could enter a trading interface.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "id": "string", "message": {}}' \ "https://social.services.api.unity.com/v1/message"
Response example
{ "type": "http://unity.com/relationships/invalid_relationship", "code": 24002, "requestID": "12345", "status": 400, "title": "Bad Request", "detail": "invalid relationship id"}
Get notification auth details.
Retrieves both a subscription token and a channel name that the user should use to subscribe to notifications.
The Friends Service updates the notifications channel as changes to the user's
relationships occur. This includes updates to the presence state of any friends, new friend requests (i.e.
relationships created), etc.
FRIEND_REQUESTIn general, the client should not depend on repeatedly polling the entire list of relationships to monitor for
changes, but should instead fetch the entire list once and then register for notifications of any updates. This
allows the client to keep the list up to date while minimizing overhead.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Set presence for a user.
Updates the presence data for a user. This can be either or both of the availability and the activity.
Updates to the presence for a user will be pushed to all users with active FRIEND relationships with that user.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "availability": "ONLINE", "activity": {}}' \ "https://social.services.api.unity.com/v1/presence"
Response example
{ "availability": "ONLINE", "activity": { "location": "In Menu" }}