Private Leagues operations

Get the configuration for all platform interactions

Private Leagues operations are responsible for communicating with Private Leagues API.

The namespace is of course called privateLeagues. All methods return promises. The general design of the namespace follows this pattern unless stated otherwise:

πŸ“˜

General call:

sdk.privateLeagues
  .someMethod()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

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

Private Leagues manage operations

Create private league

Method: create(body)

Method creates a private league, where user can configure the following options:

  • name: string. The name of the league. (required)
  • description: string. The description of the league. (required)
  • invitationCode: string. Invitation code where can be use from other users to join the league. (required)
  • templateId: string. The template which will be used for scoring stats in the league. For example if the template is set for Premier League (England) only successful predictions for Premier League matches will be counted in the league(required)
  • usersCanInviteUsers: boolean. Users can invite other users or only the administrator (the creator of the league) can do that. (required)
  • administrators: string[]. Will be there other administrators aswell with the creator of the league. (optional)
  • scoringStartsAt: string. The date from when the league 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: true,
};

sdk.privateLeagues
  .create(body)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   id: "4GJmMesXndaf3o5ijcpHIY",
   name: "TEST",
   description: "TEST",
   type: "PRIVATE",
   members: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   banned: [],
   invites: [],
   administrators: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   invitationCode: "c1l3tqf",
   templateId: "7W8JCLPCg8f0nm9YfwZShf",
   templateModel: TemplateModel,
   pastTemplates: null, // PastTemplateModel[]
   usersCanInviteUsers: true,
   scoringStartsAt: "2023-11-29",
   pinnedPosts: null
}

Update private league

Method: update(privateLeagueId, body)

Method updates the specified league. The following options are available for update:

  • name: string. The name of the league. (required)
  • description: string. The description of the league. (required)
  • invitationCode: string. Invitation code where can be use from other users to join the league. (required)
  • templateId: string. The template which will be used for scoring stats in the league. For example if the template is set for Premier League (England) only successful predictions for Premier League matches will be counted in the league(required)
  • usersCanInviteUsers: boolean. Users can invite other users or only the administrator (the creator of the league) can do that. (required)
  • administrators: string[]. Will be there other administrators aswell with the creator of the league. (required)
  • pinnedPosts: string[] . Post ids who are pinned for the league. Pinned posts can be maximum 3. (required)
  • scoringStartsAt: string. The date from when the league 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: true,
  administrators: ["Y44CxUzkpHdypYxcVVlwIQiLNtD2"],
  pinnedPosts: [],
  scoringStartsAt: "2023-11-29",
};

sdk.privateLeagues
  .update("4GJmMesXndaf3o5ijcpHIY", body)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   id: "4GJmMesXndaf3o5ijcpHIY",
   name: "UPDATE",
   description: "UPDATE",
   type: "PRIVATE",
   members: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   banned: [],
   invites: [],
   administrators: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   invitationCode: "c1l3tqf",
   templateId: "1zUfS8hzE75MYaR29HRKyr",
   templateModel: TemplateModel,
   pastTemplates: [
     {
   		 id: "7W8JCLPCg8f0nm9YfwZShf",
       name: "Test template",
       model: TemplateModel
     }
   ],
   usersCanInviteUsers: true,
   scoringStartsAt: "2023-11-29",
   pinnedPosts: []
}

Update private league's template

Method: updateTemplate(privateLeagueId, newTemplateId, oldTemplateName)

Method updates the specified league's template.

N.B. If new template ID exisits in past templates it will be removed from past templates.

N.B.2 League admin can't set same past template names for different past templates.

πŸ“˜

Example call:

const newTemplateId = "7W8JCLPCg8f0nm9YfwZShf";
const oldTemplateName = "old template name";
sdk.privateLeagues
  .updateTemplate("4GJmMesXndaf3o5ijcpHIY", newTemplateId, oldTemplateName)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   id: "4GJmMesXndaf3o5ijcpHIY",
   name: "UPDATE",
   description: "UPDATE",
   type: "PRIVATE",
   members: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   banned: [],
   invites: [],
   administrators: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   invitationCode: "c1l3tqf",
   templateId: "7W8JCLPCg8f0nm9YfwZShf",
   templateModel: TemplateModel,
   pastTemplates: [
     {
       id: "1zUfS8hzE75MYaR29HRKyr",
       name: "old template name",
       model: TemplateModel
     }
   ],
   usersCanInviteUsers: true,
   scoringStartsAt: "2023-11-29",
   pinnedPosts: []
}

Delete private league

Method: delete(privateLeagueId)

Method deletes the specified private league.

πŸ“˜

Example call:

sdk.privateLeagues
  .delete("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

true

Moderate post in a private league

Method: moderatePost(postId, moderationReason)

Method moderates the post from Private League's discussion with the specified moderation reason.

πŸ“˜

Example call:

sdk.privateLeagues
  .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"
}

Private Leagues related operations

Get league by ID

Method: getById(privateLeagueId, disableCache?)

Method returns league details info.

The response from API is cached for 1 hour. With disableCache argument you can avoid cached response.

πŸ“˜

Example call:

sdk.privateLeagues
  .getById("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   id: "4GJmMesXndaf3o5ijcpHIY",
   name: "UPDATE",
   description: "UPDATE",
   type: "PRIVATE",
   members: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   banned: [],
   invites: [],
   administrators: [
      "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
   ],
   invitationCode: "c1l3tqf",
   templateId: "1zUfS8hzE75MYaR29HRKyr",
   templateModel: TemplateModel,
   pastTemplates: [
     {
   		 id: "7W8JCLPCg8f0nm9YfwZShf",
       name: "Test template",
       model: TemplateModel
     }
   ],
   usersCanInviteUsers: true,
   scoringStartsAt: "2023-11-29",
   pinnedPosts: null
}

