Now that you have obtained an authentication token for the MIP Advance REST API, your next step is to learn how to use it. Most methods in the MIP Advance API require a current authentication token. In this tutorial we demonstrate how to include the token in your API requests.
Your authentication token expires after a period of inactivity, usually ten minutes. If your token expires, your subsequent API calls with that token will fail with a status code of 401 (Unauthorized). To continue working with the API, you must submit another login request to obtain a new token.
Please be aware that the sample code is simplified for clarity, and should be used for learning purposes only.
Type the following code into your text editor, substituting the URL of your on-premises API service for [[REST_URL]], and your authentication token for [[YOUR_TOKEN]]. For example, a default on-premises installation might have the URL "http://localhost:9001", so that line 7 below would be 'url:"http://localhost:9001/api/te/jv/sessions"', and the authentication token is a long alphanumeric string such as "DF42AC8DD76C2EAADCABC3EE2BD5AD56".
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <script> $.ajax({ method: "GET", url: "[[REST_URL]]/api/te/jv/sessions/ids", headers: {"Authorization-Token": "[[YOUR_TOKEN]]", "Accept": "application/json"}, success: function (data, status) { alert(JSON.stringify(data, undefined, 2)); }, error: function (data, status) { alert("Unable to read segment information; please contact your system administrator."); } }); </script> </head> </html>
Save the code as jvsessionslist.html
.
Open the new file in your web browser. When the request completes, you should see an alert box containing an array of the ids of all unposted Journal Voucher sessions.
As in the previous tutorial examples, we specify the URL and the HTTP verb ("GET"). Because this API call requires authentication, we included our authentication token as the value of the "Authorization-Token" header. We also included the optional header "Accept" with a value of application/json, indicating that our code expects a JSON response. (This is not required, as the Advance REST API always returns a JSON object when output is requested; we have included it in order to show the syntax of a request with multiple headers.)
The response to your HTTP request includes a status code and (if the request was successful) an array of session ID numbers.