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.
-
Returns a list of blogs
Parameters:
- id List of ids
-
Returns a Blog
Parameters:
- id List of ids
-
Returns a list of blog entries
Parameters:
- blogs List of ids
- offset
- limit
- orderBy
- orderDir
- honorPinned
-
Returns a Blog Entry
Parameters:
- id List of ids
-
Create a new blog entry
Fields:
- blog
-
Create a new comment
Fields:
- entryID
- content
- replyingTo
- postKey
-
Available Fields:
- id
- name
- url
- itemCount
- commentCount
- children
- hasUnread
- items
- follow
- nodePermissions
- uploadPermissions
- tagPermissions
-
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
-
Available Fields:
- id
- url
- timestamp
- author
- reputation
- content
- isFirstPost
- isIgnored
- isFeatured
- hiddenStatus
- articleLang
- commentPermissions
- reportStatus
- entry
-
Returns active user information
-
Returns a club
Parameters:
- id List of ids
-
Returns a list of clubs
Parameters:
- clubs List of ids
- offset
- limit
- orderBy
- orderDir
-
Return a generic piece of content
Parameters:
- url List of ids
-
Returns a member group
Parameters:
- id List of ids
-
Return language data
Parameters:
- id List of ids
-
Return login handler data
-
Return the logged-in member
-
Return a member
Parameters:
- id List of ids
- loggedIn List of ids
-
Returns a list of members
Parameters:
- members List of ids
- offset
- limit
- orderBy
- orderDir
-
Returns a messenger conversation
Parameters:
- id List of ids
-
Returns a list of messenger conversations
Parameters:
- folder List of ids
- filter
- search List of ids
- searchIn
- offset
- limit
- orderBy
- orderDir
-
Returns the member's messenger folders
-
Returns available notification types
-
Returns promoted items
Parameters:
- count List of ids
-
Returns popular contributors
Parameters:
- limit
- period
-
Returns search results
Parameters:
- term List of ids
- type
- offset
- limit
- orderBy
- orderDir
-
Returns values of system settings (subject to the setting being exposed by the API)
-
Returns community stats
-
Returns an activity stream
Parameters:
- id List of ids
-
Returns a list of user's activity streams
-
Follow a node, item or member
Fields:
- app
- area
- id
- anonymous
- type
-
Unfollow a node, item or member
Fields:
- app
- area
- id
- followID
-
Mark a notification as read
Fields:
- id
-
Upload a file to be an attachment
Fields:
- name
- contents
- postKey
- chunk
- totalChunks
- ref
-
Delete an attachment
Fields:
- id
- editorLocation
- locationId1
- locationId2
- locationId3
-
Ignore a member
Fields:
- member
- type
- isIgnoring
-
Change a notification setting
Fields:
- id
- extension
- type
- push
- inline
-
Leave a PM conversation
Fields:
- id
-
Leave a PM conversation
Fields:
- id
- memberId
-
Add a user to a PM conversation
Fields:
- id
- memberId
-
Available Fields:
- count
- users
-
Available Fields:
- url
- lang
- anonymous
- ipAddress
- timestamp
- user
-
Available Fields:
- id
- ext
- name
- size
- image
- thumbnail
- date
- uploader
-
Available Fields:
- consumedUploadSize
-
Available Fields:
- id
- name
- seoTitle
- type
-
Available Fields:
- id
- name
- type
- seoTitle
- createdDate
- memberCount
- members
- owner
- icon
- coverPhoto
- isFeatured
- about
- lastActivity
- nodes
-
Available Fields:
- id
- reactionId
- count
- image
- name
-
Available Fields:
- id
- groupType
- name
- canAccessSite
- canAccessOffline
- canTag
- maxMessengerRecipients
- members
-
Available Fields:
- id
- type
- isBeingIgnored
- lang
-
Available Fields:
- id
- 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
-
Available Fields:
- title
- isDefault
- locale
- phrases
- phrase
-
Available Fields:
- id
- title
- text
- icon
- color
- url
-
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
-
Available Fields:
- id
- name
- count
- url
-
Available Fields:
- id
- member
- isActive
- isBanned
- lastRead
- leftDate
- lastReply
-
Available Fields:
- id
- url
- timestamp
- author
- item
- reputation
- content
- isFirstPost
- isIgnored
- isFeatured
- hiddenStatus
- articleLang
- commentPermissions
- reportStatus
-
Available Fields:
- id
- type
- app
- class
- itemID
- sentDate
- updatedDate
- readDate
- author
- title
- content
- url
- unread
-
Available Fields:
- id
- disabled
- default
- value
-
Available Fields:
- id
- extension
- group
- type
- name
- description
- lang
- inline
- push
-
Available Fields:
- id
- title
- votes
- questions
- closeTimestamp
- isClosed
- isPublic
- hasVoted
- canVote
- canViewResults
- canViewVoters
- canClose
-
Available Fields:
- id
- title
- isMultiChoice
- votes
- choices
-
Available Fields:
- rep
- user
-
Available Fields:
- id
- groupId
- title
- fields
-
Available Fields:
- id
- fieldId
- title
- value
- type
-
Available Fields:
- id
- addedBy
- images
- title
- url
- item
- itemType
- description
- timestamp
- reputation
- dataCount
-
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
-
Available Fields:
- id
- hasReported
- reportType
- reportDate
- reportContent
-
Available Fields:
- id
- reason
-
Available Fields:
-
Available Fields:
- count
- results
- types
-
Available Fields:
- contentCount
- memberCount
-
Available Fields:
- id
- title
- member
- isDefault
- items
-
Available Fields:
- name
- url
-
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
-
Available Fields:
- name
- ref
-
Returns a list of forums
Parameters:
- id List of ids
-
Returns a forum
Parameters:
- id List of ids
- password List of ids
-
Returns a list of topics
Parameters:
- forums List of ids
- offset
- limit
- orderBy
- orderDir
- honorPinned
-
Returns a topic
Parameters:
- id List of ids
-
Returns a post
Parameters:
- id List of ids
-
Create a new topic
Fields:
- forumID
- title
- content
- tags
- state
- postKey
-
Create a new post
Fields:
- topicID
- content
- replyingTo
- postKey
-
React to a post
Fields:
- postID
- reactionID
- removeReaction
-
Mark a forum as read
Fields:
- id
-
Mark a topic as read
Fields:
- id
-
Mark a topic solved
Fields:
- id
- answer
- solved Boolean ( Default Value: 1)
-
Vote in a poll in a topic
Fields:
- itemID
- poll
-
Vote on a question
Fields:
- id
- vote
-
Vote on an answer
Fields:
- id
- vote
-
Set a post as best answer
Fields:
- id
-
Report a post
Fields:
- id
- reason Int ( Default Value: 0)
- additionalInfo
-
Report a post
Fields:
- id
- reportID
-
Available Fields:
- id
- name
- url
- hasUnread
- follow
- nodePermissions
- uploadPermissions
- tagPermissions
- solvedEnabled
- lastPostAuthor
- lastPostDate
- featureColor
- isRedirectForum
- redirectHits
- passwordProtected
- passwordRequired
- topicCount
- postCount
- subforums
- topics
-
Available Fields:
- id
- url
- timestamp
- author
- reputation
- content
- isFirstPost
- isIgnored
- isFeatured
- hiddenStatus
- articleLang
- commentPermissions
- reportStatus
- topic
- isQuestion
- answerVotes
- isBestAnswer
- canVoteUp
- canVoteDown
- vote
-
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
-
Available Fields:
-
Returns a gallery image
Parameters:
- id List of ids
-
Available Fields:
- id
- name
- url
- itemCount
- commentCount
- hasUnread
- items
- follow
- nodePermissions
- uploadPermissions
- tagPermissions
- owner
- lastImage
- latestImages
- item
-
Available Fields:
- id
- url
- timestamp
- author
- item
- reputation
- content
- isFirstPost
- isIgnored
- isFeatured
- hiddenStatus
- articleLang
- commentPermissions
- reportStatus
-
Available Fields:
- id
- url
- title
- seoTitle
- commentCount
- isLocked
- isPinned
- isFeatured
- hiddenStatus
- updated
- started
- isUnread
- timeLastRead
- unreadCommentPosition
- findCommentPosition
- follow
- tags
- author
- container
- content
- contentImages
- firstCommentRequired
- articleLang
- lastCommentAuthor
- lastCommentDate
- comments
- itemPermissions
- uploadPermissions
- reportStatus
-
Available Fields:
- id
- url
- title
- seoTitle
- views
- commentCount
- isLocked
- isPinned
- isFeatured
- hiddenStatus
- updated
- started
- isUnread
- timeLastRead
- unreadCommentPosition
- findCommentPosition
- follow
- tags
- author
- container
- content
- contentImages
- firstCommentRequired
- articleLang
- lastCommentAuthor
- lastCommentDate
- comments
- itemPermissions
- uploadPermissions
- reportStatus
- caption
- hasAlbum
- album
- nextImage
- prevImage
- credit
- copyright
- isMedia
- maskedFileName
- originalFileName
- smallFileName
- fileSize
- location
- dims
-
Available Fields:
- id
- url
- timestamp
- author
- item
- reputation
- content
- isFirstPost
- isIgnored
- isFeatured
- hiddenStatus
- articleLang
- commentPermissions
- reportStatus