Get user's leagues rankings

Method: getMyLeagues(filters?)

Method returns all leagues that user is member of and his results (points and position for each league) .

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.
  • leagueId: string. Filter the response to see only the specified league.
  • templateId: string. Filter the response to see only the specified template.
  • sortOrder: string. Determines the sort order - asc or desc

πŸ“˜

Example call:

sdk.privateLeagues
  .getMyLeagues()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  page: 2,
  leagueId: "4GJmMesXndaf3o5ijcpHIY",
  templateId: "1zUfS8hzE75MYaR29HRKyr",
  sortOrder: "desc"
};

sdk.privateLeagues
  .getMyLeagues(filters)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    pagination: {
      currentPage: 2,
      itemsPerPage: 1,
      numberOfPages: 3,
      totalItems: 3
    }
  },
  data: [
    {
      privateLeagueId: "4GJmMesXndaf3o5ijcpHIY",
      privateLeagueModel: PrivateLeagueModel,
      templateId: "1zUfS8hzE75MYaR29HRKyr",
      templateModel: TemplateModel,
      position: 1,
      points: 100,
      type: "private_league"
    }
  ]
}

Get reported posts in a league

Method: getReportedPosts(leagueId, filters?)

Method returns all reported posts in the specified league.

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.privateLeagues
  .getReportedPosts("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  startAfter: "postId",
  reportsCount: 1,
};

sdk.privateLeagues
  .getReportedPosts("4GJmMesXndaf3o5ijcpHIY", filters)
  .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 league

Method: getPredictions(leagueId, filters?)

Method returns all user's own predictions for the specified league.

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.privateLeagues
  .getPredictions("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  page: 2,
  profileIds: ["Y44CxUzkpHdypYxcVVlwIQiLNtD2"],
};

sdk.privateLeagues
  .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,
    }
  ]
}

Private Leagues membership operations

Invite members to a league

Method: invite(privateLeagueId, profiles)

Method invites other users to a league.

N.B. 100 is the maximum numbers of members that can be invited at once.

πŸ“˜

Example call:

sdk.privateLeagues
  .invite("4GJmMesXndaf3o5ijcpHIY", ["PGdBkHS4cXeiFWhDBTnbx885gZ32"])
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

["PGdBkHS4cXeiFWhDBTnbx885gZ32"]

Delete invitation to members in league

Method: deleteInvitation(privateLeagueId, profiles)

Method deletes invitations to members in the league.

πŸ“˜

Example call:

sdk.privateLeagues
  .deleteInvitation("4GJmMesXndaf3o5ijcpHIY", ["PGdBkHS4cXeiFWhDBTnbx885gZ32"])
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });
true

Accept an invitation to a league

Method: accept(privateLeagueId)

Method accepts the invitation to a league.

πŸ“˜

Example call:

sdk.privateLeagues
  .accept("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  profileId: "PGdBkHS4cXeiFWhDBTnbx885gZ32",
  profileModel: ProfileModel,
  leagueId: "4GJmMesXndaf3o5ijcpHIY",
  leagueModel: PrivateLeagueModel,
  message: "User joined league",
}

Reject an invitation to a league

Method: reject(privateLeagueId)

Method rejects an invitation to a league.

πŸ“˜

Example call:

sdk.privateLeagues
  .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 league",
}

Ban users from league

Method: banUsers(privateLeagueId, profiles)

Method bans users from a league.

N.B. 100 is the maximum numbers of members that can be banned at once.

πŸ“˜

Example call:

sdk.privateLeagues
  .banUsers("4GJmMesXndaf3o5ijcpHIY", ["PGdBkHS4cXeiFWhDBTnbx885gZ32"])
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

["PGdBkHS4cXeiFWhDBTnbx885gZ32"]

Join league by invitation code

Method: join(invitationCode)

Method joins the league by accepting invitation code.

πŸ“˜

Example call:

sdk.privateLeagues
  .join("c1l3tqf")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  profileId: "PGdBkHS4cXeiFWhDBTnbx885gZ32",
  profileModel: ProfileModel,
  leagueId: "4GJmMesXndaf3o5ijcpHIY",
  leagueModel: PrivateLeagueModel,
  message: "User joined league",
}

Leave league

Method: leave(privateLeagueId)

Method leaves the league.

πŸ“˜

Example call:

sdk.privateLeagues
  .leave("4GJmMesXndaf3o5ijcpHIY")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

["PGdBkHS4cXeiFWhDBTnbx885gZ32"]

Get league invitations

Method: getInvitations(filters?)

Method returns all leagues 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 leagues should be listed. To be used in the context of infinite scroll/pagination.

πŸ“˜

Example call:

sdk.privateLeagues
  .getInvitations()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  startAfter: "4GJmMesXndaf3o5ijcpHIY"
};

sdk.privateLeagues
  .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: "PRIVATE",
       members: [
          "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
       ],
       banned: [],
       invites: [],
       administrators: [
          "Y44CxUzkpHdypYxcVVlwIQiLNtD2"
       ],
       invitationCode: "c1l3tqf",
       templateId: "1zUfS8hzE75MYaR29HRKyr",
       templateModel: TemplateModel,
       pastTemplates: [
         {
           id: "7W8JCLPCg8f0nm9YfwZShf",
           name: "Test template",
           model: TemplateModel
         }
       ],
       usersCanInviteUsers: true,
       scoringStartsAt: "2023-11-29",
       pinnedPosts: null
    }
  ]
}