For a more in depth and other programming language samples, download the Sample Client Install
C# | ![]() |
---|---|
using System; using System.Net; using IWSConsoleSample.IWSServiceReference; namespace IWSConsoleSample { class GetInboundItemListSampleClass { public static void GetInboundItemListSample() { string username = "mbxXXXXXXXX"; string password = "XXXX"; /////////////////////////////////////////////////////////// ///OAuth 2.0 Authentication Start, ///Comment this block out if you are using username and password authentication // Get an access token from Concord Identity Server string endPoint = "https://login.concord.net/v1/"; string grantType = "password"; string scope = "IWS"; string IWSClientId = "ConcordIWSClient"; string IWSClientSecret = ""; AccessTokenRequest accessTokenRequest = null; AccessTokenResponse accessTokenResponse = null; TokenManager tokenManager = new TokenManager(endPoint); accessTokenRequest = new AccessTokenRequest( clientId: IWSClientId, clientSecret: IWSClientSecret, username: username, password: password, grantType: grantType, scope: scope, redirectUri: null, code: null, refreshToken: null, state: null); ///OAuth 2.0 Authentication End /////////////////////////////////////////////////////////// using (IWSAuthWrapper ws = new IWSAuthWrapper()) { Authentication authentication = null; GetInboundItemListRequest request = null; GetInboundItemListResponse response = null; authentication = new Authentication(); authentication.UserId = username; // Get an access token from Cache OR request one from the Identity Server accessTokenResponse = tokenManager.GetAccessToken(accessTokenRequest); if (accessTokenResponse == null) { Console.WriteLine("Failed to get an AccessToken, returned null"); return; } // Check to see if we failed to get an Access token via a Refresh token that has expired or been revoked, if so we need to re-authenticate if (accessTokenResponse.HttpStatusCode == HttpStatusCode.BadRequest && accessTokenResponse.Error == "invalid_grant") { Console.WriteLine("Refresh token expired, attempting to get a new Access Token"); accessTokenResponse = tokenManager.GetAccessToken(accessTokenRequest, ignoreCache: true); } if (accessTokenResponse.HttpStatusCode != HttpStatusCode.OK) { Console.WriteLine("AccessToken not valid, Error Code: {0}, Error Description: {1}", accessTokenResponse.Error, accessTokenResponse.ErrorDescription); return; } // User Name and Password authentication // authentication.Password = password; // OAuth 2.0 Authentication requires that you pass in an access token as part of the Authorization: header // (No Password required) ws.AccessToken = accessTokenResponse.AccessToken; request = new GetInboundItemListRequest(); request.MaxItems = 10; // Optional parameters that can be set. // See GetInboundItemListRequst Object // for parameter details. // request.ArchivedItems; // request.Dnis; // request.StartDate; // request.EndDate; try { response = ws.GetInboundItemList(authentication, request); if (!response.Success) { bool requiresNewToken = false; foreach (WSError error in response.Messages) { Console.WriteLine("Error retrieving fax document list. Error Code: {0} Error Description: {1}", error.ErrorCode, error.ErrorDescription); if (error.ErrorCode == -486 && error.ErrorDescription == "Invalid access token") requiresNewToken = true; } // Check to see if response indicates access token has expired, if so attempt to Refresh or Get New OAuth access token and try method call again if (requiresNewToken) { Console.WriteLine("AccessToken is not valid"); // Attempt to get a new access token or use a refresh token, if we fail we should stop accessTokenResponse = tokenManager.GetAccessToken(accessTokenRequest); if (accessTokenResponse == null) { Console.WriteLine("Failed to get an AccessToken, returned null"); return; } if (accessTokenResponse.HttpStatusCode != HttpStatusCode.OK) { Console.WriteLine("AccessToken not valid, Error Code: {0}, Error Description: {1}", accessTokenResponse.Error, accessTokenResponse.ErrorDescription); return; } } return; } if (response.InboundItemCount < 1) { Console.WriteLine("No faxes returned"); return; } Console.WriteLine("Number of faxes returned: " + response.InboundItemCount); foreach (string inboundItemId in response.InboundItemIDs) { Console.WriteLine("InboundItemId: " + inboundItemId); } // The returned InboundItemId is then used to retrieve the message // from the service using the GetInboundItemByID Method } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } Console.WriteLine("Finished retrieving inbound item list"); } } } } |