Gathering a OTCSTicket for RESTAPI from the LLCookie



If you are building a form and wish to leverage REST API calls from the form, you will need to either have the user manually authenticate with their username and password, or alternatively gather the OTCSTicket from their existing LLCookie created for the browsing session.

A OTCSTicket is simply a URIDecoded LLCookie. There are a number of JQuery plugin’s that can be leveraged for this however if you do not want add any overhead with a JQuery plugin you can manually iterate through the cookies stored in the browser.

<script>
function getCookie(){
var name="llcookie=";
var cookies = decodeURIComponent(document.cookie).split(';');
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].trim().toLowerCase().startsWith(name)) {
return cookies[i].trim().substring(name.length);
}
}
}
otcsticket = getCookie();
console.log( "otcsticket is now set to: " + otcsticket );
</script>

Both options should generate a OTCSTicket that is valid and not require any authentication prompts for the end user.

Back to post listing