Skip to content

Instantly share code, notes, and snippets.

@ctesene
Created March 15, 2023 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctesene/29245b64acc909872f6bd4042b5dbb1c to your computer and use it in GitHub Desktop.
Save ctesene/29245b64acc909872f6bd4042b5dbb1c to your computer and use it in GitHub Desktop.
Velosimo API
var Velosimo = {
_appName: '',
_key: '',
_token: '',
init: function (name, key, token) {
this._appName = name;
this._key = key;
this._token = token;
},
getCases: async function (recordId) {
var url = `https://dev.velosimo.io/app/${this._appName}/log/docs?X-Tenant-Access-Key=${this._key}&X-Tenant-Access-Token=${this._token}&recordId=${recordId}`;
return new Promise((resolve, reject) => {
$.ajax({
url,
type: 'get',
success: function (data, textStatus, xhr) {
if (!data.status || !data.status == 'success') {
return reject(`invalid status (${data.status})`);
}
if (!Array.isArray(data.documents)) {
return reject('No documents');
}
resolve(data.documents);
},
error: function (xhr, status, error) {
reject({ status, xhr, error });
}
})
});
},
getCaseDetail: async function (recordId, caseId) {
var url = `https://dev.velosimo.io/app/${this._appName}/log/case-detail?X-Tenant-Access-Key=${this._key}&X-Tenant-Access-Token=${this._token}&recordId=${recordId}&caseId=${caseId}`;
return new Promise((resolve, reject) => {
$.ajax({
url,
type: 'get',
success: function (data, textStatus, xhr) {
if (!data.status || !data.status == 'success') {
return reject(`invalid status (${data.status})`);
}
resolve(data.case);
},
error: function (xhr, status, error) {
reject({ status, xhr, error });
}
})
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment