GetCreditsUsedInDateRange
Get a count of message credits used by an account between the given dates
// uses JQuery libraryvar postUrl = 'https://secure.smsgateway.ca/services/account.svc/' + accountKey + '/CreditsUsedInDateRange';
var todayDate = new Date();var weekAgo = new Date();weekAgo.setTime(todayDate.getTime() - 7 * 24 * 3600000); // 7 days * 24 hours * 3600000 milliseconds
var body = JSON.stringify({ DateFrom: todayDate.getTime(), DateTo: weekAgo.getTime(),});
$.ajax({ url: postUrl, method: 'POST', contentType: 'application/json;charset=UTF-8', data: body,}) .done(function (response) { alert(response); }) .error(function (xhr, textStatus, errorThrown) { alert(xhr.responseText); });<?php// using SOAP Module - http://ca3.php.net/soap
class SMSParam { public $AccountKey; public $DateFrom; public $DateTo}
$client = new SoapClient('https://secure.smsgateway.ca/sendsms.asmx?WSDL');$parameters = new SMSParam;
$parameters -> AccountKey = accountKey;$parameters -> DateFrom = '2016-01-01';$parameters -> DateTo = '2016-02-01';
$Result = $client->GetCreditsUsedInDateRange($parameters);?>' Service Reference (SOAP)Dim dateFrom = Date.Now.AddDays(-7)Dim dateTo = Date.Now' Service Reference (SOAP)Using client = New SwiftSMS.SendSMSSoapClient Dim response = client.GetCreditsUsedInDateRange(accountKey, dateFrom, dateTo)End Using
' WebClient (REST)Dim url = String.Format("https://secure.smsgateway.ca/services/account.svc/{0}/CreditsUsedInDateRange", accountKey)Dim body = String.Format("{{ ""DateFrom"": ""/Date({0})/"", " & _ " ""DateTo"" : ""/Date({1})/"" " & _ "}}", epochDateFrom, epochDateTo)
Using wClient = New Net.WebClient wClient.Encoding = New UTF8Encoding() wClient.Headers.Add(HttpRequestHeader.ContentType, "application/json")
Dim wResponse = wClient.UploadString(url, body)End Using
' Function to convert .NET Date to JSON friendly Epoch date (in milliseconds)Public Function DateTimeToEpoch(ByVal DateTimeValue As Date) As Long ' Try Return CLng(DateTimeValue.Subtract(CDate("1.1.1970 00:00:00")).TotalSeconds) * 1000 Catch ex As System.OverflowException Return -1 End Try
End Functioncurl -X POST https://secure.smsgateway.ca/services/account.svc/[accountKey]/CreditsUsedInDateRange ^ -H "Content-Type:application/json" -d @data.txtvar dateFrom = DateTime.Now.AddDays(-7);var dateTo = DateTime.Now;
// Service Reference / SOAPusing (var client = new SwiftSMS.SendSMSSoapClient()){ var messagesUsed = client.GetCreditsUsedInDateRange(accountKey, dateFrom, dateTo);}
// Web Client / RESTdynamic body = new ExpandoObject();
// Convert .NET date/time to javascript friendly Unix epochsvar DatetimeMinTimeTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;body.DateFrom = "/Date(" + ((dateFrom.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000) + ")/";body.DateTo = "/Date(" + ((dateTo.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000) + ")/";
var url = string.Format("https://secure.smsgateway.ca/services/account.svc/{0}/CreditsUsedInDateRange", accountKey);
using (var wClient = new System.Net.WebClient()){ wClient.Encoding = Encoding.UTF8; wClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
var messagesUsed = wClient.UploadString(url, Newtonsoft.Json.JsonConvert.SerializeObject(body));}HTTP Request
GET:
/services/account.svc/:accountKey/CreditsUsedInDateRange| Parameter | Description | Location |
|---|---|---|
| AccountKey | Your Swift SMS Gateway account key | URL |
| DateFrom | Start date for credit usage report | BODY |
| DateTo | End date for credit usage report | BODY |
Returns
integer