Question
Calling External API
Is it possible to call External API in adobe illustrator scripting ?
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
run();
function run() {
// Creating Our XMLHttpRequest object
const xhr = new XMLHttpRequest();
// // Making our connection
var url = "https://jsonplaceholder.typicode.com/todos/1";
xhr.open("GET", url, true);
// // function execute after request is successful
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
}
// // Sending our request
xhr.send();
// Set the path to your AI file
var filePath = "C://Projects//IllustratorPacking//Labels//Source/AAB.ai";
// Set the text to find and replace
var searchText = "EMAIL";
var replaceText = this.responseText.title;
// Open the AI file
var doc = app.open(new File(filePath));
// Iterate through all text items in the document
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
// Check if the text contains the search text
if (textFrame.contents.indexOf(searchText) !== -1) {
// Replace the text
textFrame.contents = textFrame.contents.replace(searchText, replaceText);
}
}
// Save and close the modified AI file
doc.save();
doc.close();
}