<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.lifeguideonline.org/w/index.php?action=history&amp;feed=atom&amp;title=Participant_API_version_1</id>
	<title>Participant API version 1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.lifeguideonline.org/w/index.php?action=history&amp;feed=atom&amp;title=Participant_API_version_1"/>
	<link rel="alternate" type="text/html" href="https://wiki.lifeguideonline.org/w/index.php?title=Participant_API_version_1&amp;action=history"/>
	<updated>2026-05-13T19:02:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.4</generator>
	<entry>
		<id>https://wiki.lifeguideonline.org/w/index.php?title=Participant_API_version_1&amp;diff=22363&amp;oldid=prev</id>
		<title>DonCruickshank: Created page with &quot;&#039;&#039;This API is for managing an intervention as a single participant. It uses the session cookie for authentication and so JavaScript code will automatically authenticate as the logged in participant. If you need to perform changes to an intervention as a whole (e.g. create users, access user data for any participant, etc.) then see REST API version 1&#039;&#039;  __TOC__  = API usage =  The API is intended to be used by JavaScript embedded into the intervention pages to manage...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.lifeguideonline.org/w/index.php?title=Participant_API_version_1&amp;diff=22363&amp;oldid=prev"/>
		<updated>2025-11-24T15:28:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;This API is for managing an intervention as a single participant. It uses the session cookie for authentication and so JavaScript code will automatically authenticate as the logged in participant. If you need to perform changes to an intervention as a whole (e.g. create users, access user data for any participant, etc.) then see &lt;a href=&quot;/wiki/REST_API_version_1&quot; title=&quot;REST API version 1&quot;&gt;REST API version 1&lt;/a&gt;&amp;#039;&amp;#039;  __TOC__  = API usage =  The API is intended to be used by JavaScript embedded into the intervention pages to manage...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;This API is for managing an intervention as a single participant. It uses the session cookie for authentication and so JavaScript code will automatically authenticate as the logged in participant. If you need to perform changes to an intervention as a whole (e.g. create users, access user data for any participant, etc.) then see [[REST API version 1]]&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= API usage =&lt;br /&gt;
&lt;br /&gt;
The API is intended to be used by JavaScript embedded into the intervention pages to manage aspects of the current participant. For this reason, it uses the same authentication method (cookie-based session identifier) as the regular intervention pages.&lt;br /&gt;
&lt;br /&gt;
The API will not be available if there is no intervention session associated with the browser. The intervention session only starts on the first POST request received from the browser (otherwise, the session data would be overwhelmed by search and AI bot activity). In this case, the API will return a 404 HTTP response.&lt;br /&gt;
&lt;br /&gt;
If the intervention session has started but there is no current participant yet, then the API will return a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
= Quick example =&lt;br /&gt;
&lt;br /&gt;
Here is a minimal example using the Fetch API:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
async function getUserData() {&lt;br /&gt;
&lt;br /&gt;
    const command = {&lt;br /&gt;
        type: &amp;quot;listUserData&amp;quot;,&lt;br /&gt;
    };&lt;br /&gt;
    &lt;br /&gt;
    const response = await fetch(&amp;quot;/api/v1&amp;quot;, {&lt;br /&gt;
        method: &amp;quot;POST&amp;quot;,&lt;br /&gt;
        body: JSON.stringify(command)&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    return await response.json();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Example call:&lt;br /&gt;
&lt;br /&gt;
const response = await getUserData();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;data&amp;quot;: [&lt;br /&gt;
        &amp;quot;age&amp;quot;,&lt;br /&gt;
        &amp;quot;gender&amp;quot;,&lt;br /&gt;
        &amp;quot;weight&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Accessing user data =&lt;br /&gt;
&lt;br /&gt;
== List user data ==&lt;br /&gt;
&lt;br /&gt;
API request to list user data. All user data fields are returned without pagination.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Request !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;type&amp;quot;: &amp;quot;listUserData&amp;quot;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;data&amp;quot;: [&lt;br /&gt;
        &amp;quot;age&amp;quot;,&lt;br /&gt;
        &amp;quot;gender&amp;quot;,&lt;br /&gt;
        &amp;quot;weight&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Get user data ==&lt;br /&gt;
&lt;br /&gt;
API request to get user data.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Request !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;type&amp;quot;: &amp;quot;getUserData&amp;quot;,&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;age&amp;quot;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;data&amp;quot;: 25,&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;age&amp;quot;,&lt;br /&gt;
    &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the user data field does not exist then the response will have a status value of &amp;quot;notFound&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Set user data ==&lt;br /&gt;
&lt;br /&gt;
API request to create or update user data.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Request !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;type&amp;quot;: &amp;quot;setUserData&amp;quot;,&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;consent&amp;quot;,&lt;br /&gt;
    &amp;quot;data&amp;quot;: true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;consent&amp;quot;,&lt;br /&gt;
    &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Delete user data ==&lt;br /&gt;
&lt;br /&gt;
API request to delete user data.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Request !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;type&amp;quot;: &amp;quot;deleteUserData&amp;quot;,&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;goal1&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;goal1&amp;quot;,&lt;br /&gt;
    &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If the user data field does not exist then the response will have a status value of &amp;quot;notFound&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Combining multiple API requests into a single HTTP request =&lt;br /&gt;
&lt;br /&gt;
An array of requests can be provided instead of a single request. In this case, the API will return an&lt;br /&gt;
array of responses in the same order as the requests provided.&lt;br /&gt;
&lt;br /&gt;
An example that gets two user data fields.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code !! Response&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
async function processMultipleRequests() {&lt;br /&gt;
&lt;br /&gt;
    const commands = [&lt;br /&gt;
        {&lt;br /&gt;
            type: &amp;quot;getUserData&amp;quot;,&lt;br /&gt;
            id: &amp;quot;age&amp;quot;,&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            type: &amp;quot;getUserData&amp;quot;,&lt;br /&gt;
            id: &amp;quot;consent&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ];&lt;br /&gt;
    &lt;br /&gt;
    const response = await fetch(&amp;quot;/api/v1&amp;quot;, {&lt;br /&gt;
        method: &amp;quot;POST&amp;quot;,&lt;br /&gt;
        body: JSON.stringify(commands)&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    return await response.json();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Example call:&lt;br /&gt;
&lt;br /&gt;
const response = await processMultipleRequests();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
| width=&amp;quot;50%&amp;quot; valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
    {&lt;br /&gt;
        &amp;quot;data&amp;quot;: 25,&lt;br /&gt;
        &amp;quot;id&amp;quot;: &amp;quot;age&amp;quot;,&lt;br /&gt;
        &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
        &amp;quot;data&amp;quot;: true,&lt;br /&gt;
        &amp;quot;id&amp;quot;: &amp;quot;consent&amp;quot;,&lt;br /&gt;
        &amp;quot;status&amp;quot;: &amp;quot;ok&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
You can mix and match request types, e.g. setting three fields and deleting a fourth field.&lt;/div&gt;</summary>
		<author><name>DonCruickshank</name></author>
	</entry>
</feed>