Using Postman during development

I use a great (free) program called Postman which does an excellent job of rapidly prototyping new APIs as well as learning to use someone else's.

I also use it in cases like today where I want to determine if OctoPrint will pass through an artificial GCODE command which is typical of the Gcode Systems Command plugin... or if OctoPrint removes these from the serial stream.

Using Postman

First, you'll need to download the software. For OSX, it's good then to drag it into your Applications folder. For the first time running it you should Ctl-Click the icon and select Open so that your Mac will trust it.

Ignore the first wizard, closing it so that you can see the main screen.

  1. In the unmarked Method pull-down selection, choose POST in this case
  2. Click the Headers tab and add a new field called X-Api-Key and for the value, insert the API key you'll find in OctoPrint -> Settings -> API
  3. In the unmarked URL field to the right of method, type in this endpoint:
http://octopi.local/api/printer/command
  1. Click the Body tab, select the Raw radio button and in the pull-down selector to the right, select JSON
  2. In the large unmarked textarea below this, type this:
{
    "command": "OCTO801"
}
  1. Make sure that your printer is on and you've clicked the Connect button in the Connection side panel of OctoPrint
  2. Back in Postman, press the Send button

It may not look promising, but you're hoping for:

  • nothing in the unmarked Response textarea at the bottom
  • a Status of 204 NO CONTENT from OctoPrint

In this case, OctoPrint will not tell you that you don't have this particular command. The 204 status is its way of saying that it heard you and it's sent it. In my case, my printer will play a particular audio file so I know that it's working as expected. So it only took me a moment to answer my original question; OctoPrint passes the command through.

Likewise, you could use Postman to query the list of files available (assuming that you're still in Postman and you still have that header information intact).

  1. change the Method to GET
  2. change the URL to http://octopi.local/api/files
  3. press the Send button

The Status this time should be 200 OKAY and the Response textarea should contain a JSON-formatted list.

If you're a coder, you'd see that files[0].name would be what you're usually after in that JSON response for the first filename.

2 Likes