Chris Walls

Using SamanageAPI.rb with Ruby

Discussion created by Chris Walls Administrator on Aug 5, 2015

The following scripts are provided by Samanage as examples and training purposes only and not designed to work in every use case without some modification to the script itself. These scripts are not supported by Samanage as part of your Samanage Master Subscription Agreement, however if you would like this script customized to support your use case, please contact us at API.Scripts@samanage.com for a personal quote.

 

SamanageAPI is a simple Ruby file that provides a simple platform for working with the Samanage API.

 

https://github.com/SAManage/Samples/tree/master/SamanageAPI#how-to-use

How to use

SamanageAPI is a ruby Class that allows you to easily generate API calls to Get/Post/Put items into Samanage by passing a path, email, user and optional data as arguments. To begin using this function, simply require SamanageAPI.rb in your ruby script.

require_relative 'SamanageAPI.rb'

https://github.com/SAManage/Samples/tree/master/SamanageAPI#getting-data-from-samanage

 

Getting data from Samanage

Example: To 'get' users

users = SamanageAPI.get("users.xml", "email@company.com","password")

When successful users will contain hash with the following keys:

 

https://github.com/SAManage/Samples/tree/master/SamanageAPI#creating-user-in-samanage

 


Creating user in Samanage

email = "api.user@company.com"
pass = "password"
xml = "John Doejohn.doe@company.com"
call = SamanageAPI.post("users.xml", email, pass, xml)

Updating users in Samanage

xml = "value"
call = SamanageAPI.put("users/USER_ID.xml", email, pass, xml)

When correct information is entered call["success"] should be set to true and call["code"] will return 201 (Created)

Outcomes