Application & Process Automation
- Getting Started
- Common Usage Scenarios
- Troubleshooting
- Using Custom IDs
- API Method Reference
-
- GetPrograms
- GetForms
- GetFormSchema
- GetProjects
- GetProjectsByNumber
- GetProjectsByData
- CreateNewProject
- GetAllProjectData - Admin only
- GetProjectData
- SetProjectData
- GetActiveAttachment
- GetAttachmentAsAdmin – Admin only
- SetProjectAttachment
- SetAttachmentMetadata
- GetAttachmentMetadata
- SubmitProject
- GetStatusList – Admin only
- GetCustomListChoices
- GetProjectStatusHistory – Admin only
- SetProjectStatus – Admin only
- GetExportProject – Admin only
- CreateMfaSessionToken
- DeleteMfaSessionToken
- SetAssignee
- SetProjectOwner
- GetInquiryThreads – Admin Only
- GetNotesInInquiryThread – Admin Only
- SetInquiryNote – Admin Only
- SetInquiryThreadStatus – Admin Only
- SetInquiryThreadExternalId – Admin Only
- SetProjectStatusReportAs – Admin only
- Code Samples
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)'"
}