Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to make HTTP request in Illustrator ?

New Here ,
Aug 05, 2022 Aug 05, 2022

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

TOPICS
Scripting
429
Translate
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
Adobe
Adobe Employee ,
Aug 05, 2022 Aug 05, 2022

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

Translate
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
New Here ,
Jan 30, 2025 Jan 30, 2025
LATEST

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 😉  

Translate
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