Documentation

Automate your tasks with API calls

sshreach.me allows you to automate your tasks by using API calls.

There are two API call commands: connect and disconnect

The endpoint for API calls is the following: https://sshreach.me/init/api/API_CALL where API_CALL stands for the actual API command.

API commands require additional parameters. You can get the API call scaffolding with parameters by clicking on copy icon in the API CALL column on Script tab which will get you something like this:

https://sshreach.me/init/api/API_CALL?dbid=S3iusSD710sLLaa92Ka2&host_uuid=8s0ss21z-9a11-s810-s17l-sf91lksdf878&ports_id=5621&user_id=1234

You need is to replace the API_CALL with the actual connect or disconnect command.

API calls return the following json:

{"message": "OK", "error_code": 0, "success": true}

The values can be the following:

success: true if api call succeded, otherwise false

message: "OK" or error description

error_code:

    00 - ok
    11 - not connected
    12 - not disconnected
    21 - invalid api call
    22 - Too many API calls
    23 - Client blocked
    24 - Client inactive
    31 - Wrong data

Examples

bash:

   #!/bin/bash
   # open a tunnel to the remote machine
   result=$(curl 'https://sshreach.me/init/api/connect?dbid=Bad9alsdS920a11-Aqj2&host_uuid=20sldd20-20sz-aa20-aa02-aa0salskd82a&ports_id=1234&user_id=12345' | jq -r '.success')
   if [ "$result" = "true" ]; then
	# execute remote command
	ssh -p 12345 -i IDENTITY_FILE username@fw1.sshreach.me ls
	# and close the tunnel
	curl 'https://sshreach.me/init/api/disconnect?dbid=Bad9alsdS920a11-Aqj2&host_uuid=20sldd20-20sz-aa20-aa02-aa0salskd82a&ports_id=1234&user_id=12345'
else
	echo "error message goes here"
   fi

python:

  import urllib2
  import paramiko
  import json

  api_endpoint = 'https://sshreach.me/init/api/{0}?dbid=Bad9alsdS920a11-Aqj2&host_uuid=20sldd20-20sz-aa20-aa02-aa0salskd82a&ports_id=1234&user_id=12345'

  # open the tunnel
  json_result = json.loads(urllib2.urlopen(api_endpoint.format('connect')).read())

  if json_result['success'] == True:

	# prepare an ssh client
	client = paramiko.SSHClient()
	client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

	# connect to your server
	client.connect('fw1.sshreach.me', port=12345, username='username',
		key_filename='path_to_your_key_filename')

	# execute a remote command
	stdin, stdout, stderr = client.exec_command("ls")
	if not stderr.readlines():
		for line in stdout.readlines():
			print line
	else:
		# report error
		pass

	client.close()

	# close the tunnel
	json_result = json.loads(urllib2.urlopen(api_endpoint.format('disconnect')).read())

	if json_result['success'] != True:
		# report error if tunnel wasn't closed
		pass
  else:
	print json_result['message']