Check the Results of an API Call

This page contains information about checking the results of an API call.

Why Check the Results of an API Call 

After making an API call, you need to check the results of that call to determine whether it was successful and possibly take action based on the success or failure of the call.

How to Check the Results of an API Call 

Use the sample code below as a model for your own call.

Sample .NET Code 

1public static bool CheckResults(string status, ET.Integration.WSDL.CreateResult[] results, out string error, out string newID)
2{
3    error = null;
4    newID = null;
5    // If no results, then return true
6    if ((results == null) || (results.Length == 0))
7    {
8        return true;
9    }
10    //Check the status
11    if (status.Equals("OK"))
12    {
13        return true;
14    }
15    // Check the results
16    for (int i = 0; i < results.Length; i++)
17    {
18        if (results[i].StatusCode.Equals("OK"))
19        {// The status is OK so get the ID
20            if (results[i].NewID > 0)
21                newID = results[i].NewID.ToString();
22            else if (!string.IsNullOrEmpty(results[i].NewObjectID))
23                newID = results[i].NewObjectID;
24    }
25    else
26    {// The status is something else so get the error
27            if (!string.IsNullOrEmpty(results[i].StatusMessage))
28            {
29                    error = results[i].StatusMessage;
30            }
31        }
32    }
33    // Return true if we have an ID and no error
34    return (!string.IsNullOrEmpty(newID) && string.IsNullOrEmpty(error));
35}