Skip to content

Instantly share code, notes, and snippets.

@callemall
Created July 31, 2013 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callemall/6123574 to your computer and use it in GitHub Desktop.
Save callemall/6123574 to your computer and use it in GitHub Desktop.
This example uses the CheckAccount function to retrieve some basic information and settings on an account including its status, the available call balance, and most of the settings seen on the "My Account" tab when logged in to a Call-Em-All account.
# ======================================================
# Programming Example on how to check account balance
# ======================================================
function CheckAccount
(
[String] $username,
[String] $pin
)
{
$URL = "http://staging-api.call-em-all.com/webservices/ceaapi_v2.asmx"
$Action = "http://call-em-all.com/CheckAccount"
[XML] $SOAPRequest = '<?xml version="1.0" encoding="utf-8"?>
&lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
&lt;soap:Body&gt;
&lt;CheckAccount xmlns="http://call-em-all.com/"&gt;
&lt;myRequest&gt;
&lt;username&gt;' + $username +'&lt;/username&gt;
&lt;pin&gt;' + $pin + '&lt;/pin&gt;
&lt;/myRequest&gt;
&lt;/CheckAccount&gt;
&lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;'
write-host "Sending SOAP Request To Server: $URL"
write-host "SOAP Request : " + $SOAPRequest
$soapWebRequest = [System.Net.WebRequest]::Create($URL)
$soapWebRequest.Headers.Add("SOAPAction", $Action)
$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
$soapWebRequest.Accept = "text/xml"
$soapWebRequest.Method = "POST"
write-host "Initiating Send."
$requestStream = $soapWebRequest.GetRequestStream()
$SOAPRequest.Save($requestStream)
$requestStream.Close()
write-host "Send Complete, Waiting For Response."
$resp = $soapWebRequest.GetResponse()
$responseStream = $resp.GetResponseStream()
$soapReader = [System.IO.StreamReader]($responseStream)
$ReturnXml = [Xml] $soapReader.ReadToEnd()
$responseStream.Close()
write-host "============================================"
write-host "errorCode " $ReturnXml.Envelope.Body.CheckAccountResponse.CheckAccountResult.errorCode
write-host "errorMessage " $ReturnXml.Envelope.Body.CheckAccountResponse.CheckAccountResult.errorMessage
write-host "Call Balance " $ReturnXml.Envelope.Body.CheckAccountResponse.CheckAccountResult.CallBalance
write-host "CallerID " $ReturnXml.Envelope.Body.CheckAccountResponse.CheckAccountResult.CallerID
write-host "============================================"
return [xml] $ReturnXml
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment