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

Video - Tutorial on Writing an API Script

February 28 (5 years ago)
Nick O.
Forum Champion

I created a video that walks a user through writing an API script that summons a spiritual weapon to the battlefield. It's my first time making a vid like this, so feedback is appreciated. :) 

February 28 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

I'm only halfway through, but I had to jump back in here to say this is amazing. I wish I had had this when I started. Having each line written and explained is powerful education. Best video yet.

February 28 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

And finished. GREAT JOB! This is a complex subject that causes many people to just look at it and say "I don't understand any of this. Not even gonna try". By writing each line and explaining it thoroughly as you write, you've demystified it considerably.

February 28 (5 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter

Great newbie introduction to API scripting! I could give some pointers on coding conventions and some ESNext features, but I'd just be nitpicking.

February 28 (5 years ago)
Mino
Marketplace Creator

The API Terrifies me, but it's incredibly useful. I'm away from home at the moment, but I appreciate someone making a video tutorial! I'll have to check it when I get home, as not being able to follow along with an expected result is really the highest bar I have to trying to make my own scripts with the API.

This is wonderful, thank you for creating and sharing it! I've been learning JS but have still been hesitant to attempt anything with the API, but your explanations may be just the push I needed =D

February 29 (5 years ago)
Nick O.
Forum Champion

Thanks for the feedback, everyone! I'm glad you found the video helpful. I will try to make more like this in the future.

April 05 (5 years ago)

Edited April 05 (5 years ago)

Nick,  Most excellent video!  It really helped out with the basics of the java scripting language.  I'm sure the link to the documentation about the API objects will be really helpful.

Can you help me out with something though?  I can't get the new graphics object to appear. It's seems to execute the code the whole way through and I see the special affects appear beside the selected token, but no new token for the spiritual weapon appears.  I even did a direct paste of your code from GitHub and just replaced the URL for the thumbnail image.  Do I need to configure a setting in Roll20 or something?

I put the URL to the graphic (https://s3.amazonaws.com/files.d20.io/images/117882473/EolMEGCe0jG08KERVH0CPA/thumb.png?15860634515) in my web browser (Chrome) and I got the following code.  Should I be concerned about the "AccessDenied"?:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>DED6C2E2C7650F10</RequestId>
<HostId>
62+lGFITcIFgE62Yao2QZOqhpR0y4dXUASn/SCqXWQbV2gRkamVnwC2XRLZv3IhACW1n2JrSrOQ=
</HostId>

</Error> 

April 05 (5 years ago)
Nick O.
Forum Champion

Glad you liked it, Chris! There aren't any special settings you need to configure, you just need to have the image available in your library. Are there any errors appearing on the API script page? 

April 05 (5 years ago)

Edited April 05 (5 years ago)

Nick,

I don't see any except when i was trouble-shooting and i removed the numbers and question mark after the file name in the URL.  Then it came up with the following error, but now it's obvious the API needs those numbers.

"ERROR: You must include the query string in your URL. For example, use 'https://s3.amazonaws.com/files.staging.d20.io/images/123456/med.png?12345678', not 'https://s3.amazonaws.com/files.staging.d20.io/images/123456/med.png'"


April 05 (5 years ago)

Edited April 05 (5 years ago)

Further update:  I put the numbers back on the end of the URL and it's still doing the same thing where the chat message comes up, and the special effects happen, but no new icon for the spiritual weapon appears.

Any ideas?

So I think I figured it out - you have to be specific in two things: 

1) Graphics moved/copied from the marketplace into the folders of "My Library" doesn't actually count as being in your library, hence the error below, and the apparent hanging of the web page

"ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info."  

2) Using the right click pop-up menu to copy an uploaded image to a folder in your library also doesn't work.  You have to use the 3 lines to the left of the uploaded file name under "Recent Uploads" and drag it to the desired folder in "My Library".  Using the right-click pop-up menu results in everything running, just no token appearing.

I think I can work around these two requirements.

Thanks again, Nick, for your excellent video!!

April 05 (5 years ago)
Nick O.
Forum Champion

Can you post the URL to your image? 

April 05 (5 years ago)

Edited April 05 (5 years ago)

Well, since you asked (promise not to get upset though):

Lollipop (yes, I'm using your code as a gag for one of my friends playing a death cleric   LOL):

https://s3.amazonaws.com/files.d20.io/images/118285289/f8-ICjY32IiQk35vAfsRtg/original.png?15861206975

I did manage to get this working.

April 05 (5 years ago)
Nick O.
Forum Champion

A death lollipop sounds pretty awesome, actually :)

If you're still having issues, try changing the URL to this - the API usually wants to use the thumbnail versions of images. 

https://s3.amazonaws.com/files.d20.io/images/118285289/f8-ICjY32IiQk35vAfsRtg/thumb.png?15861206975

Oops.  I actually did switch the thumb in for the original in the file name for the code.  I just forgot to do that in my previous post.  It's all working good now.

Thanks, Nick!