Copy link to clipboard
Copied
I wish to call an HTTP endpoint from Illustrator Script using JavaScript. I found some references to BridgeTalk, though it didn't help. Please advise
Copy link to clipboard
Copied
Hello @K24792546oix6,
Thanks for reaching out. Would you mind trying the suggestion shared in this community post (https://community.adobe.com/t5/illustrator-discussions/how-to-access-https-site-from-javascript-sock...) and check if it helps?
Looking forward to your response.
Thanks,
Anubhav
Copy link to clipboard
Copied
There is no direct method for HTTP requests, hence there are some work around. Here is one of the method to run a diverted HTTP request directly from Illustrator script.
function httpRequest(url, method, data, outputFile) {
var curlCommand = 'curl -s -X ' + method + ' "' + url + '"';
if (method === "POST" && data) {
curlCommand += ' -d "' + data + '"';
}
curlCommand += ' -o ' + outputFile;
try {
var tempFile = new File(Folder.temp + "/tempCurlRequest.bat");
tempFile.open('w');
tempFile.write(curlCommand);
tempFile.close();
tempFile.execute();
var timeout = 30000;
var startTime = new Date().getTime();
while (new Date().getTime() - startTime < timeout) {
if (fileExists(outputFile)) {
var response = readFile(outputFile);
var file = new File(outputFile);
return response;
}
$.sleep(500); // Wait for 500ms
}
alert('Timeout: Response file not found!');
} catch (error) {
alert('Error: ' + error.message);
}
}
function fileExists(filePath) {
var file = new File(filePath);
return file.exists;
}
function readFile(filePath) {
var file = new File(filePath);
file.open('r');
var content = file.read();
file.close();
return content;
}
var url = "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.172.0/three.tsl.min.js";
var outputFile = "C:/Users/ParveenKaloi/response.txt"; // replace the file path as per your folder structure for temporaty saving the response
var method = "GET";
var data = "";
var resData = httpRequest(url, method, data, outputFile);
alert(resData)Happy Coding 😉
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more