With Kanka 2.4, a partial JavaScript dump was added for entity attributes and a handful of other information. As of 2.7, this object now includes most of the entity’s information relevant to a character sheet, with the notable exception of abilities. You can access them via the entityData object, which contains the following fields (further detailed on the official Helper page):
console.log(entityData)
{"name": "...","is_private": true/false,"type": { ... },"attributes": { ... },"tags": [ ... ],// The following are only included for Character entities"type_field": "...","gender": "...","pronouns": "...","is_dead": "...","title": "...","age": "...","traits": [ ... ],// and appearances"races": [ ... ],"families": [ ... ],"location": { ... }}
Note that the attribute names used by entityData don’t match their Blade counterparts when it comes to capitalization, which can make interactions between the two languages difficult. On the other hand, it makes it possible to interact with attributes whose name is invalid in Blade, for example those that contain special characters.
Axios API
Kanka 2.7 introduced tools to access the API via axios methods that interact with an entity’s attributes and abilities. This allows us to generate a more thorough attribute dump (including for example attribute types and pinned status) with names that match those used in Blade, as well as a thorough dump of ability information.
However, because axios is only initialized after the page is fully loaded, unlike our character sheet scripts, window.onload is necessary to defer execution until axios is ready. Any processing that relies on the attribute/ability dumps must therefore also be deferred.
functiondumpAttributes (resp, dump = {}) {// Sanitize attribute names for PHP, removing [range] if applicable, to match Blade variablesresp.forEach(obj => { dump[obj.name.replace(/\[range:.*\]|[^a-zA-Z0-9_\x80-\xff]/g,"")] = obj; });return dump;}window.onload= (event) => {// Collect attributes from the APIaxios.get(attributeApis.all.url).then(res => {window.attributes =dumpAttributes(res.data.data);console.log(attributes); // optional, useful for debugging/* Call any functions that require the dump here */ }).catch(err => {console.error("Failed to create attribute dump"); });// Collect abilities from the APIaxios.get(abilityApis.all.url).then(res => {window.abilities =res.data.data;console.log(abilities); // optional, useful for debugging/* Call any functions that require the dump here */ }).catch(err => {console.error("Failed to create ability dump"); });};
Each attribute value can then be accessed with a simple attributes.slug.value, where slug matches the attribute’s corresponding Blade variable:
window.alert("Welcome to "+attributes.CharacterName.value +"’s character sheet!");
Several other details are available via attributes.slug, beyond what is accessible in Blade; for example:
We also get a ton of information about abilities, grouped by their parent field like in the Abilities page of the entity; for example:
{"groups": [ {"id":0,"name":"Unorganised","type":"Abilities are grouped by their parent field, and fallback to being here.","abilities": [ {"id":174521,"ability_id":17663,"name":"Hypercognition", "entry": "<p>HYPERCOGNITION</p><p><b>Level:</b> 6 Divination<br><b>Casting Time:</b> 1 half action<br><b>Distance:</b> Personal<br><b>Duration:</b> 1 hour per Casting Level<br><b>Effect:</b> You gain a +6 magic bonus with Search and Sense Motive checks. As a half action, you may end this spell early to gain a +12 magic bonus with a single Investigate check.<br></p>",
"type":"Spell","charges":null,"used_charges":null,"class": [" kanka-tag-73914"," kanka-tag-wip" ],"note":"","tags": [ {"id":73914,"name":"WIP","url":"https://app.kanka.io/w/19153/entities/949972" } ],"visibility_id":1,"visibility":"Unknown","created_by":22039,"attributes": [ {"id":1175745,"name":"Level","value":"6 Divination","type":"" }, {"id":1175746,"name":"Casting Time","value":"1 half action","type":"" } ],"images": {"has":false,"thumb":"","url":"" } } ] } ],"meta": {"add_url":"https://app.kanka.io/w/19153/entities/6426718/entity_abilities/create","user_id":22039,"is_admin":true }}