loader

For this tutorial in video form, click here

Want to extract data from external services? The first way to do this is by using a simple GET or POST request to retrieve the data.

Get ID

What is a GET request? It’s essentially the same as typing in your URL in the browser. Consider the example below:

If you put this into your URL, you’ll get some JSON back:

JSON is a common data format used by many APIs. It’s quite useful because in Deluge you can use toJSONList() to transform the data into a deluge list. Here’s an example:

With the “userID”, we’ve put in a bunch of userIDs:

The key thing to remember here is that we’re using result = getUrl in our source code.

PostID

What’s the difference between GET & POST? POST is normally used to make changes to data whereas GET gives you the data in read only mode. For example, if we open a network tab and then click “save script” in the Deluge editor, you’ll see a request using POST which saves the new version of the script:

The advantage of POST is that it’s more secure. If you’re transmitting data to an external API you don’t want your internet service provider (or whoever can see the packets on your computer) to know what your password or medicare number is. You can technically transmit data via GET but anyone who’s between you and the server can see everything you’ve sent.

Conclusion

As a summary, the key difference here is that getUrl is used when you want to retrieve data, and you don’t have any concern about someone knowing what data you’re trying to receive. Post data is when you’re making changes to data or sending confidential data.

The service you’re integrating with will dictate what API method you should use. Let’s say you wanted to get tweets from Twitter. On their API reference page, it tells you the HTTP method (e.g. GET oauth/authenticate uses a GET request whereas POST oauth2/token uses POST).

We hope this tutorial helped, and we look forward to teaching you more in the future!

For this tutorial in video form, click this link