This article includes:
This code is intended as an example of how to use the PRiSMPro API services. Although the examples are in C#, the services can be accessed in any software language with SOAP or JSON capabilities.
Calling the Transactional API (SOAP)
This example shows a call to the PRiSMPro Transactional API service using SOAP to get a list of service types that your company is eligible for. The code will then use the first service type code in the list to retrieve a list of feature codes in that service type that your company is eligible for.
using System;
using PRiSMProAPI_Client.PRiSMProTransactionalAPIService;
using System.ServiceModel;
using System.IO;
...
try
{
TransactionalAPIClient tClient = new TransactionalAPIClient("TransactionalAPISOAP");
tClient.ClientCredentials.UserName.UserName = userName;
tClient.ClientCredentials.UserName.Password = password;
try
{
ItemNameList dtl = tClient.queryServiceTypeCodes();
Console.WriteLine("requestStatus = " + dtl.requestStatus);
Console.WriteLine(" Service types: ");
foreach (ItemNameRecord dt in dtl.items)
{
Console.WriteLine(" " + dt.code + ": " + dt.name);
}
if (dtl.items.Length > 0)
{
try
{
ItemNameList ftl = tClient.queryFeatureCodes(dtl.items[0].code);
Console.WriteLine("requestStatus = " + ftl.requestStatus);
Console.WriteLine(" Features: ");
foreach (ItemNameRecord ft in ftl.items)
{
Console.WriteLine(" " + ft.code + ": " + ft.name);
}
}
catch (FaultException<PRiSMProAPI_Client.PRiSMProTransactionalAPIService.PRiSMProAPIFault> ex)
{
Console.WriteLine("Error: " + Enum.GetName
(typeof(PRiSMProTransactionalAPIService.RequestStatus), ex.Detail.errorCode) +
" - " + ex.Detail.errorMessage);
}
}
}
catch (FaultException<PRiSMProAPI_Client.PRiSMProTransactionalAPIService.PRiSMProAPIFault> ex)
{
Console.WriteLine("Error: " + Enum.GetName
(typeof(PRiSMProTransactionalAPIService.RequestStatus), ex.Detail.errorCode) +
" - " + ex.Detail.errorMessage);
}
finally
{
if (tClient.State == CommunicationState.Opened)
{
tClient.Close();
}
}
}
catch (ArgumentException aex)
{
// missing user credentials
Console.WriteLine ("Exception: " + aex.Message + Environment.NewLine + aex.StackTrace);
}
catch (System.ServiceModel.Security.MessageSecurityException msex)
{
// invalid user credentials
Console.WriteLine("Exception: " + msex.Message + Environment.NewLine + msex.StackTrace);
}
Calling the Transactional API (JSON)
Below are the same Transactional API service method calls made with JSON.
using System;
using PRiSMProAPI_Client.PRiSMProTransactionalAPIService;
using System.ServiceModel;
using System.IO;
...
try
{
TransactionalAPIClient tClient = new TransactionalAPIClient("TransactionalAPIJSON");
tClient.ClientCredentials.UserName.UserName = userName;
tClient.ClientCredentials.UserName.Password = password;
try
{
ItemNameList dtl = tClient. queryServiceTypeCodes();
Console.WriteLine("requestStatus = " + dtl.requestStatus);
Console.WriteLine(" Service types: ");
foreach (ItemNameRecord dt in dtl.items)
{
Console.WriteLine(" " + dt.code + ": " + dt.name);
}
if (dtl.items.Length > 0)
{
try
{
ItemNameList ftl = tClient.queryFeatureCodes(dtl.items[0].code);
Console.WriteLine("requestStatus = " + ftl.requestStatus);
Console.WriteLine(" Features: ");
foreach (ItemNameRecord ft in ftl.items)
{
Console.WriteLine(" " + ft.code + ": " + ft.name);
}
}
catch (Exception ex)
{
// JSON calls receive exceptions as generic Exceptions. The Message received
// contains the error code and message (e.g. "7: ESN is already in the system")
Console.WriteLine("Error: " + ex.Message);
}
}
}
catch (Exception ex)
{
// JSON calls receive exceptions as generic Exceptions. The Message received
// contains the error code and message (e.g. "7: ESN is already in the system")
Console.WriteLine("Error: " + ex.Message);
}
finally
{
if (tClient.State == CommunicationState.Opened)
{
tClient.Close();
}
}
}
catch (ArgumentException aex)
{
// missing user credentials
Console.WriteLine ("Exception: " + aex.Message + Environment.NewLine + aex.StackTrace);
}
catch (System.ServiceModel.Security.MessageSecurityException msex)
{
// invalid user credentials
Console.WriteLine("Exception: " + msex.Message + Environment.NewLine + msex.StackTrace);
}
Calling the Reporting API
This example shows you how to check for available billing summary files using the Reporting API service. If there are files available for your company, the first file will be downloaded to the folder "c:\tmp". The code will report any errors to the Console.
using System;
using PRiSMProAPI_Client.PRiSMProReportingAPIService;
using System.ServiceModel;
using System.IO;
...
try
{
ReportingAPIClient rClient = new ReportingAPIClient();
rClient.ClientCredentials.UserName.UserName = userName;
rClient.ClientCredentials.UserName.Password = password;
try
{
ListOfAvailableReportFiles lstFiles = rClient.queryAvailableReportFiles(ReportFileType.SummaryFile);
if (lstFiles.reportFiles.Length > 0)
{
try
{
Stream strm = rClient.downloadSummaryFile(lstFiles.reportFiles[0]);
byte[] b = new byte[4096];
int readCount = 0;
int tot = 0;
FileStream fs = System.IO.File.Create("c:\\tmp\\" + lstFiles.reportFiles[0]);
while ((readCount = strm.Read(b, 0, 4096)) > 0)
{
fs.Write(b, 0, readCount);
tot += readCount;
}
fs.Close();
strm.Close();
}
catch (FaultException<PRiSMProAPI_Client.PRiSMProReportingAPIService.PRiSMProAPIFault> ex)
{
Console.WriteLine("Error: " + Enum.GetName
(typeof(PRiSMProReportingAPIService.RequestStatus), ex.Detail.errorCode) +
" - " + ex.Detail.errorMessage);
}
}
}
catch (FaultException<PRiSMProAPI_Client.PRiSMProReportingAPIService.PRiSMProAPIFault> ex)
{
Console.WriteLine("Error: " + Enum.GetName
(typeof(PRiSMProReportingAPIService.RequestStatus), ex.Detail.errorCode) +
" - " + ex.Detail.errorMessage);
}
finally
{
if (rClient.State == CommunicationState.Opened)
{
rClient.Close();
}
}
}
catch (ArgumentException aex)
{
// missing user credentials
Console.WriteLine ("Exception: " + aex.Message + Environment.NewLine + aex.StackTrace);
}
catch (System.ServiceModel.Security.MessageSecurityException msex)
{
// invalid user credentials
Console.WriteLine("Exception: " + msex.Message + Environment.NewLine + msex.StackTrace);
}