Profile operations

Fetch profile and update data from the Fans United Football API

Profile operations are responsible for communicating with the Profile API.
Each method that works with statistical data also converts your IDs to the desired ID provider for easier and quicker development.

The namespace is of course called profile. All methods return promises. The general design of the namespace follows this pattern:

sdk.profile.someMethod(filtersObject).then((responseObject) => {
    // do something with responseObject
});

The responses are comprised of different objects you can find here.

Profile related operations

Profile related operations are always prefixed by one of two methods: getOwn() or getById(). These fetch the user object you will be working with.
Depending on the object you are allowed to perform different actions. For instance, you can perform unsafe operations (ex. update) only on the user's own profile.
This means that addInterest(), removeInterest() and so on can only follow the getOwn() method.

Keep in mind that all responses following getById() are cached for an hour by the API. The responses following getOwn(), while not cached by the API are saved locally inside the SDK (local storage) and updated every 10 minutes.

Get user info

Method: getInfo()

The user info is returned by the getInfo() method. It can be used only after getOwn() or getById(). Note that profile response model does not have interests property.

// Getting the user's own profile
sdk.profile.getOwn().getInfo().then((responseObject) => {
     // do something with responseObject
});

// Getting other user's profile
sdk.profile.getById('user-id').getInfo().then((responseObject) => {
     // do something with responseObject
});

Example result

{
   id: "GSGUDDW5xVNSo7I0ujVbsNBoeMz2",
   name: "Dobromir Penchev",
   avatar: "https://lh3.googleusercontent.com/a/AATXAJyQ_WJv90jkuSov4LI3arP-LSkmYcY6fk5Nb6DW=s96-c",
   gender: "male",
   country: {
      id: "profile:cnt:113",
      name: "Italy",
      assets: {
          "flag": "https://profile.fansunitedassets.com/country/3a92fd87-8e19-11eb-b60d-42010a84003b.png"
      }
   },
   birthDate: "1991-03-24"
}

Get users by user IDs

Method: getByIds(["user-id"]?, "Marco Prandi"?, disableCache?)

This method allows developers to fetch multiple user profiles at once.

You can fetch multiple profiles by ids OR by search field. Search field will search for exact match in name or nickname of the profile.

N.B. Developers can't use both of the params profileIds and search or neither of them. Atleast one of them is required.

If no value is passed to disableCache (undefined) it will be set to false.

// Getting profiles by IDS
sdk.profile.getByIds(['GSGUDDW5xVNSo7I0ujVbsNBoeMz2', 'user-id-2']).then((responseObject) => {
     // do something with responseObject
});

// Getting profiles by search
sdk.profile.getByIds(null, "Marco Prandi").then((responseObject) => {
     // do something with responseObject
});

Example result

[
   {
      id: "GSGUDDW5xVNSo7I0ujVbsNBoeMz2",
      name: "Marco Prandi",
      avatar: "https://lh3.googleusercontent.com/a/AATXAJyQ_WJv90jkuSov4LI3arP-LSkmYcY6fk5Nb6DW=s96-c",
      gender: "male",
      country: {
         id: "profile:cnt:113",
         name: "Italy",
         assets: {
            flag: "https://profile.fansunitedassets.com/country/3a92fd87-8e19-11eb-b60d-42010a84003b.png"
         }
      },
      birthDate: "1991-03-24",
      interests: [
         {
            id: "89",
            source: "football",
            type: "team",
            favourite: true
         },
         {
            id: "3400",
            source: "football",
            type: "player",
            favourite: false
         }
      ]
   },
   {
      id: "user-id-2",
      name: "user-name",
      avatar: "https://lh3.googleusercontent.com/a/AATXAJyQ_WJv90jkuSov4LI3arP-LSkmYcY6fk5Nb6DW=s96-c",
      gender: "unspecified",
      country: {
         id: "profile:cnt:113",
         name: "Italy",
         assets: {
            flag: "https://profile.fansunitedassets.com/country/3a92fd87-8e19-11eb-b60d-42010a84003b.png"
         }
      },
      birthDate: "1993-11-03",
      interests: [
         {
            id: "81",
            source: "football",
            type: "team",
            favourite: true
         },
         {
            id: "3",
            source: "football",
            type: "competition",
            favourite: true
         }
      ]
   }
]

