Running a Photoshop script that interfaces with the Google Apps Script REST API

I've been experimenting with integrating Photoshop and Google Apps Script API. I managed to create an API URL in Google Apps Script, but I'm facing issues with making requests and receiving results in my Photoshop Script.

Here is the complete URL, clicking on it will display the JSON result (World Cup Italy).

    var ui = require("ui");
    var http = require("http");

   var api = "https://script.google.com/macros/s/AKfycbza_1YFg7Gux0qs_zRnrjNoIumNA-pTlAzUYKor9DIYTEWVRQjf/exec";


function makeGet(url, input, token){
   var req = new http.HTTPRequest("GET", api+"?action=get&prodid=1934 World Cup Italy");
   req.header("Content-Type", "application/x-www-form-urlencoded");
   var res = req.do();
   if(res.status != 200){
     // alert('ddd');
    return (res.body);
    }
 //  $.writeln(res.status == 200);
 //  $.writeln(res.body);
   return JSON.parse(res.body);
}

Any suggestions on how to call this API from within the Photoshop Script?

Answer №1

When working with Photoshop and API calls, you may encounter some challenges. However, the details provided below are sure to point you in the right direction.

To begin with, it's important to note that Photoshop only offers a Socket object for TCP communication. You can refer to the snippet below from the estk.aenhancers.com JavaScript Tools Guide CC for guidance on utilizing the Socket object:

reply = "";
conn = new Socket;

// accessing Adobe's home page
if (conn.open ("www.adobe.com:80")) {

    // sending a HTTP GET request
    conn.write ("GET /index.html HTTP/1.0\n\n");

    // reading the server's response
    reply = conn.read(999999);

    conn.close();
}

Additionally, Photoshop lacks built-in support for JSON.parse / JSON.stringify functionalities, so you'll need an external library for these tasks. I recommend using tonton-pixel's JSON Action Manager, particularly jamJSON:

I hope this information proves useful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Executing a SQL command that involves a JSON data type column

Currently, I am dealing with a table called individual customer that contains a column named employmentDetails which stores data in JSON format. My objective is to retrieve customers who have an empty locality field. [{ "employmentStatus": " ...

Seeking assistance with dilemmas related to jQuery (specifically kendo), .NET Web Service (asmx), and Json

After conducting extensive research on the subject, I was unable to find any satisfactory answers or complete examples. Since I have limited experience with jquery, I am in search of a straightforward sample that demonstrates what I'm trying to achiev ...

Obtaining additional information through ajax in Yii2

I have encountered an issue where, while receiving data from an ajax call, I am also getting unnecessary data such as all the contents of my PHP files. The problem is illustrated in the image below. How can I resolve this issue? https://i.stack.imgur.com ...

Implementing JavaScript to showcase a list extracted from an API dataset

I'm currently undertaking a project where I am integrating an API from a specific website onto my own webpage. { "data": [{ "truckplanNo":"TCTTV___0D010013", "truckplanType":"COLLECTION", " ...

Transforming JSON data in a Node.js API using JSONata

In need of developing a Node.js REST API for transforming JSON to JSON format. After researching multiple libraries, I have narrowed down my options to "JSONata". You can find a simple sample of JSONata here. The main challenge lies in the fact that the ...

Rails JSON output is suddenly causing timestamps to glitch and default to 2000-01-01T01:31:35Z. What could be causing this unexpected

Currently, I am constructing a JSON object in Rails like this: @list = Array.new @list << { :created_at => item.created_at } end @list.to_json The problem arises when the browser receives data like this: "created_at\":\"200 ...

Developing a personalized collection of top picks and syncing them across multiple

Currently, I am in the process of developing a favorites list using a custom listview. ----------------------------------- <Item_Name> <favorite button> ----------------------------------- On the listView, there is an onItemClickListener. ...

JavaScript is throwing an error stating that the requestData is undefined, even though the

Hello, I am attempting to retrieve weather information based on the country and city using the openweather api. JSON is a new concept for me in coding, so please bear with me through this learning process. Below is the code snippet that I have been workin ...

Error: The node is unable to parse JSON data through the API

After loading a JSON file as a string, attempting to parse it back to JSON and send it as a response: router.get('/todos', (req,res) =>{ let todos = fs.readFile('todos.json', 'utf8',(err, data) =>{ if (err) ...

Creating dynamic bar chart visuals using Morris.js with JSON responses

Utilizing the morris.js library, I am extracting and plotting bar charts from data retrieved through a webservice. Issue: The format of my webservice URL is as follows: http://localhost:9999/hellowebservice/search?select=* I populate the select query ...

Retrieve targeted information from the Coin Market Cap API by extracting specific data values using an array

I am looking to retrieve the symbol and other details using the "name" from my array. $.getJSON("//api.coinmarketcap.com/v1/ticker/?limit=0", function(data) { var crypto = [ "Ethereum", "Ripple", "Tron", ]; // used for arr ...

Exploring the depths of JSON using @attributes and @association in the realm of JavaScript and AngularJS

Currently, I am working on a project that involves utilizing an API for data retrieval, updates, and deletions. The API in question is the prestashop API. While I have managed to retrieve data and update certain items successfully, I encountered an issue. ...

Using Swift to retrieve a nil value from Firebase

I've been attempting this for the past five days, but unfortunately, I haven't had any success. Take a look at my Firebase snapshot below: Snap (Shows) { Show1 = { image = "show1_logo.png"; title = "Show 1"; }; S ...

JavaScript : Retrieve attributes from a JSON object

Situation : I have a JSON object with multiple properties and need to send only selected properties as a JSON string to the server. Approach : To exclude certain properties from the JSON string, I utilized the Object.defineProperty() method to set enumera ...

The Swift HTTP request is missing any post data

When attempting to send post data via http to the server, it seems that no post data is being returned. Below is a snippet of the code I used: var request = URLRequest(url: URL(string: "http://posttestserver.com/post.php")!) request.httpMethod = "POST" re ...

Converting objects into JSON format

I'm trying to transform an object that looks like this: { user[id]: 1, user[name]: 'Lorem', money: '15.00' } Into the following structure: { user: { id: 1, name: 'Lorem', }, money: ...

Handling error reporting using JSON in jQuery AJAX post success

UPDATE: I have resolved the PHP errors mentioned in previous Answers, however, the issue still persists. I am attempting to implement an error message display in case of a failed POST request and a success message for successfully completed requests. Curr ...

What is the best way to decode this JSON data in PHP?

My JSON data is as follows: { "routes": [ { "bounds": { "northeast": { "lat": 41.9291739, "lng": 23.7293099 }, "southwest": { "lat": 37.9103506, ...

Assistance with JSONP (Without the use of jQuery)

I've been putting in a lot of effort trying to understand how to make a JSONP request, but all the reference materials I find are full of jQuery examples. I can go through the jQuery source code, but I prefer a straightforward and simple example. I&ap ...

Strange issue encountered when utilizing Worklight along with XSL transformation on a JSON response

I'm facing an unusual issue that I can't seem to resolve. Here is an example of a JSON response that I am dealing with. "values": [ { "time": "2014-02-26T09:01:00+01:00", "data": [ "A", "B" ] }, // additional objec ...