Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
http://www.example.org/api/connection/statement

You must additionally supply your Basic Auth details with each request in the Authorization header. Your Basic Auth details can be found under Settings > Clients. To retrieve statements for a certain store ensure to use the credentials from the corresponding client. The API also accepts the following optional URL parameters for filtering the models returned.

  • sort (required - we recommend sorting by _id if nothing else)

  • search (available only for user connection User collection in Enterprise)

  • filter (not available for User connectioncollection)

  • project

  • hint

  • first

  • after

URL PARAMETERS

...

Code Block
GET http://www.example.org/api/connection/statement?sort=%7b%22timestamp%22%3a-1%2c%22statement.id%22%3a1%7d
Authorization: Basic YOUR_BASIC_AUTH

SORT PARAMETER

The sort parameter is a JSON encoded object. The keys of the object represent the names of the properties you wish to sort. The values of the object represent the order in which you want to sort the properties. To sort in ascending order, use the number 1; to sort in descending order, use the number -1.

...

Code Block
{
  "timestamp": -1,
  "_id": 1
}

In the above example, we’ve included the _id because it should be unique and the sort parameter should always contain a unique property in order for pagination to work correctly with cursors. The order of the keys in the object determines which property is sorted first, so always include a unique property at the end such as the _id property.

...

Code Block
{
  "statement.context.extensions.http://www&46;example&46;com/extension": 1
}

SORTING WITH IMPROVED PERFORMANCE

...

The search parameter is a simple string and available only for User connectioncollection. This parameter is gonna will search for the match over name and email fields of User schema. So if the value for this parameter is exampleSearchString, as shown in the request below, it will be transformed into filter as shown below.

Code Block
GET http://www.example.org/api/connection/user?search=exampleSearchString
Authorization: Basic YOUR_BASIC_AUTH

{
  "$or": [
    { "name": { "$regex": "exampleSearchString", "$options": "i" } },
    { "email": { "$regex": "exampleSearchString", "$options": "i" } }
  ]
}

FILTER PARAMETER

The filter parameter is a JSON encoded object. The keys of the object represent the names of the properties or operators. The values of the object represent the value you wish to filter by.

...

Code Block
{
  "$or": [{
    "statement.actor.account.name": "123",
    "statement.actor.account.homePage": "http://www.example.org/user"
  }, {
    "statement.verb.id": "http://www.example.org/verb"
  }]
}

In the example above, $or is a an operator , (all operators start with a dollar ($). You can find a list of the available operators in the Mongo documentation. The most common operators are the comparison operators ($eq$gt$gte$in$lt$lte$ne, and $nin) and the logical operators ($and$not$nor, and $or).

...

Code Block
{
  "statement.context.extensions.http://www&46;example&46;com/extension": {
    "$ne": "example_value"
  }
}

FILTERING WITH IMPROVED PERFORMANCE

...

Code Block
{
  "userId": "$statement.actor.account.name",
  "statement.verb": {
    "display": 0
  },
  "statement.object.id": 1
}

In the example above, the value 0 is used to exclude the verb’s display property. Similarly, the value 1 is used to include the object’s identifier. You can find out more about projections via the Mongo documentation.

...

Code Block
{
  "statement.context.extensions.http://www&46;example&46;com/extension": 1
}

HINT PARAMETER

The hint parameter is a JSON encoded object that represents a Mongo index and is similar to the sort parameter. A hint overrides Mongo’s default index selection and query optimisation process.

...

Code Block
{
  "statement.verb.id": 1
}

For more information about hints, you can checkout Mongo’s hint documentation.

...

Code Block
POST http://www.example.org/data/xAPI/statements
Authorization: Basic YOUR_BASIC_AUTH
X-Experience-API-Version: 1.0.3
Content-Type: application/json

[{
  "actor": { "mbox": "mailto:test1@example.org" },
  "verb": { "id": "http://www.example.org/verb" },
  "object": { "id": "http://www.example.org/activity" },
}, {
  "actor": { "mbox": "mailto:test2@example.org" },
  "verb": { "id": "http://www.example.org/verb" },
  "object": { "id": "http://www.example.org/activity" },
}]

The request above should return you a statement identifier for each of the statements in an array.

...

Code Block
GET http://www.example.org/api/connection/statement?first=1
Authorization: Basic YOUR_BASIC_AUTH

The request above should return you a connection, consisting of edges (which contain the models) and page info (which contains the cursors). For example, the above request would return something like the response below.

Code Block
{
  "edges": {
    "cursor": "Zmlyc3RTdGF0ZW1lbnQ=",
    "node": {
      "_id": "59ad59a40334c1bd23322c3a",
      "statement": {
        "id": "0f748889-8d6c-4423-9919-189a14484d2f",
        "actor": { "objectType": "Agent", "mbox": "mailto:test1@example.org" },
        "verb": { "id": "http://www.example.org/verb" },
        "object": { "objectType": "Activity", "id": "http://www.example.org/activity" },
        "version": "1.0.3",
        "authority": {
          "objectType": "Agent",
          "mbox": "mailto:authority@example.org"
        }
      }
    }
  },
  "pageInfo": {
    "endCursor": "Zmlyc3RTdGF0ZW1lbnQ=",
    "hasNextPage": true,
    "hasPreviousPage": true,
    "startCursor": "Zmlyc3RTdGF0ZW1lbnQ="
  }
}

RETRIEVING SUBSEQUENT PAGES

...

Code Block
GET http://www.example.org/api/connection/statement?first=1&after=Zmlyc3RTdGF0ZW1lbnQ=
Authorization: Basic YOUR_BASIC_AUTH

The request above should return you another connection, again this will consist of edges (which contain the models) and page info (which contains the cursors). For example, the request for page two would return something like the response below.

...