In the series Advanced Scripting Sample Apps we explain some use cases on how to use the Advanced Scripting. For more general info, it's very important that you read this KB-article first.
Use Case
In this example, we show how to use the twxhttp
functions. These allow you to make requests to external websites to obtain information from there. Very handy to get info from internal company-tools, e.g. if your Twixl app is a sales tool!
Instructions
Preparations
- Create a new app
- Set up your Advanced Scripting (see below)
- Run the app in the Twixl app and then go to the Gear menu > Advanced Filter Log to see the log messages.
- For the Browser Client, open the root collection, append
?debug=1
to the url and you'll see the debug icon in the toolbar.
Advanced Scripting Settings
For the Root Collection:
// Executed once for every collection before the filtering of the items function setupFilter(collection, environment) { // Get a HTTP client var client = twxhttp.NewClient(); // Get the text from a url var textURL = "https://demo.twixlmedia.com/advanced-scripting/sample.txt"; var textResponse = client.Get(textURL); twxlog.Info("Text output: " + textResponse.ToString()); // Get JSON from a url var jsonURL = "https://demo.twixlmedia.com/advanced-scripting/sample.json"; var jsonResponse = client.Get(jsonURL); twxlog.InfoDump(jsonResponse.ToJSON()); // Using the status code var badURL = "https://demo.twixlmedia.com/advanced-scripting/sample.invalid"; var badResponse = client.Get(badURL); twxlog.Info("Status code: " + badResponse.StatusCode()); // HTTP Post var postURL = "https://demo.twixlmedia.com/advanced-scripting/post.php"; var postResponse = client.PostForm(postURL, {"name": "Twixl media", "product": "Twixl Publisher"}); twxlog.Info("Post output: " + postResponse.ToString()); // HTTP Raw Post var rawURL = "https://demo.twixlmedia.com/advanced-scripting/post_json.php"; var rawResponse = client.PostRaw(rawURL, "application/json", '{"name": "Twixl media", "product": "Twixl Publisher"}'); twxlog.Info("Raw Post output: " + rawResponse.ToString()); } // Executed for once for every collection function shouldShowCollection(collection, environment) { return true; } // Executed for every single content item function shouldShowItem(contentItem, collection, environment) { return true; } // Executed once for every collection after the filtering of the items function teardownFilter(collection, environment) { }