Skip to content

API Documentation

Liam Armstrong edited this page Jun 22, 2020 · 8 revisions

API Documentation for the Tapestry Tool

These are the endpoints and functions for Tapestry's PHP back-end. Organized by functionality:

  1. Tapestry Functions
  2. Node Functions
  3. Link Functions
  4. User Functions
  5. Gravity Forms Functions
  6. H5P Functions
  7. Misc Functions

1. Tapestry Functions

All functions related to entire tapestries

Create Tapestry

Creates a new tapestry with the given nodes and links. New Tapestry's title and information is in the response settings object Response contains new ids of each node and new links between those nodes

	method: POST
	url: /tapestries
	request: {
		nodes: Array of Objects, 
		groups: Array of Objects,
		links: Array of Objects,
		title: String,
	}
	response: {
		nodes: Array of Numbers,
		groups: Array of Objects,
		linkes: Array of Objects,
		settings: Object,
		rootId: Number
	}

Delete Tapestry

Deletes tapestry with given title from WordPress

	method: DELETE
	url: /tapestries
	request: {
		title: String,
	}
	response: none

Get Tapestry Dataset

Returns the tapestry's dataset in JSON format

	method: GET
	url: /tapestries/<tapestry-post-id>
	response: {
		nodes: Array of Objects, 
		groups: Array of Objects,
		linkes: Array of Objects,
		settings: Object,
		rootId: Number
	}

Update Tapestry Dataset

Replaces a tapestry's dataset with the given data Throws error if tapestry is not empty

	method: PUT
	url: /tapestries/<tapestry-post-id>
	request: {
		nodes: Array of Objects,
		groups: Array of Objects,
		links: Array of Objects,
	}
	response: {
		nodes: Array of Numbers,
		groups: Array of Objects,
		linkes: Array of Objects,
		settings: Object,
		rootId: Number
	}

Update Tapestry Settings

Replaces the tapestry's settings with given data

	method: PUT 
	url: /tapestries/<tapestry-post-id>/settings
	request: {   
		tapestrySlug: String,
		title: String,
		status: String,
		... Remaining fields reflect each setting
	}

Create Tapestry Group

Depreciated

	method: POST
	url: /tapestries/<tapestry-post-id>/groups

2. Node Functions

Create Tapestry Node

Creates a new node in the DB and returns the validated info and Node ID

   method: POST
   url: /tapestries/<tapestry-post-id>/nodes
   request: {
   	type: String,
   	... All other fields from the node creation form
   }
   response: {
   	id: Number,
   	author: Object,
   	type: String,
   	size: String,
   	... All other fields from the Node's definition in the DB
   }

Delete Tapestry Node

Removes node with matching <node-meta-id> from DB

	method: DELETE
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>
	response: Array of Node IDs

Update Tapestry Node

Replaces data for a specific node ID in the DB

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>
	request: {
		type: String,
		... All other fields from the node creation form
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		size: String,
		... All other fields from the Node's definition in the DB
	}

Update Node Permissions

Replace a node with matching <node-meta-id>'s permission object with new data

	method: put
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/permissions
	request: {
		public: Array of String,
		authenticated: Array of String,
		... For each other role or individual ID: Array of String
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		permissions: Object,
		... All other fields from the Node's definition in the DB
	}

Update Node Coordinates

Replace Node coordinates with new coordinates Object

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/coordinates
	request: {
		coordinates: {
			x: Double
			y: Double
		}
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		coordinates: Object,
		... All other fields from the Node's definition in the DB
	}

Update Node Title

Replace Node title field with new String title

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/title
	request: {
		title: String
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		title: String,
		... All other fields from the Node's definition in the DB
	}

Update Node Description

Replace Node description field with new String description

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/description
	request: {
		description: String
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		description: String,
		... All other fields from the Node's definition in the DB
	}

Update Node Thumbnail Image URL

Replace Node image thumbnail URL field with new String URL

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/imageURL
	request: {
		imageURL: String
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		imageURL: String,
		... All other fields from the Node's definition in the DB
	}

Update Node Locked Thumbnail Image URL

Replace Node locked image thumbnail URL field with new String URL

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/lockedImageURL
	request: {
		lockedImageURL: String
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		lockedImageURL: String,
		... All other fields from the Node's definition in the DB
	}