Set birthdate, gender, country, nickname, avatar and name

Method: setBirthdate(""), setGender(""), setCountry(""), setNickname(""), setAvatar("") & setName("")

Updating the user's profile happens with a few different methods, depending on what you want to update. Each of those methods
must follow only the getOwn() method. At the end, the developer needs to call the update() method to commit the changes.

sdk.profile.getOwn()
.setBirthdate("1991-03-24") // Format "YYYY-MM-DD"
.setGender("male") // Options are: "male", "female", "unspecified"
.setCountry("profile:cnt:113") // Valid country ID from the Profile API
.setName("Lorem Ipsum")
.setNickname("lorem")
.setAvatar("https://lh3.googleusercontent.com/a/AATXAJw8D1_r67sJppc8Je2TJ0EeeH40vcjMBTPe6NYH=s96-c") // Only valid URLs are acceptable
.update();

The update() method returns a promise. Developers can chain then() method after it and inject their custom callback logic.
Resolved promise returns same model as getInfo() method.

Show profile fullness

Method: showFullnessProfile()

This method returns the fullness of the profile in percent and details how many percent each action is rewarded with.

sdk.profile.getOwn().showFullnessProfile().then((responseObject) => {
    // do something with responseObject
});
sdk.profile.getById("user-id").showFullnessProfile().then((responseObject) => {
    // do something with responseObject
});

Example result

{
   breakdown: {
      teamFollowed: {
         completed: true,
         percentage: 10
      },
      teamFavourite: {
         completed: true,
         percentage: 15
      },
      playerFollowed: {
         completed: true,
         percentage: 10
      },
      playerFavourite: {
         completed: true,
         percentage: 10
      },
      competitionFollowed: {
         completed: true,
         percentage: 10
      },
      competitionFavourite: {
         completed: false,
         percentage: 5
      },
      addedBirthdate: {
         completed: false,
         percentage: 10
      },
      addedGender: {
         completed: true,
         percentage: 10
      },
      addedCountry: {
         completed: false,
         percentage: 10
      },
      addedAvatar: {
         completed: true,
         percentage: 10
      }
   },
   totalPercentage: 75
}

Interests related operations

Interests, like profile related operations, work with the object provided by the getOwn() and getById() methods.

Show interests

Method: showInterests()

Raw interests data is available via the showInterests() method. Keep in mind that each interest id should match id schema provided in JavaScript SDK's configuration.

// Getting the user's own interests
sdk.profile.getOwn().showInterests().then((responseObject) => {
     // do something with responseObject
});

// Getting other user's interests
sdk.profile.getById('user-id').showInterests().then((responseObject) => {
     // do something with responseObject
});

Example result

[
   {
      id: "102", // id is matching sportal365 id schema
      source: "football",
      type: "team",
      favourite: false
   },
   {
      id: "3400", // id is matching sportal365 id schema
      source: "football",
      type: "player",
      favourite: false
   }
]

Show full interests

Method: showFullInterests()

In case you want to get all the entities data related to the interests, you can use showFullInterests(). This will return not only the IDs, but the model as well (names, photos, country, etc.). In addition it will convert any ID to the desired provider.

// Getting the user's own interests, but with all the entities attached
sdk.profile.getOwn().showFullInterests().then((responseObject) => {
     // do something with responseObject
});

// Getting other user's interests, but with all the entities attached
sdk.profile.getById('user-id').showFullInterests().then((responseObject) => {
     // do something with responseObject
});

Example result

