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

[Help] Best way to import text/XML into the API?

tl;dr: I have text that is outside of Roll20. I want to make handouts out of that text. What's the easiest/simplest way to get it into Roll20?

I began creating a Dungeon World campaign, and quickly found myself importing various rules into handouts for my players. I figured that I might as well import the entirety of the rules in order to really simplify the learning curve for my players, as Roll20's handout-to-handout linking and 'Show to Players' features are great.

I imagine my process will go something like this:
  1. Parse Dungeon World XML
  2. Use context to add handout-to-handout formatting
  3. Use context to add structural formatting
  4. Read formatted text/XML into the API
  5. Create formatted handouts in structured directories
However, I just began playing around with the API, and it seems that I might have trouble getting outside resources in:
While Roll20 scripts are Javascript, there are some restrictions you should be aware of if you're used to programing Javascript for websites. Roll20 scripts are executed in a separate sandbox from the Roll20 site. This provides an additional layer of separation and security for our system and your players. This sandbox means that:

You cannot make HTTP Requests (AJAX).
You cannot load external scripts or libraries (e.g. jQuery).
The environment is Javascript, but it is not an environment in a browser, so there is no DOM, page elements, CSS,document, window, etc.

Is there a way around this? Is there an alternative way to upload text to Roll20? Is there any sort of REST API?

Patrick said:


Is there a way around this? Is there an alternative way to upload text to Roll20? Is there any sort of REST API?


None.

But what you can do is copy paste the boat load of text into a handout and write a script that parses it.
June 22 (10 years ago)
Given the nature of what you're doing (namely, a one-time import of a fixed set of data), you're probably a lot better off just putting the data you want into your script rather than dealing with writing import routines. I'd be inclined to do the heavy lifting in a Python script or some such that generates the javascript to be pasted into the API window.

The API access to the folder structure is read-only. I wouldn't be surprised if there are plans in the works to make it writable, but for now you can only create handouts at the root level. So you'll have to do the structured directories thing manually after all the handouts are generated.
June 23 (10 years ago)
The Aaron
Pro
API Scripter
I agree with Manvetti. For a one-time load, just stuffing it into an API script as data is the easiest thing to do.
Thanks for the suggestions, they should save me quite a bit of time going forward.

I'm much more familiar with Python than I am with JS, so I will probably follow manveti's suggestion:
  1. Heavy lifting with Python
    1. Import text
    2. Parse text
    3. Process text
  2. Copy/Paste processed text (or generated JS) into script and run
  3. Manually adjust handout hierarchy
If I write any scripts that look somewhat generic/extensible I'll be sure to share with you guys. I've also added some of manveti's advice to https://wiki.roll20.net/API:Objects#Handout, and I might add some more handout creation examples in a bit.