+ - 0:00:00
Notes for current slide
Notes for next slide

SoftLayer API

How it works, and what to do when it doesn't

Christopher Gallo, Senior API Developer

1 / 21

Anatomy of an API Call

The SoftLayer API has two main urls to send requests to.

Only big difference is the SoftLayer_Resource_Metadata service only exists on the private network API.

2 / 21

Specify the endpoint type and version

api.softlayer.com/rest/v3.1

Types

  • REST
  • SOAP
  • XMLRPC

Versions

  • v3
  • v3.1 (Includes the SoftLayer_Search service, and some objectMask improvements)

3 / 21

API is broken down into "Services", which contain a collection of methods that perform some action.


api.softlayer.com/rest/v3.1/SoftLayer_Service


Data returned by the API is broken down into "Datatypes". Services usually have a matching datatype, but not all datatypes have a matching service.


4 / 21

5 / 21

Methods tell the API which action to actually run in a class/service.

api.softlayer.com/rest/v3.1/SoftLayer_Service/ method

$ curl -s -u $SL_USER:$SL_APIKEY \
'https://api.softlayer.com/rest/v3.1/SoftLayer_Account/getObject.json'
{"accountManagedResourcesFlag":false,"accountStatusId":1001,"address1":"4849 Alpha Rd","allowedPptpVpnQuantity":0,"brandId":2,"city":"Dallas", LOTS OF DATA}

For XML and SOAP requests, the method, and all other parameters will go into the request payload envelope.

6 / 21

Some methods require an InitParamter, listed in the documentation. For REST calls, this goes between the Service and Method. For SOAP/XML requests, this is set in the header.

api.softlayer.com/rest/v3.1/SoftLayer_Service/ initParameter/method

$ curl -s -u $SL_USER:$SL_APIKEY \
'https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/100317048/getObject'
{"accountId":307608,"createDate":"2020-04-07T04:01:49-06:00","dedicatedAccountHostOnlyFlag":false,"domain":"chechu.com", OTHER DATA}

The documentation for this API method says it requires a SoftLayer_Virtual_GuestInitParameters header, which means we need to send in a Virtual Guest id as the init parameter. If you get a 404 error on these sort of API calls, check your user has access to the resource, and the resource is active. Cancelled resources are usually not available from the API.

7 / 21

curl -u $SL_USER:$SL_APIKEY -X POST \
-d '{"parameters": [{"hostname": "testingEdit"}]}'
'https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/999999999/editObject.json'
8 / 21

You can control the format of the returned data by adding .FORMAT to the end of the URI for REST requests. XML requests will return XML data, SOAP requests will return SOAP data.

api.softlayer.com/SoftLayer_Service/ initParameter/method.json

Available formats

  • json (default for REST)
  • txt
  • xml
9 / 21

Authentication

  1. Classic API Key:
    • 64 Characters, associated with a SoftLayer user (Your VPN username in the cloud.ibm.com portal)
  2. Cloud.ibm.com:
    • API Key 32 Characters, associated with an IBMid account
  3. Token from Username / Password:
    • Temporary, associated with a SoftLayer user
  4. Bearer Token:
    • Temporary, retrieved from the IBMCloud IAM service

Read Authenticating to the SoftLayer API for full details.

10 / 21

Metadata service

SoftLayer_Resource_Metadata

  • Only useable on the https://api.service.softlayer.com endpoint.
  • No authentication needed.
  • Only provides basic information about the resource making the API call
    • getUserMetadata()
    • getTags()
    • getHostname()
    • getDatacenter
    • etc...
11 / 21

API Errors

  1. Authentication Headers not found
    • Make sure your authentication headers are correctly being sent.
  2. SoftLayer_Exception_ObjectNotFound (404)
    • Make sure the user making the API request has access to the resource
    • Make sure the resource exists, and hasn't been cancelled
  3. SoftLayer_Exception_Public Internal Error
    • Requesting too much data can result in this error. Try removing some items from the objectMask or a resultLimit
    • Some other unexpected error happened.
  4. SoftLayer_Exception_WebService_BadRequest
    • The API was not able to parse your request. Make sure there are no odd characters or mismatching brackets.
12 / 21

XML Example