Update Node Type Data

Replace Node typeData with new typeData Object

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/typeData
	request: {
		typeData: Object
	}
	response: {
		id: Number,
		author: Object,
		type: String,
		typeData: Object,
		... All other fields from the Node's definition in the DB
	}

Update Tapestry Node Size

Depreciated

	method: PUT
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/size

3. Link Functions

Create Tapestry Link

Creates a new link between two nodes with given Ids

	method: POST
	url: /tapestries/<tapestry-post-id>/links
	request: {
		source: Number,
		target: Number,
		value: 1,
		type: "",
		appearsAt: "",
	}
	response: {
		source: Number,
		target: Number,
		value: 1,
		type: "",
		appearsAt: "",
	}

Delete Tapestry Link

Removes link with given id Number

	method: DELETE
	url: /tapestries/<tapestry-post-id>/links
	request: Number
	response: Array of Link Objects

4. User Functions

Get User Progress

Retrieve all progress objects from a given tapestry

   method: GET
   url: /users/progress?post_id=<tapestry-post-id>
   response: Array of Progress Objects

Get User Entries

Retrieves user's responses to given node activity If no id is given, returns all entries for all activities

	method: GET
	url: /users/entries?node_id=<node-meta-id>
	response: Array of Entry Objects

Set User's Node Progress

Set the progress value for a given node in a given tapestry

	method: POST
	url: /users/progress
	request: {
		node_id: Number,
		post_id: Number,
		progress_value: Number
	}
	response: None

Set User's Node as Complete

Marks the given node in the given tapestry as complete

	method: POST
	url: /users/completed?post_id=<tapestry-post-id>&node_id=<node-meta-id>
	response: None

Set User's Quiz Question as Complete

Marks the given question, in the given node and tapestry, as complete

	method: POST
	url: /users/quiz?post_id=<tapestry-post-id>&node_id=<node-meta-id>&question_id=<question-id>
	response: None

Get User's H5P Settings

Get the current user's H5P settings for the current tapestry

	method: POST
	url: /users/h5psettings/<tapestry-post-id>
	response: {
		volume: Number,
		muted: Boolean,
		playbackRate: Double,
		quality: String,
		caption: Object
	}

Set User's H5P Settings

Save new H5P settings to database Models the interactive video player settings API

	method: POST
	url: /users/h5psettings/<tapestry-post-id>
	request: {
		volume: Number,
		muted: Boolean,
		playbackRate: Double,
		quality: String,
		caption: Object
	}
	response: none

Get User's Audio Submission

Returns the base64 audio string from the server for given params

	method: GET
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/audio/<question-id>
	response: String

Set User's Audio Submission

Save the audio submission to the server and return a link to that submission

	method: POST
	url: /tapestries/<tapestry-post-id>/nodes/<node-meta-id>/audio
	request: {
		audio: String,
		questionId: String (GUID)
	}
	response: String

Get User's Favourites

Returns a list of node id's user has marked as favorite

	method: GET
	url: /users/favourites?post-id=<tapestry-post-id>
	response: Array of Node IDs

Set User's Favourites

Takes a string representation of the current favourites list, and saves that to the DB

	method: POST
	url: /users/favourites?post-id=<tapestry-post-id>
	request: {
		favourites: String
	}
	response: None

5. Gravity Forms Functions

Check if Gravity Forms Exists

Returns whether or not Gravity Forms is installed on this WordPress instance

	method: GET
	url: /gf/exists
	response: Boolean

Get All Gravity Form Options

Returns all available Gravity Forms forms in this WordPress instance

	/gf/forms
	response: Array of Objects

Get Form Entry

Returns gravity form entry object following the API specs

	method: GET
	url: /gf/entries?form_id=<form-id>
	response: Entry Object

6. H5P Functions

Get All H5P Options

Get the titles of all H5P content items on WP instance

	method: GET
	url: /h5p 
	response: Array of Objects with Title and IDs

7. Misc Functions

Login

Logins in user with given credentials. Returns a hash String (session ID?)

	method: POST
	url: /login
	request: {
		username: String,
		password: String
	}
	response: String

Logout

Logs current user out

	method: POST
	url: /logout
	response: None