Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zapier Code > xAPI Template

Zapier Code > xAPI Template

Send xAPI statements using Zapier Code Action

https://zapier.com

Zapier Code Documentation

https://zapier.com/help/code/

=== Copyright 2016 TorranceLearning

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

// This example uses input from Rocketbook > Google Drive Trigger (http://getrocketbook.com)
// but can be altered for most Zapier triggers.
var stmt = {
actor: {
name: inputData.name,
mbox: inputData.mbox
},
verb: {
id: 'http://adlnet.gov/expapi/verbs/uploaded',
display: {
'en-US': 'uploaded'
}
},
object: {
id: 'http://www.torrancelearning.com/xapi/activities/rocketbook/page',
definition: {
name: { 'en-US': inputData.title },
description: { 'en-US': inputData.desc }
}
},
attachments:[
{ "usageType": "http://www.torrancelearning.com/xapi/activities/extensions/rocketbook/url",
"ContentType":inputData.mimetype,
"length":inputData.filesize,
"sha2":inputData.md5,
"fileUrl":inputData.url
}
],
context: {
extensions: {
'http://www.torrancelearning.com/xapi/activities/extensions/rocketbook/url': inputData.url,
'http://www.torrancelearning.com/xapi/activities/extensions/rocketbook/alt_url': inputData.alt_url
}
},
timestamp: (new Date()).toISOString()
};
console.log(stmt);
var endpoint = '[YOUR XAPI ENDPOINT HERE]';
var basicAuth = 'Basic [YOUR BASIC AUTH HERE]';
fetch(endpoint, {
method: 'POST',
headers: {
'X-Experience-API-Version': '1.0.0',
'Content-Type': 'application/json',
'Authorization': basicAuth
},
body: JSON.stringify(stmt)
})
.then(function(res) {
console.log(res);
return res.json();
}).then(function(json) {
console.log(json);
json = json || {};
callback(null, { success: true });
}).catch(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.