Jump to content

Introduction

IPS4 provides an extensive GraphQL API to provide a way to build apps and integrations that extend and enhance your community.

Using GraphQL outside of the Invision Framework

If you want to use the GraphQL API outside of the IPS Framework, you have to create an OAuth Client and grant it access to GraphQL.

When using an Client ID key, all queries are run as the user, or as alternative, you can use the raw API key and use $_SERVER['HTTP_X_IPS_ACCESSTOKENMEMBER']to set a specific member which will be used as the currently logged in member.

When using OAuth, all queries are run as the specific member.

The endpoint to run the queries is https://www.example.com/api/graphql

A simple example to fetch club information from the club with ID 1:

require_once 'init.php';
$key = "f7f7ccea934691456ca45f873800688d";

$query = "{core{club(id:1){name}}}";
$result = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->base_url, \'/\' ) . \'/api/graphql/index.php\' )->request()->login( $key, "" )->post(
        array(\'query\' => $query)
    )->decodeJson();

print_r($result);
Returns
Array ( [data] => Array ( [core] => Array ( [club] => Array ( [name] => test ) ) ) )

Or the same request with plain cURL

$key = "f7f7ccea934691456ca45f873800688d";
$communityUrl = "https://community.com";
$query = "{core{club(id:1){name}}}";
$url = curl_init( $communityUrl . '/api/graphql/index.php' );
curl_setopt_array( $curl, array(
    CURLOPT_RETURNTRANSFER	=> TRUE,
    CURLOPT_HTTPAUTH        => CURLAUTH_BASIC,
    CURLOPT_USERPWD         => "{$key}:"
    CURLOPT_USERAGENT       => "MyUserAgent/1.0"
    CURLOPT_POSTFIELDS      => [ 'query' => $query ]
) );
print_r( json_decode( curl_exec( $curl ), TRUE ) );

Using GraphQL inside the Invision Framework with internal methods