[
   {
      id: "102",
      source: "football",
      type: "team",
      favourite: false,
      model: {
         id: "102",
         country: {
            id: "15",
            alias: null,
            countryCode: "ENG",
            assets: {
               flag: "https://football.fansunitedassets.com/country/3a930dd8-8e19-11eb-b60d-42010a84003b.png"
            },
            name: "England"
         },
         gender: "male",
         assets: {
            logo: "https://football.fansunitedassets.com/team/41fba11d-8c4e-11eb-aff3-42010a8400d1.png"
         },
         name: "Manchester United",
         code: "MNU",
         national: false,
         fullName: null,
         shortName: null
      }
   },
   {
      id: "3400",
      source: "football",
      type: "player",
      favourite: false,
      model: {
         id: "3400",
         country: {
            id: "31",
            alias: null,
            countryCode: "PRT",
            assets: {
               flag: "https://football.fansunitedassets.com/country/3a92ec60-8e19-11eb-b60d-42010a84003b.png"
            },
            name: "Portugal"
         },
         birthDate: "1985-02-05",
         firstName: "Cristiano Ronaldo",
         lastName: "dos Santos Aveiro",
         name: "Cristiano Ronaldo",
         position: "forward",
         assets: {
            headshot: "https://football.fansunitedassets.com/player/41ff1b20-8c4e-11eb-aff3-42010a8400d1.jpeg"
         },
         teams: [
            {
               id: "102",
               country: {
                  id: "15",
                  alias: null,
                  countryCode: "ENG",
                  assets: {
                     flag: "https://football.fansunitedassets.com/country/3a930dd8-8e19-11eb-b60d-42010a84003b.png"
                  },
                  name: "England"
               },
               gender: "male",
               assets: {
                  logo: "https://football.fansunitedassets.com/team/41fba11d-8c4e-11eb-aff3-42010a8400d1.png"
               },
               name: "Manchester United",
               code: "MNU",
               national: false,
               fullName: null,
               shortName: null
            },
            {
               id: "1651",
               country: {
                  id: "31",
                  alias: null,
                  countryCode: "PRT",
                  assets: {
                     flag: "https://football.fansunitedassets.com/country/3a92ec60-8e19-11eb-b60d-42010a84003b.png"
                  },
                  name: "Portugal"
               },
               gender: "male",
               assets: {
                  logo: "https://football.fansunitedassets.com/team/4217ec5f-8c4e-11eb-aff3-42010a8400d1.png"
               },
               name: "Portugal",
               code: "POR",
               national: true,
               fullName: null,
               shortName: null
            }
         ]
      }
   }
]

Add interest

Method: addInterest({})

Users can add interests only to their own profiles. This happens with the addInterest() method which follows getOwn().
The addInterest() method can be chained allowing developers to send multiple interests at the same time.

Just like the update of the profile, the developer needs to finally call the update() method.

Accepts object with the following options:

  • source: string. Options are:

    • FOOTBALL
    • CRICKET
    • FIELD_HOCKEY
    • TENNIS
    • VOLLEYBALL,
    • TABLE_TENNIS
    • BASKETBALL,
    • BASEBALL
    • RUGBY
    • GOLF
    • ATHLETICS
    • FORMULA_1
    • BOXING
    • ICE_HOCKEY
    • AMERICAN_FOOTBALL
    • MMA
    • MOTOGP
    • BADMINTON
    • CYCLING
    • SNOOKER
    • GYMNASTICS
    • HANDBALL
    • WRESTLING
    • HORSE_RACING
    • WEIGHT_LIFTING
    • CHESS
    • SQUASH
    • BIATHLON
    • WINTER_SPORTS
    • MARTIAL_ARTS
    • WATER_SPORTS,
    • SHOOTING, RALLY
    • RHYTHMIC_GYMNASTICS
  • type: string. Options are "team", "player", "competition" and "sport"

  • id: string. The unique ID of the resource

  • favourite: boolean. Determines whether the interest is a favourite or not

// User adding interests to their profile
sdk.profile.getOwn()
.addInterest({
    source: "football",
    type: "team",
    id: "102",
    favourite: false
})
.addInterest({
    source: "football",
    type: "player",
    id: "3400",
    favourite: false
})
.update();

The update() method returns a promise. Developers can chain then() method after it and inject their custom callback logic.
Resolved promise returns same model as getInfo() method.

Remove interest

Method: removeInterest({})

Users can remove interests from their own profiles. This happens with the removeInterest() method which follows getOwn().
The removeInterest() method can be chained allowing developers to remove multiple interests at the same time.

Just like the update of the profile, the developer needs to finally call the update() method.

Accepts object with the following options:

  • source: string. Options
  • type: string. Options are "team", "player", "competition" and "sport"
  • id: string. The unique ID of the resource
  • favourite: Optional boolean. Determines whether the interest is a favourite or not.
// User adding interests to their profile
sdk.profile.getOwn()
.removeInterest({
    source: "football",
    type: "team",
    id: "102",
    favourite: false
})
.removeInterest({
    source: "football",
    type: "player",
    id: "3400",
    favourite: false
})
.update();

The update() method returns a promise. Developers can chain then() method after it and inject their custom callback logic.
Resolved promise returns same model as getInfo() method.

