Application & Process Automation

Getting Started
Authentication & Access
Accounts with Multi-Factor Authentication
Using method GetPrograms
Common Usage Scenarios
Create and Submit a Project
Add/Change Data in an Existing Project
Daily Polling for Project Changes
Troubleshooting
Using Custom IDs
API Method Reference
GetPrograms
URL Format
Response
XML Attributes
Sample Code
GetForms
URL Format
Response
Forms Attributes
AvailableInStatuses and LeadsToStatus
Status Attributes
Sample Code
GetFormSchema
V1 Response
V2 Response
Sample Code
GetProjects
V1 Response
V2 Response
V3 Response
Sample Code
GetProjectsByNumber
V1 Response
V2 Response
Sample Request
Sample Code
GetProjectsByData
Sample Request
Request XML Nodes and Attributes
V1 Response
V2 Response
CreateNewProject
Sample Response
Response XML Attributes
Sample Code
GetAllProjectData - Admin only
Sample Response
XML Attributes
Sample Code
GetProjectData
Sample Response
XML Attributes
Sample Code
SetProjectData
Sample Request
Request XML Attributes
Sample Response
Response XML Attributes
Sample Code
GetActiveAttachment
URL Format
Sample Code
GetAttachmentAsAdmin – Admin only
URL Format
SetProjectAttachment
Identifying attachment file types
URL Format
Sample Response
Response XML Attributes
Sample Code
SetAttachmentMetadata
Sample Request
Request XML Attributes
Sample Response
Response XML Attributes
Sample Code
GetAttachmentMetadata
URL Format
Sample Response
Response XML Attributes
Sample Code
SubmitProject
URL Format
Sample Response
Response XML Attributes
Sample Code
GetStatusList – Admin only
Sample Code
URL Format
Sample Response
Response XML Attributes
GetCustomListChoices
URL Format
Sample Response
Response XML Attributes
GetProjectStatusHistory – Admin only
URL Format
Sample Response
Response XML Attributes
Sample Code
SetProjectStatus – Admin only
URL Format
Sample Response
Response XML Attributes
Sample Code
GetExportProject – Admin only
Response XML Attributes
Sample Code
URL Format
Sample Response
CreateMfaSessionToken
URL Format
Sample Request
Request XML Attributes
Sample Response
Response XML Attributes
Sample Code
DeleteMfaSessionToken
URL Format
Sample Response
Sample Code
SetAssignee
URL Format
Sample Request
Request XML Attributes
Sample Response
Response XML Attributes
SetProjectOwner
URL Format
Sample Request
Request XML Attributes
Sample Response
Response XML Attributes
GetInquiryThreads – Admin Only
GetNotesInInquiryThread – Admin Only
SetInquiryNote – Admin Only
SetInquiryThreadStatus – Admin Only
SetInquiryThreadExternalId – Admin Only
SetProjectStatusReportAs – Admin only
Code Samples
EncodeAuthorizationHeader
MakeGetRequest
MakePostRequest
MakeGetFileRequest
MakeDeleteRequest
PowerShell

Code Samples


// Encodes PowerClerk credentials and generates an Authorization header string.

public static string EncodeAuthorizationHeader(string username, string password)
{
    StringBuilder header = new StringBuilder();
    header.Append("Basic ");
    byte[] bytes = Encoding.UTF8.GetBytes(username + ":" + password);
    header.Append(Convert.ToBase64String(bytes));
    return header.ToString();
}

// Issues a GET request and returns an XML response.
private XDocument MakeGetRequest(string url, string username, string password, string apiKey)
{
    Uri uri = new Uri(url);
    XDocument xmlResponse = null;
    String authHeader = EncodeAuthorizationHeader(username, password);
    using (HttpClient webClient = new HttpClient())
    {
        webClient.DefaultRequestHeaders.Clear();
        webClient.DefaultRequestHeaders.Add("Authorization", authHeader);
        webClient.DefaultRequestHeaders.Add("X-ApiKey", apiKey);
        using (HttpResponseMessage response = webClient.GetAsync(uri).Result)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Request failed with status code: " + response.StatusCode);
            }
                xmlResponse = XDocument.Parse(response.Content.ReadAsStringAsync().Result);
        }
    }
    return xmlResponse;
}

// Issues a POST request and returns an XML response.
private XDocument MakePostRequest(string url, string username, string password, string apiKey, XmlDocument xmldoc)
{
    Uri uri = new Uri(url);
    XDocument xmlResponse = null;
    String authHeader = EncodeAuthorizationHeader(username, password);
    using (HttpClient webClient = new HttpClient())
    {
        webClient.DefaultRequestHeaders.Clear();
        webClient.DefaultRequestHeaders.Add("Authorization", authHeader);
        webClient.DefaultRequestHeaders.Add("X-ApiKey", apiKey);
        using (HttpResponseMessage response = webClient.PostAsync(uri, new StringContent(xmldoc.OuterXml.ToString(), Encoding.UTF8, "application/xml")).Result)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Request failed with status code: " + response.StatusCode);
            }
            xmlResponse = XDocument.Parse(response.Content.ReadAsStringAsync().Result);
        }
    }
    return xmlResponse;
}

// Issues a GET request, receives a stream response, and saves the stream as a file.
private void MakeGetFileRequest(string url, string filePath, string username, string password, string apiKey)
{
    Uri uri = new Uri(url);
    String authHeader = EncodeAuthorizationHeader(username, password);
    using (HttpClient webClient = new HttpClient())
    {
        webClient.DefaultRequestHeaders.Clear();
        webClient.DefaultRequestHeaders.Add("Authorization", authHeader);
        webClient.DefaultRequestHeaders.Add("X-ApiKey", apiKey);
        using (HttpResponseMessage response = webClient.GetAsync(uri).Result)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Request failed with status code: " + response.StatusCode);
            }
            using (FileStream file = new FileStream(filePath, FileMode.Create))
            {
                response.Content.ReadAsStreamAsync().Result.CopyTo(file);
            }
        }
    }
}

// Issues a DELETE request for the specified resource.
private XDocument MakeDeleteRequest(string url, string username, string password, string apiKey)
{
    Uri uri = new Uri(url);
    String authHeader = EncodeAuthorizationHeader(username, password);
    using (HttpClient webClient = new HttpClient())
    {
        webClient.DefaultRequestHeaders.Clear();
        webClient.DefaultRequestHeaders.Add("Authorization", authHeader);
        webClient.DefaultRequestHeaders.Add("X-ApiKey", apiKey);
        using (HttpResponseMessage response = webClient.DeleteAsync(uri).Result)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Request failed with status code: " + response.StatusCode);
            }
        }
    }
}


// Illustrates how to retrieve/encode credentials and make a call to retrieve a list of a programs in a given agency – replace the values MyAPIKey and MyAgencyId with yours:

Param(
    [parameter(Mandatory=$true)]
    [PSCredential]
    $creds
    )
$authHash = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($creds.UserName + ":" + $creds.GetNetworkCredential().Password))
$headers = @{"X-ApiKey" = "MyAPIKey"; "Authorization"="Basic " + $authHash}
$agency = "MyAgencyId"

$c = Invoke-WebRequest -header $headers -Uri https://api.powerclerk.com/Service.svc/v1/Programs?Agency=$agency
[XML] $x = $c.Content
foreach ($p in $x.ProgramsResponse.Programs)
{
    write-host "Agency '$($x.ProgramsResponse.Programs.Program.AgencyName)' has program '$($p.Program.ProgramName)' with ID '$($p.Program.ProgramId)'"
}