API Subscriptions (GQL)

List a user or team's Subscriptions

The following lists the Subscriptions of the user or team calling the query:

query subscriptions(
  $where: SubscriptionsWhereInput, 
  $pagination: PaginationInput) {
    subscriptions(
      where: $where,
      pagination: $pagination) {
    nodes{
      id
      userId
      apiId
      status
    }
  }
}
{
  "where": {},
  "pagination": {
    "first": 10
  }
}

List any user or team's Subscriptions (admin)

Environment Admins can query for any user or team's subscriptions. This query is used in the Users tab of the Admin Panel. In the Variables, the userId can contain a user or team ID.

๐Ÿ“˜

Environment Admin from personal account

This query only works if you are an Environment Admin. Currently, you must execute this query from your Personal Account (not a team account). This means if the GraphQL Platform API is private, you must personally be invited to use the API.

  query subscriptions($where: SubscriptionsWhereInput) {
    subscriptions(where: $where){
     nodes {
      id
      createdAt
      canceledAt
      api {
        id
        name
        visibility
        category
      }
     }
    }
  }
  {
    "where": {
      "userId": 7344547
   }
  }

List an API's Subscriptions

The following lists the personal users and teams subscribed to an API. You must specify the apiId.

query subscriptions($where: SubscriptionsWhereInput, $pagination: PaginationInput) {
 subscriptions(where: $where, pagination: $pagination) {
  nodes {
   id
   entity {
    type
    name
    email
    id
   }
   status
   createdAt
   canceledAt
   api {
    id
    name
   }
  }
  totalCount
 }
}
{
 "where": {
  "apiId": "api_f6108c78-5ee7-40e5-b177-7b740c96ef2a",
  "pagingArgs": {
   "limit": -1,
   "orderBy": "createdAt",
   "orderDirection": "desc"
  }
 }
}

Additionally, you can view the Subscriptions in the user interface Studio's Hub Listing - Community Tab.

Create a user or team API Subscription

For APIs that use the Rapid Runtime

The following creates a user or team Subscription to an API. If the ownerId is a user, it creates a user Subscription. If the ownerId is a team, it creates a team Subscription.

You must specify the billingPlanVersionId, which can be obtained using query.billingPlanVersions (shown below this query).

mutation CreateSubscription($input: SubscriptionCreateInput!) {
    createSubscription(input: $input) {
      id
      apiId
      status
    __typename
      }
}
{
  "input": {
    "apiId": "api_81eaf459-fd5f-4239-ae64-ab9f06559888",
    "billingPlanVersionId": "billingplanversion_62cb69e2-0503-4f82-83d0-4c6ed78dc2c4",
    "ownerId": "6028339"
  }
}

Obtain an API's billing plan versions

query BillingPlanVersions($where: BillingPlanVersionWhereInput) {
  billingPlanVersions(where: $where) {
    nodes {
      id
      name
      price
      pricing
    }
  }
}
{
  "where": {
    "apiId": "api_81eaf459-fd5f-4239-ae64-ab9f06559888"
  },
  "pagination": {
    "first": "50"
  }
}

For APIs that do not use the Rapid Runtime

The createExternalGatewayApiSubscription mutation can be used to subscribe a user or team to an API version, independent of whether the API uses the Rapid Runtime. No billingPlanVersionId (see above) needs to be provided.

This mutation will subscribe the user or team that owns the X-RapidAPI-Key used to make the call to a specific version of an API. If the apiVersionId is not provided, the Current API version will be used.

For private APIs, the user or team must be invited to use the API that they want to subscribe to before this mutation will work.

mutation CreateExternalGatewayApiSubscription($input: ExternalGatewaySubscriptionCreateInput!) {
    createExternalGatewayApiSubscription(input: $input) {
      id
      apiId
      apiVersionId
      status
    __typename
      }
}
{
  "input": {
    "apiId": "api_6040d9e7-3d00-43d5-bc51-b7e10c3348ea"
  }
}

Delete an API subscription

The id of the subscription must be specified. You can obtain this using query.subscriptions (see above).

mutation deleteSubscription($id: ID!) {
  deleteSubscription(id: $id)
}
{
  "id": "4460204"
}