Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How to call external API and exchange data?

Community Beginner ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

Hello,

I wonder if it's at all possible to talk to an external JavaScript API from an InDesign script? Particularly, I'd like to use this calendar module to get supported countries and then holiday names for a chosen country and year. I'd like to use an external library due to it being constantly updated. 

 

I found the below piece of code but am unsure how it should be modified to work with the above API. Any help or similar examples would be much appreciated. BTW I'm on a Mac.

 

var remoteCode = 'http://remote-site.com/test.js'; //location of your remote file
var script = app.doScript("do shell script \"curl 'remoteCode'\"".replace("remoteCode", remoteCode), ScriptLanguage.APPLESCRIPT_LANGUAGE);
// Set script args 
app.scriptArgs.setValue("scriptArg1", "Hello"); 
// Set environmental vars 
$.setenv("envVar1", "World"); 
// Run the "remote" script 
app.doScript(script, ScriptLanguage.JAVASCRIPT);

 

TOPICS
Scripting

Views

52

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

LATEST

So I've been trying to pass some variables around and got an early sucess.

Local JSX:

var remoteCode = 'https://someserver.com/remote.js';
var script = app.doScript("do shell script \"curl 'remoteCode'\"".replace("remoteCode", remoteCode), ScriptLanguage.APPLESCRIPT_LANGUAGE);
var data = ["OK", 2021];
app.doScript(script, ScriptLanguage.JAVASCRIPT, data);
alert(response);

Remote JS:

var incoming = data != null ? data : "error";
var response = "response: " + incoming;

 It looks like I would be able to extend both scripts to get the information I need.

Just for clarification, what do the below lines do?

// Set script args
app.scriptArgs.setValue("scriptArg1", "Hello");
// Set environmental vars
$.setenv("envVar1", "World");

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines