Accessing the REST API
Pass-through access
Do the following to access the REST API through a web application endpoint:
- Log in to iMIS.
- Retrieve the verification token from the page. The token is stored in a hidden field with the element ID RequestVerificationToken.
- Compose an HTTP Web Request.
- Add the token to your request header as RequestVerificationToken.
- Complete the request.
Using developer tools and jQuery
Do the following to access the REST API using only a browser with developer tools and jQuery:
- Open a browser.
- Log in to iMIS.
- Open the developer console and enter a request. If the request is correct, a response in the form of a JSON object is received from iMIS.
jQuery.ajax("https://YourImisUrlHere/api/party/101", {
type: "get",
contentType: "application/json",
headers: {
"RequestVerificationToken": document.getElementById("__RequestVerificationToken").value
},
success: function (data) {
console.log(data);
}
});
var request = new XMLHttpRequest();
var promise = new Promise(function (resolve, reject) {
// open and send
request.open('get', 'https://YourImisUrlHere/api/party/101');
// attach RequestVerificationToken header to request object
request.setRequestHeader("RequestVerificationToken",
document.getElementById("__RequestVerificationToken").value);
// add listener to request object
request.onload = function () {
// This is called even on 404s, etc.
// so check the status
if (request.status === 404) {
reject(Error(request.statusText));
} else {
// Resolve the promise with the response text,
// log to the console for debugging purposes
var response = request.response;
resolve(response);
console.log(response);
}
};
// Handle network errors
request.onerror = function () {
reject(Error("Network Error"));
};
request.send();
});
The following expected response is received from iMIS:
{
"$type":"Asi.Soa.Membership.DataContracts.ComboPartyData, Asi.Contracts",
"BirthDate":"1953-08-19T00:00:00",
"Gender":0,
"OrganizationName":"Prodigy Makers International",
"PersonName":{
"$type":"Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Contracts",
"FirstName":"Douglas",
"InformalName":"Doug",
"LastName":"Hunt",
"MiddleName":"A.",
"NamePrefix":"Mr.",
"NameSuffix":"Jr.",
"FullName":"Mr. Douglas A. Hunt, Jr."
},
"PrimaryOrganization":{
"$type":"Asi.Soa.Membership.DataContracts.PrimaryOrganizationInformationData, Asi.Contracts",
"Name":"Prodigy Makers International",
"Title":"President"
},
"AdditionalAttributes":{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"CustomerTypeDescription",
"Value":"Company Member"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"IsMemberRecord",
"Value":{
"$type":"System.Boolean",
"$value":true
}
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"CustomerTypeCode",
"Value":"CM"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"IsMember",
"Value":{
"$type":"System.Boolean",
"$value":true
}
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"IsInactiveMember",
"Value":{
"$type":"System.Boolean",
"$value":false
}
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"AllowAdvanceRenewal",
"Value":{
"$type":"System.Boolean",
"$value":false
}
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"JoinDate",
"Value":"1968-08-28T00:00:00"
}
]
},
"Addresses":{
"$type":"Asi.Soa.Membership.DataContracts.FullAddressDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Membership.DataContracts.FullAddressData, Asi.Contracts",
"AdditionalLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
]
},
"Address":{
"$type":"Asi.Soa.Membership.DataContracts.AddressData, Asi.Contracts",
"AddressId":"1",
"AddressLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
"P.O. Box 4564"
]
},
"CityName":"Newark",
"CountryCode":"US",
"CountryName":"United States",
"CountrySubEntityCode":"NJ",
"CountrySubEntityName":"New Jersey",
"FullAddress":"P.O. Box 4564\rNewark, NJ 07107-2564\rUNITED STATES",
"PostalCode":"07107-2564",
"VerificationStatus":0
},
"AddresseeText":"Prodigy Makers International\r\nP.O. Box 4564\rNewark, NJ 07107-2564\rUNITED STATES",
"AddressPurpose":"Address",
"CommunicationPreferences":{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceData, Asi.Contracts",
"Reason":"default"
},
{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceData, Asi.Contracts",
"Reason":"mail"
},
{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceData, Asi.Contracts",
"Reason":"bill"
},
{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceData, Asi.Contracts",
"Reason":"ship"
}
]
},
"Email":"[email protected]",
"Fax":"(201) 898-4255",
"FullAddressId":"1",
"Note":"P.S.I. Code 9450",
"Phone":"(201) 898-9000",
"Salutation":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"main"
},
"Text":"Prodigy Makers International"
},
"DisplayName":"Doug",
"DisplayOrganizationTitle":"President",
"DisplayOrganizationName":"Prodigy Makers International"
},
{
"$type":"Asi.Soa.Membership.DataContracts.FullAddressData, Asi.Contracts",
"AdditionalLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
]
},
"Address":{
"$type":"Asi.Soa.Membership.DataContracts.AddressData, Asi.Contracts",
"AddressId":"2",
"AddressLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
"115 Franklin Avenue",
"Suite 256"
]
},
"Barcode":"/710101/",
"CityName":"Newark",
"CountrySubEntityCode":"NJ",
"FullAddress":"115 Franklin Avenue\rSuite 256\rNewark, NJ 71010",
"PostalCode":"71010",
"VerificationStatus":0
},
"AddresseeText":"Prodigy Makers International\r\n115 Franklin Avenue\rSuite 256\rNewark, NJ 71010",
"AddressPurpose":"Street Address",
"CommunicationPreferences":{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceDataCollection, Asi.Contracts",
"$values":[
]
},
"FullAddressId":"2",
"Salutation":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"main"
},
"Text":"Prodigy Makers International"
},
"DisplayName":"Doug",
"DisplayOrganizationTitle":"President",
"DisplayOrganizationName":"Prodigy Makers International"
},
{
"$type":"Asi.Soa.Membership.DataContracts.FullAddressData, Asi.Contracts",
"AdditionalLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
]
},
"Address":{
"$type":"Asi.Soa.Membership.DataContracts.AddressData, Asi.Contracts",
"AddressId":"3",
"AddressLines":{
"$type":"Asi.Soa.Membership.DataContracts.AddressLineDataCollection, Asi.Contracts",
"$values":[
"2031 Maple"
]
},
"Barcode":"/882200/",
"CityName":"Somerville",
"CountrySubEntityCode":"NJ",
"FullAddress":"2031 Maple\rSomerville, NJ 88220",
"PostalCode":"88220",
"VerificationStatus":0
},
"AddresseeText":"Prodigy Makers International\r\n2031 Maple\rSomerville, NJ 88220",
"AddressPurpose":"Home Address",
"CommunicationPreferences":{
"$type":"Asi.Soa.Membership.DataContracts.CommunicationPreferenceDataCollection, Asi.Contracts",
"$values":[
]
},
"FullAddressId":"3",
"Salutation":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"main"
},
"Text":"Prodigy Makers International"
},
"DisplayName":"Doug",
"DisplayOrganizationTitle":"President",
"DisplayOrganizationName":"Prodigy Makers International"
}
]
},
"AlternateIds":{
"$type":"Asi.Soa.Core.DataContracts.AlternateIdDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Core.DataContracts.AlternateIdData, Asi.Contracts",
"Id":"101",
"IdType":"Id"
}
]
},
"Emails":{
"$type":"Asi.Soa.Membership.DataContracts.EmailDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Membership.DataContracts.EmailData, Asi.Contracts",
"Address":"[email protected]",
"EmailType":"Address"
}
]
},
"FinancialInformation":{
"$type":"Asi.Soa.Membership.DataContracts.FinancialInformationData, Asi.Contracts"
},
"Phones":{
"$type":"Asi.Soa.Membership.DataContracts.PhoneDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(201) 346-9989",
"PhoneType":"_Home Phone"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(201) 898-9000",
"PhoneType":"_Work Phone"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(201) 898-4255",
"PhoneType":"_Fax"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(411)643-5821",
"PhoneType":"Mobile"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(201) 898-9000",
"PhoneType":"Address"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PhoneData, Asi.Contracts",
"Number":"(201) 898-4255",
"PhoneType":"Address Fax"
}
]
},
"Salutations":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"IsOverridden":false,
"SalutationId":"101",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"FAMILY"
},
"Text":"Mr. Douglas A. Hunt, Jr."
},
{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"IsOverridden":true,
"SalutationId":"101",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"FORMAL"
},
"Text":"Mr. Douglas A. Hunt"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"IsOverridden":false,
"SalutationId":"101",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"HOUSEHOLD"
},
"Text":"The Hunt Household"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"IsOverridden":false,
"SalutationId":"101",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"INFORMAL"
},
"Text":"Doug"
},
{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationData, Asi.Contracts",
"IsOverridden":false,
"SalutationId":"101",
"SalutationMethod":{
"$type":"Asi.Soa.Membership.DataContracts.PartySalutationMethodSummaryData, Asi.Contracts",
"PartySalutationMethodId":"LIST_AS"
},
"Text":"Mr. Douglas A. Hunt, Jr."
}
]
},
"SocialNetworks":{
"$type":"Asi.Soa.Membership.DataContracts.PartySocialNetworkDataCollection, Asi.Contracts",
"$values":[
]
},
"CommunicationTypePreferences":{
"$type":"Asi.Soa.Membership.DataContracts.PartyCommunicationTypePreferenceDataCollection, Asi.Contracts",
"$values":[
]
},
"SortIsOverridden":false,
"UpdateInformation":{
"$type":"Asi.Soa.Core.DataContracts.EntityUpdateInformationData, Asi.Contracts",
"CreatedBy":"ADMINISTRATOR",
"CreatedOn":"2012-11-13T12:52:41.95",
"UpdatedBy":"ADMINISTRATOR",
"UpdatedOn":"2012-11-13T12:52:41.95"
},
"PartyId":"101",
"Id":"101",
"UniformId":"5a8151eb-a601-4230-84d1-fa95f63af7c8",
"Status":{
"$type":"Asi.Soa.Membership.DataContracts.PartyStatusData, Asi.Contracts",
"PartyStatusId":"A",
"Name":"Active",
"Description":"Active"
},
"Name":"Prodigy Makers International",
"Sort":"Prodigy Makers International"
}
Direct access (OAuth 2.0)
The OAuth 2.0 token security is used for external or cross-site access to the ASI Scheduler web API. After an authorization request to access the server is posted, the tokenreceived is added to the headers of all other requests. For details on using the OAuth2.0 framework, go to http://www.oauth.net/.
The correct URL format for using OAuth 2.0 to access the ASI Scheduler API is:
https://server.com/asiScheduler/api/
Do the following to use OAuth 2.0:
- Obtain an access token.
- Add the token to headers.
- Make a request.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
namespace AsiRestApiAccess
{
public static class Program
{
public static HttpClient Client;
static Program()
{
// set HTTP Client's base address to target iMIS instance scheduler/service
Client = new HttpClient
{
BaseAddress = new Uri("https://testapi.imis.com/Asi.Scheduler_SDKDemo/")
};
// address client's certificate and header values
// NOTE: This causes all Server Certificates for https to be accepted without validation.
// This is convenient during development with self-signed certificates or mismatched hostnames.
// In production, you should use only certificates signed by a trusted CA and delete this line.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// POST to the iMIS token endpoint with form-encoded data set, which should be modified to
// correspond to your iMIS instance's MANAGER/RemoteService user
var response = Client.PostAsync("token", new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", "demouser"),
new KeyValuePair<string, string>("password", "demo123")
})).Result;
// deserialize incoming JSON to Token object specified below, attach token to client's authorization
// header with the 'Bearer' prefix to being making authenticated requests to iMIS
Token token = JsonConvert.DeserializeObject<Token>(response.Content.ReadAsStringAsync().Result);
Client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.AccessToken);
}
/// <summary>
/// C# class representation of iMIS Bearer Token, used to authenticate additional requests
/// </summary>
internal class Token
{
[JsonProperty("access_token")] public string AccessToken { get; set; }
[JsonProperty("token_type")] public string TokenType { get; set; }
[JsonProperty("expires_in")] public int ExpiresIn { get; set; }
[JsonProperty("userName")] public string UserName { get; set; }
[JsonProperty(".issued")] public string Issued { get; set; }
[JsonProperty(".expires")] public string Expires { get; set; }
}
static void Main(string[] args)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
namespace AsiRestApiAccess
{
public static class Program
{
public static HttpClient Client;
static Program()
{
// set HTTP Client's base address to target iMIS instance scheduler/service
Client = new HttpClient
{
BaseAddress = new Uri("https://testapi.imis.com/Asi.Scheduler_SDKDemo/")
};
// address client's certificate and header values
// NOTE: This causes all Server Certificates for https to be accepted without validation.
// This is convenient during development with self-signed certificates or mismatched hostnames.
// In production, you should use only certificates signed by a trusted CA and delete this line.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// POST to the iMIS token endpoint with form-encoded data set, which should be modified to
// correspond to your iMIS instance's MANAGER/RemoteService user
var response = Client.PostAsync("token", new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", "demouser"),
new KeyValuePair<string, string>("password", "demo123")
})).Result;
// deserialize incoming JSON to Token object specified below, attach token to client's authorization
// header with the 'Bearer' prefix to being making authenticated requests to iMIS
Token token = JsonConvert.DeserializeObject<Token>(response.Content.ReadAsStringAsync().Result);
Client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.AccessToken);
}
/// <summary>
/// C# class representation of iMIS Bearer Token, used to authenticate additional requests
/// </summary>
internal class Token
{
[JsonProperty("access_token")] public string AccessToken { get; set; }
[JsonProperty("token_type")] public string TokenType { get; set; }
[JsonProperty("expires_in")] public int ExpiresIn { get; set; }
[JsonProperty("userName")] public string UserName { get; set; }
[JsonProperty(".issued")] public string Issued { get; set; }
[JsonProperty(".expires")] public string Expires { get; set; }
}
/// <summary>
/// Small example utilizing the above created and authenticated HTTP client
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
const string itemId = "G15"; // Product code
var item = Client.GetAsync($"api/item/{itemId}").Result;
if (item != null && item.IsSuccessStatusCode)
{
Console.WriteLine("Product: {0}", item.Content.ReadAsStringAsync().Result);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Asi.Soa.Membership.DataContracts;
using Newtonsoft.Json;
namespace iMISRestBoilerplate
{
public static class Program
{
public static HttpClient Client;
static Program()
{
// set HTTP Client's base address to target iMIS instance scheduler/service
Client = new HttpClient
{
BaseAddress = new Uri("https://testapi.imis.com/Asi.Scheduler_SDKDemo/")
};
// address client's certificate and header values
// NOTE: This causes all Server Certificates for https to be accepted without validation.
// This is convenient during development with self-signed certificates or mismatched hostnames.
// In production, you should use only certificates signed by a trusted CA and delete this line.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// POST to the iMIS token endpoint with form-encoded data set, which should be modified to
// correspond to your iMIS instance's MANAGER/RemoteService user
var response = Client.PostAsync("token", new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", "demouser"),
new KeyValuePair<string, string>("password", "demo123")
})).Result;
// deserialize incoming JSON to Token object specified below, attach token to client's authorization
// header with the 'Bearer' prefix to being making authenticated requests to iMIS
Token token = JsonConvert.DeserializeObject<Token>(response.Content.ReadAsStringAsync().Result);
Client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.AccessToken);
}
static async Task<PartySummaryData> GetPartyDataAsync(string partyId)
{
PartySummaryData party = new PartySummaryData();
// Query Party service endpoint
var response = await Client.GetAsync($"api/PartySummary/{partyId}");
if (response.IsSuccessStatusCode)
{
// deserialize response to DataContract
party =
JsonConvert.DeserializeObject<PartySummaryData>(await response.Content.ReadAsStringAsync());
}
return party;
}
static void Main(string[] args)
{
GetPartyDataAsync("23173").GetAwaiter().GetResult();
}
/// <summary>
/// C# class representation of iMIS Bearer Token, used to authenticate additional requests
/// </summary>
internal class Token
{
[JsonProperty("access_token")] public string AccessToken { get; set; }
[JsonProperty("token_type")] public string TokenType { get; set; }
[JsonProperty("expires_in")] public int ExpiresIn { get; set; }
[JsonProperty("userName")] public string UserName { get; set; }
[JsonProperty(".issued")] public string Issued { get; set; }
[JsonProperty(".expires")] public string Expires { get; set; }
}
}
}
Updated about 6 years ago