Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

API script for create character and set its token

I know I can run something like:  createObj('character', {  _id: 'UN33', name: '[NPC]:Rat Swarm' }); and create a character sheet by API script, but I also want to set its token For that I previously uploaded an image for my library, at: " tokens/rat-swarm.png ". I know I could get a reference to that image using browser's debug tool but I intent to do that (create a character sheet and set its token) for too many characters, so, getting the images URL by this method is the last thing I want to resort to. Is there any other way? Like " my.account.lib.base.url/tokens/rat-swarm.png "
1568241276
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Well, I'm assuming you don't want this to be hardcoded in. The easiest way is to drop the token on the vtt from your library. Then you can run your API script with the token selected and just get the token details from the selected token.
1568242250
The Aaron
Roll20 Production Team
API Scripter
1) the api can only access user uploaded images, it cannot access external resources.  2) setdefaulttoken() sets the token associated with a character.  3) passing _id to createObj() will be ignored, it generates ids for objects.  The easiest option is to create tokens by dragging them to the map and getting the created graphic's imgsrc. 
Allright. Thank you, guys!