Follower related operations

Get followers & following

Method: getFollowers({}) & getFollowing({})

These methods allow the developers to fetch the lists of followers and following users for one's own or a specified profile.

These methods support pagination. The developer can specified how many users to be fetched, as well as specify after which User ID to start.

Available options:

  • limit: integer. Determines how many items should be returned. Default: 20, Max: 50
  • startAfter: string. The ID of the user after which the count will start
// Getting 10 of the user's own followers, starting after user with ID "c9KSw6UscWe9iNWCvcb12blNShi2"
sdk.profile.getOwn().getFollowers({
    limit: 10,
    startAfter: "c9KSw6UscWe9iNWCvcb12blNShi2"
}).then((responseObject) => {
     // do something with responseObject
});

// Getting the users followed by the currently logged user
sdk.profile.getOwn().getFollowing().then((responseObject) => {
     // do something with responseObject
});

// Getting a specified user's followers
sdk.profile.getById('user-id').getFollowers({
    limit: 10,
    startAfter: "c9KSw6UscWe9iNWCvcb12blNShi2"
}).then((responseObject) => {
     // do something with responseObject
});

// Getting a list of users followed by a specified user
sdk.profile.getById('user-id').getFollowing().then((responseObject) => {
     // do something with responseObject
});

Example result

// response from getFollowers() method call
{
   meta: {
      pagination: {
         nextPageStartsAfter: "c9KSw6UscWe9iNWCvcb12blNShi2",
         itemsPerPage: 10
      }
   },
   data: [
      {
         avatar: "https://lh3.googleusercontent.com/a-/AOh14Gisnho2CGFkqq99Gp-TbX5CL3Ws2RYW2PcXyq0J1w=s96-c",
         followerId: "ygLWDk3V7kYeC7drW9bzD6dMkWZ2",
         name: "Viktor Yordanov",
         nickname: "BukTop4o",
         profileId: "IP7jJ2aRrrexiAQp9TNT8uWzFDj2"
      }
   ]
}

// response from getFollowing() method call
{
   meta: {
      pagination: {
         nextPageStartsAfter: "ygLWDk3V7kYeC7drW9bzD6dMkWZ2",
         itemsPerPage: 20
      }
   },
   data: [
      {
         avatar: "https://lh3.googleusercontent.com/a-/AOh14Gisnho2CGFkqq99Gp-TbX5CL3Ws2RYW2PcXyq0J1w=s96-c",
         followingId: "ygLWDk3V7kYeC7drW9bzD6dMkWZ2",
         name: "Viktor Yordanov",
         nickname: "BukTop4o",
         profileId: "IP7jJ2aRrrexiAQp9TNT8uWzFDj2"
      }
   ]
}

Follow user

Method: follow(["user-id"])

This method allows users to follow other users. In the request the users that are being followed are listed as an array of user IDs.
In the response we return user objects of the followed users.

NB: If you send a request to follow a user that is already being followed, that user will not be returned in the response (it will return an empty array []).

sdk.profile.getOwn().follow(["2Blge85wjjecpG3bMEMjzieLgTz1", "YP3SKSzPRlVOBNtv4xssnCnGUQP2"])
	.then(() => {
  // Handle response
	})

Example result

[
   {
      avatar: "https://lh3.googleusercontent.com/a/AATXAJzz0ZipT7BfcJIIPUtUjrSEHS-yF3F7av4Daj7c=s96-c",
      followingId: "YP3SKSzPRlVOBNtv4xssnCnGUQP2",
      name: "Borislav Gizdov",
      nickname: "Rider",
      profileId: "GSGUDDW5xVNSo7I0ujVbsNBoeMz2"
   },
   {
      avatar: "https://lh3.googleusercontent.com/a-/AOh14GhKfHbOhgk2i0ZFaqh8Y0e1xazfFzTFHWQ56c1D=s96-c",
      followingId: "2Blge85wjjecpG3bMEMjzieLgTz1",
      name: "Zlatin Zlatev",
      nickname: "Shhh",
      profileId: "GSGUDDW5xVNSo7I0ujVbsNBoeMz2"
   }
]

Unfollow user

Method: unfollow(["user-id"])

By passing an array of user IDs, the user can unfollow a list of users at once. On success, we will return "true" in the promise.

sdk.profile.getOwn().unfollow(["2Blge85wjjecpG3bMEMjzieLgTz1", "YP3SKSzPRlVOBNtv4xssnCnGUQP2"])
.then((responseBoolean) => {
   // Handle boolean
});

Points, tiers and badges opeartions

Get profile stats

Method: getStats()

Returns points, tiers, badges, predictions and success rates statistics for own or specified profile.

N.B. To be able to see single predictions breakdown, you need to configure the competitions and teams for it. You can do it in our Management Portal Features- > Loyalty -> Badges

// Get own profile points and tier
sdk.profile.getOwn().getStats()
  .then((responseObject: ProfileStatsModel) => {
   // Handle response
	})
	.catch((error: any) => {
});

// Get specified profile points and tier
sdk.profile.getById("tyuaMEKdleSzyPniKcXdoM0mviK2").getStats()
  .then((responseObject: ProfileStatsModel) => {
   // Handle response
	})
	.catch((error: any) => {
});

Example result

{
   profileId: "tyuaMEKdleSzyPniKcXdoM0mviK2",
   tier: "bronze",
   predictionsMade: 373,
   points: 2350,
   successRates: {
      overallPercent: 34,
      byCompetition: {
          "fb:c:3": {
              successRatePercent: 25,
              model: CompetitionBasicModel
          }
      },
      byTeam: {
          "fb:t:8102": {
              successRatePercent: 22,
              model: TeamBasicModel
          }
      },
      byMarket: {
          FT_1X2: {
              successRatePercent: 50
          }
      }
   },
   predictions: {
      single: {
         predictionsMade: 310,
         correct: 200,
         points: 266,
         breakdown: {
            footballCompetitions: [
                {
                  entityId: "1",
                  entityType: "competition",
                  entitySource: "football-api",
                  model: CompetitionBasicModel,
                  predictionsMade: 200,
                  correct: 123,
                  points: 4565,
                }
            ],
            footballTeams: [
                {
                  entityId: "89",
                  entityType: "team",
                  entitySource: "football-api",
                  model: TeamBasicModel,
                  predictionsMade: 200,
                  correct: 123,
                  points: 4565,
                }
          ]
         }
      },
      topX: {
         participations: 23,
         points: 1260
      },
      matchQuiz: {
         participations: 40,
         points: 824
      }
   },
   tiers: [
      {
         id: "bronze",
         achievedAt: "2023-09-25T06:28:56Z"
      }
   ],
   badges: [
      {
         id: "matchquiz_newbie",
         achievedAt: "2023-09-25T06:28:56Z"
      },
      {
         id: "topx_newbie",
         achievedAt: "2023-09-25T06:28:56Z"
      },
      {
         id: "predictor_newbie",
         achievedAt: "2023-09-25T06:28:56Z"
      }
   ]
}

Get profile badges

Method: getBadges()

Returns list of aquired badges for own or specified profile.

// Get own profile badges
sdk.profile.getOwn().getBadges().then((responseArray) => {
   // Handle response
});

// Get specified profile badges
sdk.profile.getById("tyuaMEKdleSzyPniKcXdoM0mviK2").getBadges().then((responseArray) => {
   // Handle response
});

Example result

["predictor_top", "topx_regular", "matchquiz_regular"]

Other operations

Get countries

Method: getCountries(disableCache?)

This method fetches countries. Unlike the "football countries", these are the actual political entities. Countries like "England" and "Scotland" are missing and replaced by "Great Britain".
If no value is passed to disableCache (undefined) it will be set to false.

sdk.profile.getCountries().then((responseObject) => {
    // do something with responseObject
});

Example result

[
   {
      id: "profile:cnt:1",
      name: "Aruba",
      assets: {
         flag: "https://profile.fansunitedassets.com/country/3a937cca-8e19-11eb-b60d-42010a84003b.png"
      }
   },
   {
      id: "profile:cnt:10",
      name: "Armenia",
      assets: {
         flag: "https://profile.fansunitedassets.com/country/3a934d22-8e19-11eb-b60d-42010a84003b.png"
      }
   },
   {
      id: "profile:cnt:100",
      name: "Honduras",
      assets: {
         flag: "https://profile.fansunitedassets.com/country/3a93178e-8e19-11eb-b60d-42010a84003b.png"
      }
   }
]