For a more in depth and other programming language samples, download the Sample Client Install

C# Copy imageCopy
using System;
using System.IO;
using System.Net;

namespace FaxWSConsoleApplication
{
    public static class SimpleSendFaxClass
    {
        const string oauthUrl = "https://login.concord.net/v1/connect/token";
        const string faxWSUrl = "https://ws.concordfax.com/fax/v5";

        public static void SimpleSendFax()
        {
            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 grantType = "password";
            string scope = "FaxWS";
            string faxWSClientId = "A9F528F9-0000-4B70-0000-078C23030424-ConcordApiFaxWS";
            string faxWSClientSecret = "";

            AccessTokenRequest accessTokenRequest = null;
            AccessTokenResponse accessTokenResponse = null;
            TokenManager tokenManager = new TokenManager(oauthUrl);

            accessTokenRequest = new AccessTokenRequest(
                clientId: faxWSClientId,
                clientSecret: faxWSClientSecret,
                username: username,
                password: password,
                grantType: grantType,
                scope: scope,
                redirectUri: null,
                code: null,
                refreshToken: null,
                state: null);

            ///OAuth 2.0 Authentication End
            ///////////////////////////////////////////////////////////

            using(FaxWSAuthWrapper ws = new FaxWSAuthWrapper())
            {
                ws.Url = faxWSUrl;

                string recipientName = "RecipientName";
                string recipientFaxNumber = "12065550000"; // FaxNumber

                string faxFileName = "c:\\FaxImage.tif";

                FileStream inputFile = new FileStream(faxFileName, FileMode.Open, FileAccess.Read);
                byte[] tiffJobFile = new Byte[inputFile.Length];
                inputFile.Read(tiffJobFile, 0, (int)inputFile.Length); // Read file
                inputFile.Close();

                try
                {
                    // 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
                    //string result = ws.SimpleSendFax(username, password, recipientName, recipientFaxNumber, tiffJobFile);

                    // 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;

                    string result = ws.SimpleSendFax(UserID: username, strPIN: "", RecipientName: recipientName, FaxNumber: recipientFaxNumber, TIFFJobFile: tiffJobFile);

                    if(result.StartsWith("br"))
                    {
                        Console.WriteLine("JobId: " + result);
                    }
                    else
                    {
                        Console.WriteLine("SimpleSendFax Failed with error: " + result);
                    }

                }
                catch(Exception ex)
                {
                    Console.WriteLine("Error while calling SimpleSendFax : " + ex.Message);
                }

            }
        }
    }
}
Visual Basic Copy imageCopy
Imports System.IO
Imports System.Net

Namespace FaxWSVBConsoleApplication
    Friend Class SimpleSendFaxClass
        Public Shared Sub SimpleSendFax()
            Dim username As String = "mbxXXXXXXXX"
            Dim password As String = "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

            Dim oauthUrl As String = "https://login.concord.net/v1/connect/token"
            Dim grantType As String = "password"
            Dim scope As String = "FaxWS"
            Dim faxWSClientId As String = "A9F528F9-0000-4B70-0000-078C23030424-ConcordApiFaxWS"
            Dim faxWSClientSecret As String = ""
            Dim accessTokenRequest As AccessTokenRequest = Nothing
            Dim accessTokenResponse As AccessTokenResponse = Nothing
            Dim tokenManager As TokenManager = New TokenManager(oauthUrl)
            accessTokenRequest = New AccessTokenRequest(clientId:=faxWSClientId, clientSecret:=faxWSClientSecret, username:=username, password:=password, grantType:=grantType, scope:=scope, redirectUri:=Nothing, code:=Nothing, refreshToken:=Nothing, state:=Nothing)


            '' OAuth 2.0 Authentication End
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            Using ws As FaxWSAuthWrapper = New FaxWSAuthWrapper()
                Dim recipientName As String = "RecipientName"
                Dim recipientFaxNumber As String = "12065550000" ' FaxNumber
                Dim faxFileName As String = "c:\FaxImage.tif"
                Dim inputFile As FileStream = New FileStream(faxFileName, FileMode.Open, FileAccess.Read)
                Dim tiffJobFile As Byte() = New Byte(inputFile.Length - 1) {}
                inputFile.Read(tiffJobFile, 0, inputFile.Length) ' Read file
                inputFile.Close()

                Try
                    ' Get an access token from Cache OR request one from the Identity Server
                    accessTokenResponse = tokenManager.GetAccessToken(accessTokenRequest)

                    If accessTokenResponse Is Nothing Then
                        Console.WriteLine("Failed to get an AccessToken, returned null")
                        Return
                    End If


                    ' 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 AndAlso Equals(accessTokenResponse.Error, "invalid_grant") Then
                        Console.WriteLine("Refresh token expired, attempting to get a new Access Token")
                        accessTokenResponse = tokenManager.GetAccessToken(accessTokenRequest, ignoreCache:=True)
                    End If

                    If accessTokenResponse.HttpStatusCode <> HttpStatusCode.OK Then
                        Console.WriteLine("AccessToken not valid, Error Code: {0}, Error Description: {1}", accessTokenResponse.Error, accessTokenResponse.ErrorDescription)
                        Return
                    End If


                    ' User Name and Password authentication
                    'string result = ws.SimpleSendFax(username, password, recipientName, recipientFaxNumber, tiffJobFile);

                    ' 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
                    Dim result As String = ws.SimpleSendFax(UserID:=username, strPIN:="", RecipientName:=recipientName, FaxNumber:=recipientFaxNumber, TIFFJobFile:=tiffJobFile)

                    If result.StartsWith("br") Then
                        Console.WriteLine("JobId: " & result)
                    Else
                        Console.WriteLine("SimpleSendFax Failed with error: " & result)
                    End If

                Catch ex As Exception
                    Console.WriteLine("Error while calling SimpleSendFax : " & ex.Message)
                    Return
                End Try
            End Using
        End Sub
    End Class
End Namespace

See Also