Dynamic approach to fetching Instance class properties

I have personally run into the issue that I cannot in any easy way get a list of properties for an Instance class. There have been a few hacky solutions around - with the most popular being MaximumADHD’s repo having a copy of the api dump of studio updated every week.
Personally I wanted a more dynamic/‘auto’ updated method, so I looked around, and found that there are actually static json endpoints for the documentation. Below is a javascript example for anyone who would like to replicate this approach.

Note 1: Of course, the exact same code can be used for fetching methods or events, just replace .properties everywhere with .methods or .events.
Note 3: The ‘code’ after /docs/_next/data/ in the url might be a version string - I have not figured this out yet, I will edit the post in the case that this stops working, with an added fetch to get the current version string

JavaScript:

/**
 * @function fetchProperties - Fetches the properties of an instance type
 * @param {string} instanceType - The instance type to fetch the properties of
 * 
 * @returns {Promise<Array<string>>} - The properties of the instance type
 */
const fetchProperties = (instanceType) => new Promise((resolve, reject) =>
    fetch(`https://create.roblox.com/docs/_next/data/ifZs4oxdB6OZde9e3u-pA/en-us/reference/engine/classes/${instanceType}.json`).then((r) => r.json()).then((ref) => {
        // @ts-ignore
        resolve([ref.pageProps.data.apiReference.properties, ...ref.pageProps.data.classReferenceParents.map((parent) => parent.properties)].flat().map((prop) => prop.name))
    }).catch(reject)
)
2 Likes

Maybe I could suggest you to add another tutorial using HttpService?

1 Like

Thank you for the suggestion, I decided not to since you need a proxy for that regardless, at which point you might as well just make a web server of your own :slight_smile: !

2 Likes