Queries can be run within templates with help of the graphql template helper.
For example {graphql='{core{me{name,email,url}}}'} will return a JSON object with the name, email and profile url of the currently logged in Member {"core":{"me":{"name":"admin","email":"daniel@local","url":"http:\/\/localhost\/featurebranch\/index.php?\/profile\/1-admin\/"}}.
Inside PHP Userland code, you can use the \IPS\Api\GraphQL::execute( $query, $variables ) method to run queries and mutations.

  • blog queries blogs
    Returns a list of blogs

    Parameters:

    • id List of ids
  • blog queries blog
    Returns a Blog

    Parameters:

    • id List of ids
  • blog queries entries
    Returns a list of blog entries

    Parameters:

    • blogs List of ids
    • offset
    • limit
    • orderBy
    • orderDir
    • honorPinned
  • blog queries entry
    Returns a Blog Entry

    Parameters:

    • id List of ids
  • blog mutations createEntry
    Create a new blog entry

    Fields:

    • blog
  • blog mutations replyEntry
    Create a new comment

    Fields:

    • entryID
    • content
    • replyingTo
    • postKey
  • blog objects Blog

    Available Fields:

    • id
    • name
    • url
    • itemCount
    • commentCount
    • children
    • hasUnread
    • items
    • follow
    • nodePermissions
    • uploadPermissions
    • tagPermissions
  • blog objects Entry

    Available Fields:

    • id
    • url
    • title
    • seoTitle
    • views
    • commentCount
    • isLocked
    • isPinned
    • isFeatured
    • hiddenStatus
    • updated
    • started
    • isUnread
    • timeLastRead
    • unreadCommentPosition
    • findCommentPosition
    • follow
    • tags
    • author
    • container
    • content
    • contentImages
    • hasPoll
    • poll
    • firstCommentRequired
    • articleLang
    • lastCommentAuthor
    • lastCommentDate
    • comments
    • itemPermissions
    • uploadPermissions
    • reportStatus
  • blog objects Comment

    Available Fields:

    • id
    • url
    • timestamp
    • author
    • reputation
    • content
    • isFirstPost
    • isIgnored
    • isFeatured
    • hiddenStatus
    • articleLang
    • commentPermissions
    • reportStatus
    • entry
  • core queries activeUsers
    Returns active user information
  • core queries club
    Returns a club

    Parameters:

    • id List of ids
  • core queries clubs
    Returns a list of clubs

    Parameters:

    • clubs List of ids
    • offset
    • limit
    • orderBy
    • orderDir
  • core queries content
    Return a generic piece of content

    Parameters:

    • url List of ids
  • core queries group
    Returns a member group

    Parameters:

    • id List of ids
  • core queries language
    Return language data

    Parameters:

    • id List of ids
  • core queries loginHandlers
    Return login handler data
  • core queries me
    Return the logged-in member
  • core queries member
    Return a member

    Parameters:

    • id List of ids
    • loggedIn List of ids
  • core queries members
    Returns a list of members

    Parameters:

    • members List of ids
    • offset
    • limit
    • orderBy
    • orderDir
  • core queries messengerConversation
    Returns a messenger conversation

    Parameters:

    • id List of ids
  • core queries messengerConversations
    Returns a list of messenger conversations

    Parameters:

    • folder List of ids
    • filter
    • search List of ids
    • searchIn
    • offset
    • limit
    • orderBy
    • orderDir
  • core queries messengerFolders
    Returns the member's messenger folders
  • core queries notificationTypes
    Returns available notification types
  • core queries ourPicks
    Returns promoted items

    Parameters:

    • count List of ids
  • core queries popularContributors
    Returns popular contributors

    Parameters:

    • limit
    • period
  • core queries settings
    Returns values of system settings (subject to the setting being exposed by the API)
  • core queries stats
    Returns community stats
  • core queries stream
    Returns an activity stream

    Parameters:

    • id List of ids
  • core queries streams
    Returns a list of user's activity streams
  • core mutations follow
    Follow a node, item or member

    Fields:

    • app
    • area
    • id
    • anonymous
    • type
  • core mutations unfollow
    Unfollow a node, item or member

    Fields:

    • app
    • area
    • id
    • followID
  • core mutations markNotificationRead
    Mark a notification as read

    Fields:

    • id
  • core mutations uploadAttachment
    Upload a file to be an attachment

    Fields:

    • name
    • contents
    • postKey
    • chunk
    • totalChunks
    • ref
  • core mutations deleteAttachment
    Delete an attachment

    Fields:

    • id
    • editorLocation
    • locationId1
    • locationId2
    • locationId3
  • core mutations ignoreMember
    Ignore a member

    Fields:

    • member
    • type
    • isIgnoring
  • core mutations changeNotificationSetting
    Change a notification setting

    Fields:

    • id
    • extension
    • type
    • email
    • push
    • inline
  • core mutations leaveConversation
    Leave a PM conversation

    Fields:

    • id
  • core mutations removeConversationUser
    Leave a PM conversation

    Fields:

    • id
    • memberId
  • core mutations addConversationUser
    Add a user to a PM conversation

    Fields:

    • id
    • memberId
  • core objects ActiveUsers

    Available Fields:

    • count
    • users
  • core objects ActiveUser

    Available Fields:

    • url
    • lang
    • anonymous
    • ipAddress
    • timestamp
    • user
  • core objects Attachment

    Available Fields:

    • id
    • ext
    • name
    • size
    • image
    • thumbnail
    • date
    • uploader
  • core objects AttachmentPermissions

    Available Fields:

    • consumedUploadSize
  • core objects ClubNode

    Available Fields:

    • id
    • name
    • seoTitle
    • type
  • core objects Club

    Available Fields:

    • id
    • name
    • type
    • seoTitle
    • createdDate
    • memberCount
    • members
    • owner
    • icon
    • coverPhoto
    • isFeatured
    • about
    • lastActivity
    • nodes
  • core objects Reaction

    Available Fields:

    • id
    • reactionId
    • count
    • image
    • name
  • core objects Group

    Available Fields:

    • id
    • groupType
    • name
    • canAccessSite
    • canAccessOffline
    • canTag
    • maxMessengerRecipients
    • members
  • core objects IgnoreOption

    Available Fields:

    • id
    • type
    • isBeingIgnored
    • lang
  • core objects Member

    Available Fields:

    • id
    • email
    • url
    • name
    • title
    • timezone
    • joined
    • notifications
    • notificationCount
    • posts
    • contentCount
    • reputationCount
    • solvedCount
    • ip_address
    • warn_level
    • profileViews
    • validating
    • group
    • isOnline
    • lastActivity
    • lastVisit
    • lastPost
    • secondaryGroups
    • defaultStream
    • allowFollow
    • follow
    • content
    • clubs
    • photo
    • coverPhoto
    • customFieldGroups
    • maxUploadSize
    • canBeIgnored
    • ignoreStatus
    • messengerDisabled
    • messengerNewCount
  • core objects Language

    Available Fields:

    • title
    • isDefault
    • locale
    • phrases
    • phrase
  • core objects Login

    Available Fields:

    • id
    • title
    • text
    • icon
    • color
    • url
  • core objects MessengerConversation

    Available Fields:

    • id
    • url
    • title
    • seoTitle
    • commentCount
    • started
    • isUnread
    • timeLastRead
    • unreadCommentPosition
    • findCommentPosition
    • author
    • content
    • contentImages
    • firstCommentRequired
    • articleLang
    • lastCommentAuthor
    • lastCommentDate
    • comments
    • itemPermissions
    • uploadPermissions
    • reportStatus
    • folder
    • participants
    • activeParticipants
    • participantBlurb
    • lastMessage
    • updated
  • core objects MessengerFolder

    Available Fields:

    • id
    • name
    • count
    • url
  • core objects MessengerParticipant

    Available Fields:

    • id
    • member
    • isActive
    • isBanned
    • lastRead
    • leftDate
    • lastReply
  • core objects MessengerReply

    Available Fields:

    • id
    • url
    • timestamp
    • author
    • item
    • reputation
    • content
    • isFirstPost
    • isIgnored
    • isFeatured
    • hiddenStatus
    • articleLang
    • commentPermissions
    • reportStatus
  • core objects Notification

    Available Fields:

    • id
    • type
    • app
    • class
    • itemID
    • sentDate
    • updatedDate
    • readDate
    • author
    • title
    • content
    • url
    • unread
  • core objects NotificationMethod

    Available Fields:

    • id
    • disabled
    • default
    • value
  • core objects NotificationType

    Available Fields:

    • id
    • extension
    • group
    • type
    • name
    • description
    • lang
    • inline
    • email
    • push
  • core objects Poll

    Available Fields:

    • id
    • title
    • votes
    • questions
    • closeTimestamp
    • isClosed
    • isPublic
    • hasVoted
    • canVote
    • canViewResults
    • canViewVoters
    • canClose
  • core objects PollQuestion

    Available Fields:

    • id
    • title
    • isMultiChoice
    • votes
    • choices
  • core objects PopularContributor

    Available Fields:

    • rep
    • user
  • core objects ProfileFieldGroup

    Available Fields:

    • id
    • groupId
    • title
    • fields
  • core objects ProfileField

    Available Fields:

    • id
    • fieldId
    • title
    • value
    • type
  • core objects PromotedItem

    Available Fields:

    • id
    • addedBy
    • images
    • title
    • url
    • item
    • itemType
    • description
    • timestamp
    • reputation
    • dataCount
  • core objects ContentSearchResult

    Available Fields:

    • indexID
    • itemID
    • objectID
    • containerID
    • url
    • containerTitle
    • class
    • itemClass
    • firstCommentRequired
    • content
    • contentImages
    • articleLang
    • title
    • unread
    • hiddenStatus
    • updated
    • created
    • isComment
    • isReview
    • replies
    • relativeTimeKey
    • author
    • itemAuthor
    • club
    • reactions
  • core objects Report

    Available Fields:

    • id
    • hasReported
    • reportType
    • reportDate
    • reportContent
  • core objects ReportReason

    Available Fields:

    • id
    • reason
  • core objects SearchResult

    Available Fields:

  • core objects Stats

    Available Fields:

    • contentCount
    • memberCount
  • core objects Stream

    Available Fields:

    • id
    • title
    • member
    • isDefault
    • items
  • core objects Tag

    Available Fields:

    • name
    • url
  • core objects Settings

    Available Fields:

    • base_url
    • tags_enabled
    • tags_min
    • tags_max
    • tags_min_req
    • tags_len_min
    • tags_len_max
    • tags_open_system
    • site_online
    • site_offline_message
    • board_name
    • reputation_enabled
    • reputation_highlight
    • reputation_show_profile
    • allow_reg
    • allow_reg_target
    • allow_result_view
    • geolocation_enabled
    • version
    • privacy_type
    • privacy_text
    • privacy_link
    • reg_rules
    • guidelines_type
    • guidelines_text
    • guidelines_link
    • forums_questions_downvote
    • forums_uses_solved
    • allowedFileTypes
    • chunkingSupported
    • maxChunkSize
    • automoderationEnabled
    • reportReasons
  • core objects UploadProgress

    Available Fields:

    • name
    • ref
  • forums queries forums
    Returns a list of forums

    Parameters:

    • id List of ids
  • forums queries forum
    Returns a forum

    Parameters:

    • id List of ids
    • password List of ids
  • forums queries topics
    Returns a list of topics

    Parameters:

    • forums List of ids
    • offset
    • limit
    • orderBy
    • orderDir
    • honorPinned
  • forums queries topic
    Returns a topic

    Parameters:

    • id List of ids
  • forums queries post
    Returns a post

    Parameters:

    • id List of ids
  • forums mutations createTopic
    Create a new topic

    Fields:

    • forumID
    • title
    • content
    • tags
    • state
    • postKey
  • forums mutations replyTopic
    Create a new post

    Fields:

    • topicID
    • content
    • replyingTo
    • postKey
  • forums mutations postReaction
    React to a post

    Fields:

    • postID
    • reactionID
    • removeReaction
  • forums mutations markForumRead
    Mark a forum as read

    Fields:

    • id
  • forums mutations markTopicRead
    Mark a topic as read

    Fields:

    • id
  • forums mutations markTopicSolved
    Mark a topic solved

    Fields:

    • id
    • answer
    • solved Boolean ( Default Value: 1)
  • forums mutations voteInPoll
    Vote in a poll in a topic

    Fields:

    • itemID
    • poll
  • forums mutations voteQuestion
    Vote on a question

    Fields:

    • id
    • vote
  • forums mutations voteAnswer
    Vote on an answer

    Fields:

    • id
    • vote
  • forums mutations setBestAnswer
    Set a post as best answer

    Fields:

    • id
  • forums mutations reportPost
    Report a post

    Fields:

    • id
    • reason Int ( Default Value: 0)
    • additionalInfo
  • forums mutations revokePostReport
    Report a post

    Fields:

    • id
    • reportID
  • forums objects Forum

    Available Fields:

    • id
    • name
    • url
    • hasUnread
    • follow
    • nodePermissions
    • uploadPermissions
    • tagPermissions
    • solvedEnabled
    • lastPostAuthor
    • lastPostDate
    • featureColor
    • isRedirectForum
    • redirectHits
    • passwordProtected
    • passwordRequired
    • topicCount
    • postCount
    • subforums
    • topics
  • forums objects Post

    Available Fields:

    • id
    • url
    • timestamp
    • author
    • reputation
    • content
    • isFirstPost
    • isIgnored
    • isFeatured
    • hiddenStatus
    • articleLang
    • commentPermissions
    • reportStatus
    • topic
    • isQuestion
    • answerVotes
    • isBestAnswer
    • canVoteUp
    • canVoteDown
    • vote
  • forums objects Topic

    Available Fields:

    • id
    • url
    • title
    • seoTitle
    • views
    • isLocked
    • isPinned
    • isFeatured
    • hiddenStatus
    • updated
    • started
    • isUnread
    • timeLastRead
    • unreadCommentPosition
    • findCommentPosition
    • follow
    • tags
    • author
    • content
    • contentImages
    • hasPoll
    • poll
    • firstCommentRequired
    • articleLang
    • itemPermissions
    • uploadPermissions
    • reportStatus
    • forum
    • isArchived
    • isHot
    • isSolved
    • solvedId
    • canMarkSolved
    • solvedComment
    • isQuestion
    • questionVotes
    • canVoteUp
    • canVoteDown
    • vote
    • hasBestAnswer
    • bestAnswerID
    • canSetBestAnswer
    • postCount
    • posts
    • lastPostAuthor
    • lastPostDate
  • forums objects VoteType

    Available Fields:

×
×
  • Create New...