//php print_r($this); ?>
Contents |
Overview
The MosoMRM API is implemented and consumed as a RESTful (Representational State Transfer) service. This makes our API different from other SOAP/RPC based APIs that you may be used to invoking. We’ve chosen the RESTful approach to maximize our compatibility with other systems and to minimize the hurdles to interfacing with the API. Before we get into some real life examples that you can experience right now, first we need to cover some basics.
The Basics
In order to utilize our API, or to view the associated documentation, you must first be authenticated against one or more MosoMRM instances (why?...See FAQ #1). This means you’ll need the following items before continuing:
- Your MosoMRM site URL e.g. https://demo20.mosocloud.com/.
- A set of credentials consisting of a Username and Password combination.
- An Endpoint Key to identify the terminal from which you are logging-in. (In the MosoMRM User Interface, this is referred to as a “Workstation Id” and it will also display this way on the Log-In screen.
If you do not have all 3 of the items above, please contact your account representative to request a sandbox account.
Viewing the API Reference Documentation
Once you have the basic information discussed above, point your web browser to: https://demo20.mosocloud.com/api/1.0/. You will be prompted to Log-In, and after doing so you will be directed to the documentation page. This documentation is generated by our servers in real-time from the current build of the application, ensuring that you are always viewing the most up-to-date version of the documentation.
Authenticating to the API
The first step in our journey through the API is to utilize your assigned credentials to authenticate yourself and authorize the API services you will be utilizing. The result of your authentication will be an AuthToken. Once you have a valid AuthToken, you can identify yourself in every subsequent call using only this token, avoiding the need re-send your credentials.
The easiest way to authenticate is to simply Log-In using your browser (see Viewing the API Reference Documentation). Using a browser Log-In will give you access to the API within the context of your current browser window. If you want to Log-In without having to invoke the application UI, you may do so by requesting the following URL (see https://demo20.mosocloud.com/api/1.0/#SessionStart) using your preferred HTTP client (we’ll use CURL for our examples):
curl –k “[https://demo20.mosocloud.com/api/1.0/session/?username={USERNAME}&password={PASSWORD}&endpointkey={ENDPOINTKEY}]"
If successful, the response will appear with the following structure:
JSON { "Result": { "Control": { "ErrorCode": 0, "Message": "SUCCESS" }, "Data": { "String": "5afe51b6-2fca-4a68-90ed-cc11ed415a4d" } } }
XML <Result> <Control> <ErrorCode>0</ErrorCode> <Message>SUCCESS</Message> </Control> <Data> <String>8fd9d213-c5e4-4664-b495-d93845a87afa</String> </Data> </Result>
Let’s take a moment to dissect the data we just received. You’ll notice that there are two formats, JSON and XML. You may choose to utilize either format when interfacing with the API, and while it is perfectly valid to switch formats between each request, you should note that every request/response pair will be read and sent back to you in the same format. To choose the format you want to work with, you must include a Content Type header in your request packet.
- To use XML, set the Content Type to “text/xml”.
- To use JSON use “application/json”. The default format will always be JSON when no Content Type is specified.
The structure of the response will be consistent for every API service and consists of a Result root node, a Control child node, and a Data child node.
- The Control node contains an ErrorCode and a Message node.
- The Data node will contain various other entities ranging from primitive types, like the AuthToken, to complex data types with multiple descendants and other types.
Success and Failure Codes
If all goes well with your API call, the response will contain an ErrorCode of “0”. In this case, the "Message” will also always be “SUCCESS”. If an error occurs, the ErrorCode will be an HTTP status code, most likely "500" (application error), and the error message will contain information related to the error.
Requesting Information Using the API
When you use the API to retrieve information, this is called a “GET” request in HTTP parlance. This is the easiest method to use when calling our API making it perfect for our first example:
Let’s "get" a list of Business Units (https://demo20.mosocloud.com/api/1.0/#BusinessUnitsGet).
Request:
curl –k “https://demo20.mosocloud.com/api/1.0/businessunits/?authtoken={AuthToken}”
- Note: If your HTTP client can accept cookies, you wont have to specify the "AuthToken" param in the request.
To retrieve a single Business Unit, the request would simply specify the id:
curl –k “https://demo20.mosocloud.com/api/1.0/businessunits/1
Response:
{ "Result": { "Control": { "ErrorCode": 0, "Message": "SUCCESS" }, "Data": { "BusinessUnit": { "TimeZoneName": "US/Eastern", "BatchMerchantAccountCode": 2001, "DivisionId": 2, "Name": "Silver Spring", "Code": "100", "Description": "", "Sequence": 0, "InActive": false, "GLCodePrefix": "100", "PermissionInherited": false, "PrimaryContactInfo": { "BusinessUnitId": 0, "ContactInformationType": 0, "Address1": null, "Address2": null, "Address3": null, "City": null, "StateProvinceId": null, "PostalCode": null, "CountryId": null, "PhoneNumber1CountryCode": null, "PhoneNumber1": null, "PhoneNumber1DialingInfo": null, "PhoneNumber2CountryCode": null, "PhoneNumber2": null, "PhoneNumber2DialingInfo": null, "FaxNumberCountryCode": null, "FaxNumber": null, "FaxNumberDialingInfo": null, "EmailAddress": null, "WebsiteUrl": null, "AggregateResourceName": 154, "ObjectId": "00000000-0000-0000-0000-000000000000", "ResourceHandle": null, "ID": 0, "HasSecurityContext": false, "SecurityContext": null }, "ObjectId": "cada8073-c26a-4524-b62f-cadba670b415", "ID": 1, . . .
Frequently Asked Questions
Why must I be logged in to view the API documentation?
- Just like the application itself, our API is tailored for the individual user. This means that different users will be able to see and access different parts of the API. That’s why we need to know who you are before you can interface with the API.