Accessing the Syrinscape API with javascript


#1

Hi guys

I already wrote @benjamin about this, but I decided to write in here, as maybe someone else had the same problem and already solved it.

I am currently trying to build a remote control for Syrinscape, that I can integrate into foundryvtt (https://foundryvtt.com/), therefore I am trying to access the API with javascript.
While I can get the play and stop functions to run without problems, I cannot read from the API remotely.

Here is my basic fetch command (replace AUTH with the Auth token)

fetch(“https://www.syrinscape.com/online/frontend-api/soundsets/29/?format=json&auth_token=”+AUTH)
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
generates an error:

“Access to fetch at 'https://www.syrinscape.com/online/frontend-api/soundsets/29/?format=json&auth_token=AUTH from origin ‘http://127.0.0.1:5500’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.”

when I now set the mode to no-cors, i only get the opaque response with no data in it.
Can anyone point me the right way, so I can access the API from a 3rd party script?

Thanks in advance.


#3

@sonofconan Any thoughts?


#4

When I route the request through a CORS Proxy like: https://github.com/Rob--W/cors-anywhere I can access the data just fine


#5

I might have found a workaround. i can build all the links I need when I have the Auth key and the information provided in syrinscape_remote_control_links_Sven_.csv
Either i can use the public version, or I have to do regular updates of my scripts manually.
A Public version would of course be easier :slight_smile:


#6

I’m really glad someone’s building this! I’ve been putting sound links I want to use in journal entries and individual macros manually, and that works well for a scene or very often used sounds. But, I’d prefer something purpose-built in the long run.


#7

It’s my first foray into proper coding. But i managed to parse the csv. So I might get a prototype running soon.


#8

I’d be happy to help test if you need a guinea pig.


#9

I hit a small milestone today. I managed to create a module that reads in the csv and outputs the values to the console.
Not much but baby steps :smiley:


#10

Im super interested in this and your work here.


#11

I was a bit busy the last few days, so I didn’t make much progress. I will have some time off soon though and I plan to use that to continue on the module.

Just keep in mind that this is only a remote. It won’t be able to pipe audio into fvtt directly. That would need a way to add your own player and AFAIK this isn’t planned yet.


#12

Small Update:

I got the Parsing off the CSV down, now I need to create the control menus from that data:

  • Using Categories as filters for Soundsets
  • Using the Soundset as Filter for Moods
  • Generating the Links for each Mood
  • Generating a Stop Button (I think I need to use the Silence Soundset for that)
  • Building a nice Menu around all that.

I would also love to find a way, so i can add the Soundsets to Journal Entries and the like in order to start them Quickly.

I shall keep posting updates here.


#13

Thanks for the update @chrome it’s looking really promising :slight_smile: