Apex EDI Vendor Portal

Apex EDI API V3 Documentation

C# Sample Code

Sample Eligibility Request Submission

The source code below illustrates one example of submitting eligibility requests and requesting responses through Apex EDI. For additional examples of request types please see the list of sample requests.

NOTE: When submitting eligibility test requests on the sandbox system, the payer ID APX14114 must be used in the JSON PayerId field.

Compact Example

.NET Libraries

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json.Linq;

NOTE: The usage of the free Newtonsoft.Json library requires downloading this library and including it in the project references. The .NET library System.Text.Json can be used instead if desired.

Authentication

All API calls require authentication which must be included in the HttpClient header:

//                     sample key                      sample password
string creds = "XORVKPEAWPCGV1QUEXWPO34N" + ":" + "JA1TSZNKTQOFK4WOHIWQ0K9D";
byte[] bcreds = Encoding.ASCII.GetBytes(creds);
string base64Creds = Convert.ToBase64String(bcreds);
HttpClient client = new HttpClient { BaseAddress = new Uri(ServiceBaseURL) };
client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Creds);

API Calling Convention

For each API HTTP call, there is a HttpResponseMessage that is returned. This can be viewed by reading the Content property as a string.

APIs can be called in the following way, using the HttpClient:

HttpResponseMessage _response = client.PostAsync("payers/get_list?vendorSiteId=000_Client&type=Medical", null).Result;

or

HttpResponseMessage_response = 
client.PostAsJsonAsync("eligibility/submit?vendorSiteId=MyVendorSiteId", httpStringContent).Result;

Sample Code - C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json.Linq;

namespace SimpleEligibility
{
	class Program
	{
		private static HttpResponseMessage _response;
		private static string _creds = "XORVKPEAWPCGV1QUEXWPO34N" + ":" + "JA1TSZNKTQOFK4WOHIWQ0K9D";
		private static string _vendorSiteId = "ZZZ_TEST";
		private static string jsonEligTextFile = @"C:\TestFiles\EligTest01.json";


		static void Main(string[] args)
		{
			using (HttpClient client = new HttpClient())
			{
				client.BaseAddress = new Uri("https://sandbox.services.apexedi.com/api/v3/");
				byte[] creds = Encoding.ASCII.GetBytes(_creds);
				string base64Creds = Convert.ToBase64String(creds);
				client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Creds);
				client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
				client.Timeout = System.Threading.Timeout.InfiniteTimeSpan;

				StringContent httpStringContent = null;

				// The member ID of the subscriber controls what will be returned.  This is true, even if the benefits 
				// are  being requested for a dependent.  When using a test payer, the following member IDs may be 
				// used to auto-generate various errors and response scenarios

				// 1001 - envelope errors
				// 1002 - payer errors
				// 1003 - payee errors
				// 1004 - subscriber errors
				// 1005 - dependent errors
				// 1006 - syntax error
				// 1007 - complex benefits will be returned
				// 1008 - simple benefits will be returned after a delay of approximately 65 seconds. Note that
				// there will be a 65 second delay for each patient (subscriber or dependent) where 1008 is the
				// subscriber member ID.
				// Any other member ID - simple benefits will be returned
				/*
				 * IDs in the range of 1009 to 1999 are reserved for special return values, so they should be avoided. 
				 * Any other Membership ID (letters or numbers) will return simple benefits
				 */

				string memberId = "1007";	// 1007 will give complex benefits

				string jsonString =
					$@"{{
				""BenefitInquiries"": [
				{{
					""Payers"": [
					{{
						""CommonName"": ""Test Payer"",
						""EntityType"": ""Organization"",
						""Payees"": [
						{{
							""CommonName"": ""LASTNAME"",
							""EntityType"": ""Individual"",
							""FirstName"": ""FIRSTNAME"",
							""NationalProviderId"": ""1234567893"",
							""Subscribers"": [
							{{
								""Dependents"": null,
								""RequestedBenefits"": [
								{{
									""IsFamilyBenefit"": false,
									""NOTE: For Dental General Coverage Type Use - "": ""Dental Care"",
									""Type"": [
									""HealthBenefitPlanCoverage""
										]
								}}],
								""BirthDate"": ""1981/08/21"",
								""CommonName"": ""LastName"",
								""FirstName"": ""John"",
								""Gender"": ""Male"",
								""MemberId"": ""{memberId}"",
								""PayeeTraceNumber"": {{
									""Number"": ""SingleSubServiceSingle-01"",
									""OriginatorID"": ""1923457658""
								}}
							}}],
							""Type"": ""Facility""
						}}],
						""NOTE: For Dental Payer ID in Sandbox Use - "": ""TST02"",
						""PayerId"": ""TST01"",
						""Type"": ""Payer""
					}}],
					""RequestType"": ""Request""
				}}],
				""IsTest"": true
			}}
			";

				// Alternately, you can load a JSON file instead of using 
				// the hard coded inline example above
				if (File.Exists(jsonEligTextFile))
				{
					jsonString = File.ReadAllText(jsonEligTextFile);
				}

				httpStringContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
				_response = client.PostAsync($"eligibility/submit?vendorSiteId={_vendorSiteId}", httpStringContent)
					.Result;

				string resultString = string.Empty;
				if (_response != null && _response.Content != null)
				{
					resultString = _response.Content.ReadAsStringAsync().Result;
				}

				try
				{
					long requestId = 0L;
					if (_response.StatusCode == HttpStatusCode.OK)
					{
						JObject jObject = JObject.Parse(resultString);
						requestId = (long) (jObject["RequestId"] ?? 0);

						string statusMsg = (string) (jObject["Status"] ?? string.Empty);

						if (string.Compare(statusMsg, 
							    "ResultsComplete", StringComparison.CurrentCultureIgnoreCase) != 0)
						{
							_response = client.PostAsync(
									$"eligibility/get_responses?vendorSiteId={_vendorSiteId}&requestId={requestId}",
									null)
								.Result;

							if (_response != null && _response.Content != null)
							{
								resultString = _response.Content.ReadAsStringAsync().Result;
							}
						}
					}

				}
				catch (Exception ex)
				{
					Console.WriteLine(ex);
					throw;
				}
			}
		}
	}
}