Web Services - Ws - PDocDetailApi.GetPddList

Sample C# code to use the web service - similar code will work for all the web services except uploading documents.  Note the ability to loop through model validation errors.       
private const string myUserName = "myUserName";
private const string myPassword = "password";
string myUrlPrefix = "https://documentvacuum.com/";

public ActionResult GetPDocDetailApi()

    int pDocId = 911; //make sure this is a valid PDocId
    string entityId="abcd"; //make sure this is a valid unique entityId
    HttpClient client = new HttpClient();
    //use either PDocId or EntityId to find the record
    string myUrlSuffix = “PDocDetailApi/GetPddList?”
        "id=" + pDocId + "&identityColumn=PDocId";
    //string myUrlSuffix = “PDocDetailApi/GetPddList?” +
    //      "id=" + entityId +"&identityColumn=EntityId";
    string myUrl = myUrlPrefix + myUrlSuffix;

    var buffer = System.Text.Encoding.ASCII.GetBytes(myUserName + ":" + myPassword);
    var authHeader = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic",
    client.DefaultRequestHeaders.Authorization = authHeader;

        var task = client.GetAsync(myUrl);
        HttpStatusCode statusCode = task.Result.StatusCode;
        var output = task.Result.Content.ReadAsStringAsync().Result;

        if (statusCode == HttpStatusCode.OK)
           string outcome = "Success";
            //While the list will normally have one element, it is possible that there are two, the
            //first originally created with a pdf document, and then when the text contents are not
            //extractable this goes to status 27 and a second is created to extract text using the image
            //rather than embedded text
            List<PDocDetailApi> pddApiList =
            //if a document has completed processing successfully, it will be shown below
            PDocDetailApi pddApiSuccess = pddApiList.Where(x =>
                x.PDocStatusId == 21).FirstOrDefault();
        else if (statusCode == HttpStatusCode.Unauthorized)
             string outcome = "Bad login credentials or insufficient account permissions";
       else if (statusCode == HttpStatusCode.BadRequest)
           string outcome = "There was a problem with the information submitted";
          BnieModelStateError outcome2 =
           if (outcome2.Errors != null && outcome2.Errors.Count > 0)
               for (int i=0; i < outcome2.Errors.Count; i++)
                   string modelValidationError = outcome2.Errors.ElementAt(i).Value[0];
       else if (statusCode == HttpStatusCode.NotFound)
             string outcome = "We could not find any pDocDetails that match";
       else if (statusCode == HttpStatusCode.InternalServerError)
             string outcome = "Something else went wrong";
    catch (Exception e)
        string s = e.Message;

    return RedirectToAction("Index");

Last modified: 4/14/2021
Other articles:
Anonymous Mode Email
Web Services - Ws - PDocDetailApi.GetPddList
Combining Multiple Docs into One Doc
Billing - DocVacBasic & DocVacGold
Setup Docs
Excel to Consume Web Services
CSV Files
Financial Statement / Table Extraction
Key Term Search with Wildcards
DocVac Dictionary of Jargon