API GET from Submit Point
API GET from Submit Point
Hello fellow Forum users.
I'm looking to do a GET command using REST of a list of stocks out of Tila Phoenix and populate them to a dropdown list in a submit point.
I've been using the HTTP request to do API call successfully to create new stocks, add to them, delete them, get plans, etc. As this flow as progressed the need for the user to know if a stock exists is needed so I've been trying add this in the submit point, if the stock isn't there the user can use the add portion of the submit point to add it and then be able to submit the csv to do the imposition in tilia.
I can get the response using HTTP request in a sample flow but I don't know how to script it in the check point to take the response and allow it to be a long drop down.
Any help or sample of how the script need to be done would be a huge help!!
Thanks,
-O
I'm looking to do a GET command using REST of a list of stocks out of Tila Phoenix and populate them to a dropdown list in a submit point.
I've been using the HTTP request to do API call successfully to create new stocks, add to them, delete them, get plans, etc. As this flow as progressed the need for the user to know if a stock exists is needed so I've been trying add this in the submit point, if the stock isn't there the user can use the add portion of the submit point to add it and then be able to submit the csv to do the imposition in tilia.
I can get the response using HTTP request in a sample flow but I don't know how to script it in the check point to take the response and allow it to be a long drop down.
Any help or sample of how the script need to be done would be a huge help!!
Thanks,
-O
Color Science & Workflow Automation
Re: API GET from Submit Point
The list of stocks is not likely to be a very dynamic list so what I would suggest to make things a lot easier is that in your script you put the response into global data and make sure you run the script once every hour (or whatever interval you find suitable).
The script expression in the submit point then becomes very easy because all it has to do is take the list from global data.
Tip: use jobArrived in combination with FireStarter to trigger the script and add a submit point in the flow with a trigger so you have the ability to trigger a sync whenever you changed something in Phoenix.
The script expression in the submit point then becomes very easy because all it has to do is take the list from global data.
Tip: use jobArrived in combination with FireStarter to trigger the script and add a submit point in the flow with a trigger so you have the ability to trigger a sync whenever you changed something in Phoenix.
Re: API GET from Submit Point
I kind of follow. I can admit my scripting is a bit poor and I have not messed with the global data. I see there is app that easily allows you to store exactly what you are saying to global data, I just felt a simple call would be easier since this flow wont be used a lot. But I appreciate the input and this will allow me to learn something new, pending I can figure it out. HA! - In the end Id still like see an example of how the script should be written for a call out of a Submit Point.freddyp wrote: ↑Tue Dec 20, 2022 8:49 am The list of stocks is not likely to be a very dynamic list so what I would suggest to make things a lot easier is that in your script you put the response into global data and make sure you run the script once every hour (or whatever interval you find suitable).
The script expression in the submit point then becomes very easy because all it has to do is take the list from global data.
Tip: use jobArrived in combination with FireStarter to trigger the script and add a submit point in the flow with a trigger so you have the ability to trigger a sync whenever you changed something in Phoenix.
-O
Color Science & Workflow Automation
Re: API GET from Submit Point
The below Script expression work assuming you're Phoenix 8+. You will just need swap out the phoenixURL with the URL of your Phoenix instance API endpoint
Code: Select all
// Define Phoenix API URL variable
var phoenixURL = "http://path-to-phoenix-api:8022/phoenix";
// Define HTTP client function
function httpClient(url) {
// Create HTTP object
var theHTTP = new HTTP();
theHTTP.url = url;
theHTTP.authScheme = HTTP.NoneAuth;
theHTTP.get();
// Wait for request to finish
while (!theHTTP.waitForFinished(3)) {}
// Check if status code is 200
if (theHTTP.statusCode != 200) job.log(2, "Phoenix REST API unavailable, " + theHTTP.statusCode + " status code returned");
return theHTTP.getServerResponse().toString("UTF-8");
}
// Define a sheets array to push to and return
var sheets = [];
// Define stocks variable and get stock library
var stocks = JSON.parse(httpClient(phoenixURL + "/libraries/v2/stocks"));
// Loop through stock library
for (var i = 0; i < stocks.length; i++) {
var currentStock = stocks[i];
for (var j = 0; j < currentStock.grades.length; j++) {
var currentGrade = currentStock.grades[j];
for (var k = 0; k < currentGrade.sheets.length; k++) {
var currentSheet = currentGrade.sheets[k];
sheets.push(currentStock.name + "/" + currentGrade.name + "/" + currentSheet.name);
}
}
}
sheets.join(";");
Re: API GET from Submit Point
Thank you so much. I was actually closer than I thought. This shows me the structure I needed. - I'll be able to use this for a lot of other things. I'll test it here shortly and let you know how to goes.mkayyyy wrote: ↑Tue Dec 20, 2022 3:59 pm The below Script expression work assuming you're Phoenix 8+. You will just need swap out the phoenixURL with the URL of your Phoenix instance API endpoint
Code: Select all
// Define Phoenix API URL variable var phoenixURL = "http://path-to-phoenix-api:8022/phoenix"; // Define HTTP client function function httpClient(url) { // Create HTTP object var theHTTP = new HTTP(); theHTTP.url = url; theHTTP.authScheme = HTTP.NoneAuth; theHTTP.get(); // Wait for request to finish while (!theHTTP.waitForFinished(3)) {} // Check if status code is 200 if (theHTTP.statusCode != 200) job.log(2, "Phoenix REST API unavailable, " + theHTTP.statusCode + " status code returned"); return theHTTP.getServerResponse().toString("UTF-8"); } // Define a sheets array to push to and return var sheets = []; // Define stocks variable and get stock library var stocks = JSON.parse(httpClient(phoenixURL + "/libraries/v2/stocks")); // Loop through stock library for (var i = 0; i < stocks.length; i++) { var currentStock = stocks[i]; for (var j = 0; j < currentStock.grades.length; j++) { var currentGrade = currentStock.grades[j]; for (var k = 0; k < currentGrade.sheets.length; k++) { var currentSheet = currentGrade.sheets[k]; sheets.push(currentStock.name + "/" + currentGrade.name + "/" + currentSheet.name); } } } sheets.join(";");
This community is great!
-O
Color Science & Workflow Automation
Re: API GET from Submit Point
This worked fantastic. Now I need to clean the library up and get the submit point as I want it.
I used the base of the script to populate other items as well. This allows the user to see the stocks prior to submitting a csv for use with Phoenix and if it's not there they can add it on the fly and it'll be added at the time of submit making this a one step process.
Thanks again to @mkayyy
I used the base of the script to populate other items as well. This allows the user to see the stocks prior to submitting a csv for use with Phoenix and if it's not there they can add it on the fly and it'll be added at the time of submit making this a one step process.
Thanks again to @mkayyy
Color Science & Workflow Automation
Re: API GET from Submit Point
Looks great, glad I could help!rhd_ole wrote: ↑Tue Dec 20, 2022 4:59 pm This worked fantastic. Now I need to clean the library up and get the submit point as I want it.
I used the base of the script to populate other items as well. This allows the user to see the stocks prior to submitting a csv for use with Phoenix and if it's not there they can add it on the fly and it'll be added at the time of submit making this a one step process.
Screenshot 2022-12-20 at 9.53.55 AM.png
Thanks again to @mkayyy
Re: API GET from Submit Point
Bringing this back up from the dead hoping you can assist again @mkayyymkayyyy wrote: ↑Tue Dec 20, 2022 5:31 pmLooks great, glad I could help!rhd_ole wrote: ↑Tue Dec 20, 2022 4:59 pm This worked fantastic. Now I need to clean the library up and get the submit point as I want it.
I used the base of the script to populate other items as well. This allows the user to see the stocks prior to submitting a csv for use with Phoenix and if it's not there they can add it on the fly and it'll be added at the time of submit making this a one step process.
Screenshot 2022-12-20 at 9.53.55 AM.png
Thanks again to @mkayyy
I just realized this doesn't' include roll stocks. I tried to edit your script but I can't seem to get it both to combine in the list.
Color Science & Workflow Automation
Re: API GET from Submit Point
Sure, ezpz that. The below code block will pull all sheets and rolls:rhd_ole wrote: ↑Thu Jan 26, 2023 1:57 pmBringing this back up from the dead hoping you can assist again @mkayyymkayyyy wrote: ↑Tue Dec 20, 2022 5:31 pmLooks great, glad I could help!rhd_ole wrote: ↑Tue Dec 20, 2022 4:59 pm This worked fantastic. Now I need to clean the library up and get the submit point as I want it.
I used the base of the script to populate other items as well. This allows the user to see the stocks prior to submitting a csv for use with Phoenix and if it's not there they can add it on the fly and it'll be added at the time of submit making this a one step process.
Screenshot 2022-12-20 at 9.53.55 AM.png
Thanks again to @mkayyy
I just realized this doesn't' include roll stocks. I tried to edit your script but I can't seem to get it both to combine in the list.
Code: Select all
// Define Phoenix API URL variable
var phoenixURL = "http://path-to-phoenix-api:8022/phoenix";
// Define HTTP client function
function httpClient(url) {
// Create HTTP object
var theHTTP = new HTTP();
theHTTP.url = url;
theHTTP.authScheme = HTTP.NoneAuth;
theHTTP.get();
// Wait for request to finish
while (!theHTTP.waitForFinished(3)) {}
// Check if status code is 200
if (theHTTP.statusCode != 200) job.log(2, "Phoenix REST API unavailable, " + theHTTP.statusCode + " status code returned");
return theHTTP.getServerResponse().toString("UTF-8");
}
// Define a sheets and rolls array to push to and return
var sheetsAndRolls = [];
// Define stocks variable and get stock library
var stocks = JSON.parse(httpClient(phoenixURL + "/libraries/v2/stocks"));
// Loop through stock library
for (var i = 0; i < stocks.length; i++) {
var currentStock = stocks[i];
for (var j = 0; j < currentStock.grades.length; j++) {
var currentGrade = currentStock.grades[j];
for (var k = 0; k < currentGrade.sheets.length; k++) {
var currentSheet = currentGrade.sheets[k];
sheetsAndRolls.push(currentStock.name + "/" + currentGrade.name + "/" + currentSheet.name);
}
for (var r = 0; r < currentGrade.rolls.length; r++) {
var currentRoll = currentGrade.rolls[r];
sheetsAndRolls.push(currentStock.name + "/" + currentGrade.name + "/" + currentRoll.name);
}
}
}
sheetsAndRolls.join(";");
Re: API GET from Submit Point
Thanks for the quick reply. This worked great. I added sheetsAndRolls.sort(); so they are in order and this is beautiful. Thank you so much.. I love this community.mkayyyy wrote: ↑Thu Jan 26, 2023 2:19 pm
Sure, ezpz that. The below code block will pull all sheets and rolls:
Code: Select all
// Define Phoenix API URL variable var phoenixURL = "http://path-to-phoenix-api:8022/phoenix"; // Define HTTP client function function httpClient(url) { // Create HTTP object var theHTTP = new HTTP(); theHTTP.url = url; theHTTP.authScheme = HTTP.NoneAuth; theHTTP.get(); // Wait for request to finish while (!theHTTP.waitForFinished(3)) {} // Check if status code is 200 if (theHTTP.statusCode != 200) job.log(2, "Phoenix REST API unavailable, " + theHTTP.statusCode + " status code returned"); return theHTTP.getServerResponse().toString("UTF-8"); } // Define a sheets and rolls array to push to and return var sheetsAndRolls = []; // Define stocks variable and get stock library var stocks = JSON.parse(httpClient(phoenixURL + "/libraries/v2/stocks")); // Loop through stock library for (var i = 0; i < stocks.length; i++) { var currentStock = stocks[i]; for (var j = 0; j < currentStock.grades.length; j++) { var currentGrade = currentStock.grades[j]; for (var k = 0; k < currentGrade.sheets.length; k++) { var currentSheet = currentGrade.sheets[k]; sheetsAndRolls.push(currentStock.name + "/" + currentGrade.name + "/" + currentSheet.name); } for (var r = 0; r < currentGrade.rolls.length; r++) { var currentRoll = currentGrade.rolls[r]; sheetsAndRolls.push(currentStock.name + "/" + currentGrade.name + "/" + currentRoll.name); } } } sheetsAndRolls.join(";");
Color Science & Workflow Automation