Skip to content
TORNLIFE More

[Guide] Testing API endpoints using Bruno

Started by Glasnost [1844049] on in Tools & Userscripts.

1 replies · 80 views · thread synced · 4 days ago · View on torn.com
About this thread

Posts archived: 2 / 2 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
2
Discussion span
→
People posting
2
Likes on archived posts
12
Authority score
34 / 100
Historical score
14 / 100
Story score
29 / 100
Engagement score
46 / 100
Glasnost [1844049]

Staff: I am aware this is a guide, but this forum is heavily concentrated for people who use the API and develop tools, so it may technically belong in another section, but like the suggestions topic here, I ask it remains in the Tools & Userscripts section where it seems more relevant.

 

So I have recently been asked similar-ish questions by several people lately, and have recommended the use of a tool called Bruno for looking at the API endpoints available. To save myself the job of repeating instructions each time, and it may be of use to others, dumping a brief guide here on using it.

 

I won't be exploring all features of Bruno here, only a brief guide mainly to make people aware it exists, and how to import the OpenAPI specification in.

 

1. Download Bruno

 

First, download it from the official source: https://www.usebruno.com/

 

The free version is all you need. Download and install it as per the instructions on the website.

 

 

2. Import the OpenAPI Spec of the Torn API

 

You can find the OpenAPI spec for Torn on the swagger page: https://www.torn.com/swagger.php

 

At present, this is: https://www.torn.com/swagger/openapi.json

 

Copy this URL, and in Bruno, click the three dots in the top left and select "Import Collection"

 

[image: uploads.glasnost.dev]

 

 

 

Now select the "OpenAPI V3 URL" option, enter the OpenAPI spec URL retrieved earlier, and hit import.

 

[image: uploads.glasnost.dev]

 

 

Choose a location on disk to save the collection to - it does not matter where you save it generally speaking, but I prefer to keep them in the documents directory in their own "Torn" sub-folder to keep it separate from my work and other projects.

 

 

Javascript Sandbox Warning

 

If this pops up, it is best left to "Safe Mode" unless you have reason to change this. If you need to ask if you should change it, you do not need to change it.

 

[image: uploads.glasnost.dev]

 

 

 

You should now have the requests imported and show in the Bruno menu, like so:

 

[image: uploads.glasnost.dev]

 

 

 

3. Setup your variables

 

If you look at the requests, you will see instances of {{baseUrl}}, which is a variable used. You want to set this URL across all requests, since they are going to the Torn API.

 

Find the collection in the Bruno menu, and click the 3 dots, and go to "Settings":

 

[image: uploads.glasnost.dev]

 

 

 

Navigate to the "Vars" sub-menu, create a "Pre Request" called "baseUrl" and set the value to "https://api.torn.com/v2", and click "Save" like below:

 

[image: uploads.glasnost.dev]

 

 

 

Setup Variables for your API Key Levels [Optional but recommended]

 

So, to save yourself constantly entering certain API keys, setup further variables for a key of each level, creating the appropriate key level in settings and entering them here in place of the "enter your API key here" text.

 

[image: uploads.glasnost.dev]

 

 

This means when you make a request, instead of filling in the "key" box with your actual API key, you can use a variable like the below. This is useful if you want to rotate API keys or change the level of the key being used easily.

 

[image: uploads.glasnost.dev]

 

 

 

4. Make your first request

 

Now, you are set. Head to the request you want to make, in my case I have chosen to get the basic profile information.

 

In the "key" field, enter the API key you wish to use, or if you followed my recommended step earlier to use variables, enter {{publicKey}} or the name you set it up under. I use variables, so this is how it looks to me. Press the "->" button to make the request.

 

[image: uploads.glasnost.dev]

 

 

 

Conclusion

 

That is pretty much it. Honestly, a few minutes of setup here can save you a lot of time later on. Have a play around with it and get familiar with how the tool works, there are lots of similar tools out there such as Postman, but Bruno is open source and has less restrictions or other weirdness about it. It's open source, and it just works, perfect for developing on Torn.

 

As you progress, you can see how to save custom requests you are making, add more variable for custom key types and more. If you are making a project, I always recommend saving those requests to a specific sub-folder, it makes diagnosing any format changes a whole load easier, and maintains the original API specification.