The MotorBase Application Programming Interface is simply a way to access MotorBase data, one that makes it easy for third-party and custom tools to programatically access and interact with our services.The API follows the REST style, and this guide should provide everything you need to implement software that works with MotorBase.
The Terms of Service covers the acceptable use of the API (along with the rest of the site). Beyond the legalities, please design your programs to use the MotorBase API considerately—cache as much as possible, limit the frequency of your requests, and include a User-Agent header in your requests. If you find a problem with the API, please give us a chance to correct it. If you have any questions or issues, feel free to contact support@motorbase.com.
The MotorBase REST APIs provide access to resources (data entities) via URI paths. To use a REST API, your application will make an HTTP request and parse the response. The format for both request and response is JSON. Your methods will be the standard HTTP methods like GET, PUT, POST and DELETE.
The REST API is based on open standards, so you can use any web development language to access the API. We have detailed examples on how to access our API; see the Try the API! page for details.
All API requests require that you have a MotorBase account in the host, just like when you access a site through a browser. Login is done with HTTP Basic Authentication. For example, using the cURL command line program:
curl -i http://testco.motorbaseonline.com/api/v1/login -H "Content-Type: application/json" -X POST -d '{"username" : "test", "password" : "test"}'
Note: if you're using Windows, you must always use double quotes and the inner quotes must be escaped: "{\"username\" : \"test\", \"password\" : \"test\"}".
As a result, the authentication response will include an ACCESS TOKEN which you must include in each subsequent request header, in all future calls for a given session.
curl -i http://testco.motorbaseonline.com/api/v1/asn/12345 -H "x-access-token: 9T9h9WY00wzKXIktG7Sndg" -H "Content-type: application/json"
Notice in the example above the request was made using "HTTP" and not "HTTPS" (encrypted). The reason is that the sample URL is pointing to our "mock" (test) server simply for you to test the API functionality. When pointing to our production servers, the protocol will be HTTPS (SSL).
All HTTP response codes are wrapped and included in the HTTP code response property (see below). Possible status codes include:
200: Success (upon a successful GET, PUT, or DELETE request)
201: Created (upon a successful POST request)
400: Resource Invalid (improperly formatted request)
401: Unauthorized (incorrect or missing authentication credentials)
404: Resource Not Found
405: Method Not Allowed
406: Not Acceptable
500: Application Error
With the many myriad response code in the HTTP spec, often there are only a few that clients care about, frequently boiling down to "success", "error", or "failure". As a result, the MotorBase API wraps all responses in a representation that contains the following properties:
code - contains the HTTP response status code as an integer
status - contains the text SUCCESS, FAIL, or ERROR. Where:
FAIL - is for HTTP status response values from 500-599
ERROR - is fore statuses 400-499 and
SUCCESS - is for everything else, e.g., 1xx, 2xx and 3xxx responses.
message - this field is optional and it may contain a brief explanation about the response. For internationalization purposes (i18n), this may contain a message number or code (TBD).
data - contains the response body. In the cases of ERROR or FAIL statuses, this contains the cause, and the exception name.
A successful response would look similar to this:
{"code" : 200,
"status": "SUCCESS",
"message": "Successful authentication."
"data" : {"token" : "4frt43523423dfdfg26f" }
}
An example error response could look like this:
{"code" : 403,
"status" : "ERROR",
"message" : "Failed to authenticate token.",
"data" : {"exception" : "UnauthorizedException"}
}
The service described below -- the operation, data contract, and error codes -- is what Spring Point is proposing as means of exchanging information between MotorBase and the Vendor services for submitting Purchase Orders. Notice that MotorBase will not be hosting this service in production, as this is to be done by you, the vendor. However, we created a mock server for you to test it and see how this service works.
Questions or comments
Roger Kepler
crkepler@yahoo.com