$ curl -d @SoftLayer_Account-getObject.xml https://api.softlayer.com/xmlrpc/v3.1/SoftLayer_Account
SoftLayer_Account-getObject.xml
<?xml version='1.0' encoding='iso-8859-1'?>
<methodCall>
<methodName>getObject</methodName>
<params>
<param><value><struct><member>
<name>headers</name>
<value><struct><member>
<name>authenticate</name>
<value>
<struct>
<member><name>username</name><value><string>SL123456</string></value></member>
<member><name>apiKey</name><value><string>APIKEYGOESHERE</string></value></member>
</struct>
</value>
</member>
<member>
<name>SoftLayer_ObjectMask</name>
<value><struct>
<member><name>mask</name><value><string>mask[id,companyName]</string></value></member>
</struct></value>
</member></struct></value>
</member></struct></value></param>
</params>
</methodCall>
13 / 21

XML Response

<?xml version="1.0" encoding="utf-8"?>
<params>
<param>
<value>
<struct>
<member>
<name>companyName</name>
<value><string>SoftLayer Internal - Development Community</string></value>
</member>
<member>
<name>id</name><value><int>307608</int></value>
</member>
</struct>
</value>
</param>
</params>
14 / 21

SOAP Example

curl -d @soapAccountGetObject.soap https://api.softlayer.com/soap/v3.1/SoftLayer_Account
soapAccountGetObject.soap
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.softlayer.com/soap/v3.1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns1:authenticate xmlns:ns1="http://api.service.softlayer.com/soap/v3.1/">
<ns1:username>SL123456</ns1:username>
<ns1:apiKey>APIKEYGOESHERE</ns1:apiKey>
</ns1:authenticate>
<ns1:SoftLayer_ObjectMask>
<mask>mask[id,companyName]</mask>
</ns1:SoftLayer_ObjectMask>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getObject/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
15 / 21

SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.softlayer.com/soap/v3.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getObjectResponse><getObjectReturn xsi:type="ns1:SoftLayer_Account"><companyName xsi:type="xsd:string">SoftLayer Internal - Development Community</companyName><id xsi:type="xsd:int">307608</id></getObjectReturn></ns1:getObjectResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
16 / 21

REST Example

Basic Template

$> curl -u [username]:[apiKey] \
-d '{"parameters": ["first", "second"]}' \
https://api.[service.]softlayer.com/rest/v3.1/[serviceName]/[initializationParameter]/[methodName]?
objectMask=mask[]&
objectFilter={}
&resultLimit=[offsetValue],[limitValue]

Real Example

$> curl -u $SL_USER:$SL_APIKEY 'https://api.softlayer.com/rest/v3.1/SoftLayer_Account/getObject.json?
objectMask=mask%5Bid%2CcompanyName%5D'
{"companyName":"SoftLayer Internal - Development Community","id":307608}

line breaks added for readability only

17 / 21

Simple API calls with CLI tools

SLCLI

https://github.com/softlayer/softlayer-python

$ slcli call-api --help
Usage: slcli call-api [OPTIONS] SERVICE METHOD [PARAMETERS]...
$ slcli call-api SoftLayer_Account getObject --mask="mask[id,companyName]"
:.............:............................................:
: name : value :
:.............:............................................:
: companyName : SoftLayer Internal - Development Community :
: id : 307608 :
:.............:............................................:
18 / 21

IBMCLOUD SL

https://www.ibm.com/cloud/cli

$ ibmcloud.exe sl call-api --help
USAGE:
ibmcloud.exe sl call-api SERVICE METHOD [OPTIONS]
$ ibmcloud.exe sl call-api SoftLayer_Account getObject --mask="mask[id,companyName]"
{
"companyName": "SoftLayer Internal - Development Community",
"id": 307608
}
19 / 21

API Gotchas

  • Sending in method parameters requires the following format for REST requests
    {"parameters": ["first", {"second_is_object":{"id":1234}}]}
  • Paramters are NOT NAMED in the request, they go in order as listed on sldn.softlayer.com
  • XMLRPC returns integers as signed 32 bit, so some large numbers might overflow
  • Adding a LOCAL property to an object mask removes all default properties
  • Its very easy to request too much data from the API. Be mindful of how many properties you are asking for in a single request.
  • Its better to make a lot of small API requests than one large request.
20 / 21

The End

for more detailed information and documentation

https://sldn.softlayer.com/article/

21 / 21

Anatomy of an API Call

The SoftLayer API has two main urls to send requests to.

Only big difference is the SoftLayer_Resource_Metadata service only exists on the private network API.

2 / 21
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow