This wrapper tp.api.callApi() is for making calls to specific endpoints without the need for an API token, from the front end of your website. It automatically appends the current user token to the request. It takes an object as a parameter where you can pass in any additional data needed for the request (e.g. rid, term_id, tracking_id, etc.).
See below for examples, and links to each respective API endpoint for further detail.
/access/check
Example:
tp.api.callApi("/access/check", { rid: "RIONCGC" }, function(data) { console.log(data)});
/access/list
Example:
tp.api.callApi("/access/list", {}, function(data) { console.log(data)});
var token = tp.pianoId.getToken();
tp.api.callApi("/access/list", { user_token: token }, function(data) { console.log(data)});
/access/token/list (deprecated)
This returns the __tac cookie, the same as tp.util.getTacCookie();.
Example:
tp.api.callApi("/access/token/list", {}, function(data) { console.log(data)});
/anon/user/get
This returns the basic user object for a logged-in user, similar to tp.pianoId.getUser();.
Example:
tp.api.callApi("/anon/user/get", {}, function(data) { console.log(data)});
/conversion/external/create
Example:
tp.api.callApi("/conversion/external/create", {aid: "", term_id: "", fields: {}}, function(data) { console.log(data) });
/conversion/list
Example:
tp.api.callApi("/conversion/list", {}, function(data) { console.log(data)});
/conversion/log
Example:
tp.api.callApi("/conversion/log", {tracking_id: "", term_id: "", term_name: ""}, function(data) { console.log(data)});
/conversion/logFunnelStep
/conversion/logMicroConversion
/conversion/registration/create
Example:
tp.api.callApi("/conversion/registration/create", {aid: "bktqrVjVsu", term_id: "TMCL1RLOHRTU"}, function(data) {console.log(data)});
Use case: There are two main ways that a user can create an account in Piano, when using Identity Management: natively, through the Identity Management sign-up functionality, or through a registration or purchase flow. In a registration flow, the user creates an account and converts on a registration term, which grants access to a registration resource.
In the specific case that there are places on your site where a user can create an account outside of a registration flow (through a sign-up button, for example) but you want all users who sign up to have access to the registration term, you can implement something like this:
tp = window.tp || [];
tp.push(["init", function() {
tp.push(["addHandler", "loginSuccess", function() {
tp.api.callApi("/access/check/", {rid: "<RID>"}, function (data) {
console.log("access check data: ", data);
if (!data.access.granted) {
tp.api.callApi("/conversion/registration/create", {term_id: "<TERM_ID>"}, function (data) {
console.log("reg conversion done: ", data)
});
}
});
}]);
}]);
/email/confirmation/check
Example:
tp.api.callApi("/email/confirmation/check", {}, function(data){
console.log(data)
});
The method tp.api.getEndpoint() returns the endpoint (the base URL) for the Piano environment currently implemented on your site. For example, on a staging site where a Piano Sandbox app is implemented, calling this method will return https://sandbox.tinypass.com/api/v3.