Challenges operations
Get the configuration for all platform interactions
Challenges operations are responsible for communicating with Private Leagues API.
The namespace is of course called challenges. All methods return promises. The general design of the namespace follows this pattern unless stated otherwise:
General call:
sdk.challenges .someMethod() .then((response) => { // Handle response }) .catch((error) => { // Handle error });
The responses are comprised of different objects you can find here.
Challenges manage operations
Issue a challenge
Method: issue(body, userId)
Method creates a challenge and invites a user to it. User can configure the following options:
- name:
string
. The name of the challenge. (required) - description:
string
. The description of the challenge. (required) - invitationCode:
string
. Invitation code where can be use from other users to join the challenge. (required) - templateId:
string
. The template which will be used for scoring stats in the challenge. For example if the template is set for Premier League (England) only successful predictions for Premier League matches will be counted in the challenge(required) - usersCanInviteUsers:
boolean
. Users can invite other users or only the administrator (the creator of the challenge) can do that. (required) - administrators:
string[]
. Will be there other administrators aswell with the creator of the challenge. (optional) - scoringStartsAt:
string
. The date from when the challenge will be scoring points. If not provided it will be set the current date. The format is (YYYY-MM-DD). Example value: 2023-12-12 (optional)
Example call:
const body = { name: "TEST", description: "TEST", invitationCode: "c1l3tqf", templateId: "7W8JCLPCg8f0nm9YfwZShf", usersCanInviteUsers: false, }; sdk.challenges .issue(body, "PGdBkHS4cXeiFWhDBTnbx885gZ32") .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "TEST",
description: "TEST",
type: "ONE_VS_ONE",
members: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2"
],
invitationCode: "c1l3tqf",
templateId: "7W8JCLPCg8f0nm9YfwZShf",
templateModel: TemplateModel,
pastTemplates: null, // PastTemplateModel[]
usersCanInviteUsers: false,
scoringStartsAt: "2023-11-29",
pinnedPosts: null
}
Update challenge
Method: update(challengeId, body)
Method updated the specified challenge. The following options are available for update:
- name:
string
. The name of the challenge. (required) - description:
string
. The description of the challenge. (required) - invitationCode:
string
. Invitation code where can be use from other users to join the challenge. (required) - templateId:
string
. The template which will be used for scoring stats in the challenge. For example if the template is set for Premier League (England) only successful predictions for Premier League matches will be counted in the challenge(required) - usersCanInviteUsers:
boolean
. Users can invite other users or only the administrator (the creator of the challenge) can do that. (required) - administrators:
string[]
. Will be there other administrators aswell with the creator of the challenge. (required) - pinnedPosts:
string[]
. Post ids who are pinned for the challenge. Pinned posts can be maximum 3. (required) - scoringStartsAt:
string
. The date from when the challenge will be scoring points. If not provided it will be set the current date. The format is (YYYY-MM-DD). Example value: 2023-12-12 (required)
Example call:
const body = { name: "UPDATE", description: "UPDATE", invitationCode: "c1l3tqf", templateId: "1zUfS8hzE75MYaR29HRKyr", usersCanInviteUsers: false, administrators: ["Y44CxUzkpHdypYxcVVlwIQiLNtD2", "PGdBkHS4cXeiFWhDBTnbx885gZ32"], pinnedPosts: [], scoringStartsAt: "2023-11-29", }; sdk.challenges .update("4GJmMesXndaf3o5ijcpHIY", body) .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "UPDATE",
description: "UPDATE",
type: "ONE_VS_ONE",
members: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
invitationCode: "c1l3tqf",
templateId: "1zUfS8hzE75MYaR29HRKyr",
templateModel: TemplateModel,
pastTemplates: [
{
id: "1zUfS8hzE75MYaR29HRKyr",
name: "old template name",
model: TemplateModel
}
],
usersCanInviteUsers: true,
scoringStartsAt: "2023-11-29",
pinnedPosts: []
}
Delete challenge
Method: delete(challengeId)
Method deletes the specified challenge.
Example call:
sdk.challenges .delete("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
true
Update challenge's template
Method: updateTemplate(challengeId, newTemplateId, oldTemplateName)
Method updates the specified challenge's template.
N.B. If new template ID exisits in past templates it will be removed from past templates.
N.B.2 Challenge admin can't set same past template names for different past templates.
Example call:
const newTemplateId = "7W8JCLPCg8f0nm9YfwZShf"; const oldTemplateName = "old template name"; sdk.challenges .updateTemplate("4GJmMesXndaf3o5ijcpHIY", newTemplateId, oldTemplateName) .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "UPDATE",
description: "UPDATE",
type: "ONE_VS_ONE",
members: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
invitationCode: "c1l3tqf",
templateId: "7W8JCLPCg8f0nm9YfwZShf",
templateModel: TemplateModel,
pastTemplates: [
{
id: "1zUfS8hzE75MYaR29HRKyr",
name: "old template name",
model: TemplateModel
}
],
usersCanInviteUsers: true,
scoringStartsAt: "2023-11-29",
pinnedPosts: []
}
Moderate post in a challenge
Method: moderatePost(postId, moderationReason)
Method moderates the post from Challenge's discussion with the specified moderation reason.
Example call:
sdk.challenges .moderatePost("postId", "SPAM") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
id: "postId",
userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
discussionId: "discussionId",
content: "Content is updated!",
repliesCount: 0,
replyId: "postId",
reactions: [],
reactionsCount: 0,
reports: [],
reportsCount: 0,
versions: [
{
content: "New awesome post!",
updateAt: "2023-12-11T11:58:47Z"
}
],
privatePost: false,
deleted: false,
deletedAt: null,
deletedBy: null,
moderated: true,
moderatedAt: "2023-12-11T11:58:47Z",
moderatedBy: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
moderatedReason: "SPAM",
createdAt: "2023-12-11T11:58:47Z",
updatedAt: "2023-12-11T12:58:47Z"
}
Challenges related operations
Get user's own challenges
Method: getMyChallenges(filters?)
Method returns all challenges (with no members) that the user is part of.
The following options are available for filters:
- userRole:
string
. What is the user's role - administrator or member
Example call:
sdk.challenges .getMyChallenges() .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
[
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "UPDATE",
description: "UPDATE",
type: "ONE_VS_ONE",
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
membersCount: 2,
invitationCode: "c1l3tqf",
templateId: "1zUfS8hzE75MYaR29HRKyr",
templateModel: TemplateModel,
pastTemplates: [
{
id: "1zUfS8hzE75MYaR29HRKyr",
name: "old template name",
model: TemplateModel
}
],
usersCanInviteUsers: true,
scoringStartsAt: "2023-11-29",
pinnedPosts: null
}
]
Get challenge by ID
Method: getById(challengeId, disableCache?)
Method returns challenge details info.
The response from API is cached for 1 hour. With disableCache
argument you can avoid cached response.
Example call:
sdk.challenges .getById("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Handle error });
Example result
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "UPDATE",
description: "UPDATE",
type: "ONE_VS_ONE",
members: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
membersCount: 2,
invitationCode: "c1l3tqf",
templateId: "1zUfS8hzE75MYaR29HRKyr",
templateModel: TemplateModel,
pastTemplates: [
{
id: "1zUfS8hzE75MYaR29HRKyr",
name: "old template name",
model: TemplateModel
}
],
usersCanInviteUsers: true,
scoringStartsAt: "2023-11-29",
pinnedPosts: null
}
Get user's challenges standings
Method: getMyChallengesStandings(filters?)
Method returns all challenges that user is member of and his results (points and position for each challenge) .
The following options are available for filters:
- limit:
number
. Determines how many items per page there will be. - page:
number
. The number of the page. - challengeId:
string
. Filter the response to see only the specified challenge. - templateId:
string
. Filter the response to see only the specified template. - sortOrder:
string
. Determines the sort order - asc or desc
Example call:
sdk.challenges .getMyChallengesStandings() .then((response) => { // Handle response }) .catch((error) => { // Throws error message }); const filters = { limit: 1, page: 2, challengeId: "4GJmMesXndaf3o5ijcpHIY", templateId: "1zUfS8hzE75MYaR29HRKyr", sortOrder: "desc" }; sdk.challenges .getMyChallengesStandings(filters) .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
meta: {
pagination: {
currentPage: 2,
itemsPerPage: 1,
numberOfPages: 3,
totalItems: 3
}
},
data: [
{
challengeId: "4GJmMesXndaf3o5ijcpHIY",
challengeModel: PrivateLeagueModel,
templateId: "1zUfS8hzE75MYaR29HRKyr",
templateModel: TemplateModel,
position: 1,
points: 100,
type: "challenge"
}
]
}
Get reported posts in a challenge
Method: getReportedPosts(challengeId, filters?)
Method returns all reported posts in the specified challenge.
The following options are available for filters:
- limit:
number
. Determines how many items per page there will be. - startAfter:
string
. The ID after which the posts should be listed. To be used in the context of infinite scroll/pagination. - reportsCount:
number
. Will return all posts who are reported with count greater of reportsCount filter param.
Example call:
sdk.challenges .getReportedPosts("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message }); const filters = { limit: 1, startAfter: "postId", reportsCount: 1, }; sdk.challenges .getReportedPosts("4GJmMesXndaf3o5ijcpHIY", 4GJmMesXndaf3o5ijcpHIY) .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
meta: {
pagination: {
totalItems: 1,
nextPageStartsAfter: "postId",
lastCommentCreateTimestamp: "2023-12-11T11:58:47Z"
}
},
data: [
{
id: "postId",
userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
discussionId: "4GJmMesXndaf3o5ijcpHIY",
content: "Content is updated!",
repliesCount: 0,
replyId: "postId",
reactions: [],
reactionsCount: 0,
reports: [
{
userId: "1",
reason: "SPAM",
reasonDetails: null
},
{
userId: "2",
reason: "AD",
reasonDetails: null
},
],
reportsCount: 2,
versions: [
{
content: "New awesome post!",
updateAt: "2023-12-11T11:58:47Z"
}
],
privatePost: false,
deleted: false,
deletedAt: null,
deletedBy: null,
moderated: true,
moderatedAt: "2023-12-11T11:58:47Z",
moderatedBy: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
moderatedReason: "SPAM",
createdAt: "2023-12-11T11:58:47Z",
updatedAt: "2023-12-11T12:58:47Z"
}
]
}
Get predictions for a challenge
Method: getPredictions(challengeId, filters?)
Method returns all user's own predictions for the specified challenge.
The following options are available for filters:
- limit:
number
. Determines how many items per page there will be.
N.B. The maximum limit is 20. - page:
number
. The number of the page. - profileIds:
string[]
. Will return all predictions for the specified profile ids.
Example call:
sdk.challenges .getPredictions("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message }); const filters = { limit: 1, page: 2, profileIds: ["Y44CxUzkpHdypYxcVVlwIQiLNtD2"], }; sdk.challenges .getPredictions("4GJmMesXndaf3o5ijcpHIY", filters) .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
meta: {
pagination: {
currentPage: 2,
itemsPerPage: 1,
numberOfPages: 3,
totalItems: 3
}
},
data: [
{
predictionId: "GSGUDDW5xVNSo7I0ujVbsNBoeMz2_p_OVER_GOALS_fb:m:806686519",
predictionModel: PredictionResponseModel,
profileId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
profileModel: ProfileModel,
}
]
}
Challenges membership operations
Accept an invitation to challenge
Method: accept(challengeId)
Method accepts the invitation to challenge.
Example call:
sdk.challenges .accept("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
profileId: "PGdBkHS4cXeiFWhDBTnbx885gZ32",
profileModel: ProfileModel,
leagueId: "4GJmMesXndaf3o5ijcpHIY",
leagueModel: PrivateLeagueModel,
message: "User joined challenge",
}
Reject an invitation to challenge
Method: reject(challengeId)
Method rejects an invitation to challenge.
Example call:
sdk.challenges .reject("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
profileId: "PGdBkHS4cXeiFWhDBTnbx885gZ32",
profileModel: ProfileModel,
leagueId: "4GJmMesXndaf3o5ijcpHIY",
leagueModel: null,
message: "User rejected to join challenge",
}
Leave challenge
Method: leave(challengeId)
Method leaves the challenge.
Example call:
sdk.challenges .leave("4GJmMesXndaf3o5ijcpHIY") .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
["PGdBkHS4cXeiFWhDBTnbx885gZ32"]
Get challenge invitations
Method: getInvitations(filters?)
Method returns all challenges that the user has been invited.
The following options are available for filters:
- limit:
number
. Determines how many items per page there will be. - startAfter:
string
. The ID after which the challenges should be listed. To be used in the context of infinite scroll/pagination
Example call:
sdk.challenges .getInvitations() .then((response) => { // Handle response }) .catch((error) => { // Throws error message }); const filters = { limit: 1, startAfter: "4GJmMesXndaf3o5ijcpHIY" }; sdk.challenges .getInvitations(filters) .then((response) => { // Handle response }) .catch((error) => { // Throws error message });
Example result
{
meta: {
pagination: {
itemsPerPage: 1,
nextPageStartsAfter: "4GJmMesXndaf3o5ijcpHIY",
}
},
data: [
{
id: "4GJmMesXndaf3o5ijcpHIY",
name: "UPDATE",
description: "UPDATE",
type: "ONE_VS_ONE",
members: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
banned: [],
invites: [],
administrators: [
"Y44CxUzkpHdypYxcVVlwIQiLNtD2",
"PGdBkHS4cXeiFWhDBTnbx885gZ32"
],
invitationCode: "c1l3tqf",
templateId: "1zUfS8hzE75MYaR29HRKyr",
templateModel: TemplateModel,
pastTemplates: [
{
id: "1zUfS8hzE75MYaR29HRKyr",
name: "old template name",
model: TemplateModel
}
],
usersCanInviteUsers: true,
scoringStartsAt: "2023-11-29",
pinnedPosts: null
}
]
}
Updated 6 months ago