Interface Details: - .NET Framework



Automatic Billing Access: API Technical SpecTable of Contents TOC \o "1-3" \h \z \u 1.Interface Details: PAGEREF _Toc428263154 \h 22.Status codes PAGEREF _Toc428263155 \h 23.GetUsageList Call Details PAGEREF _Toc428263156 \h 34.GetUsageByMonth Call Details PAGEREF _Toc428263157 \h 55.Client sample code PAGEREF _Toc428263158 \h 6a.Source code: PAGEREF _Toc428263159 \h 6b.Sample code to call the API PAGEREF _Toc428263160 \h 6c.Javascript for downloading report PAGEREF _Toc428263161 \h 8Interface Details:?NameUriCommentTech DesignGetUsageListGET /rest/{enrollment}/usage-reportsGet the list of months when usage reports are availableUsage Restful APIGetUsageByMonthGET /rest/{enrollment}/usage-report?month={month}&type={type}&fmt={format}Get the usage report for the specified month, report type and format.Usage Restful API?Status codes?descriptioncodemessageNo error200OKVersion is missing400Version expectedJWT is invalid, format wrong401UnauthorizedJWT is expired401UnauthorizedJWT is revoked401UnauthorizedReport file not available404Report not availableEnrollment number not found404Enrollment number not found??GetUsageList Call Details?Description: Get the list of month when usage reports are available.?Request:GET /rest/{enrollment}/usage-reports?enrollment: the enrollment number?Headerapi-version: Specifies the version of the API requested. (format: yyyy-mm-dd)Authorization: bearer {access key}?Response:?Status code: See status code in the All page.Status Message: See status message in the All page?Headerapi-version: Specifies the version of the API requested. (format: yyyy-mm-dd). Note: this version number is reserved for future extension. By default, add 2014-09-02?body?JSON:JSON definition{object_type,contract_version,[{Month,LinkToDownloadSummaryReport,LinkToDownloadDetailReport,LinkToDownloadStoreChargeReport,LinkToDownloadPriceSheetReport},{Month,LinkToDownloadSummaryReport,LinkToDownloadDetailReport,LinkToDownloadStoreChargeReport,LinkToDownloadPriceSheetReport}]}Sample JSON{ "AvailableMonths": [ { "Month": "2015-08", "LinkToDownloadSummaryReport": "rest/8283365/usage-report?month=2015-08&type=summary&fmt=csv", "LinkToDownloadDetailReport": "rest/8283365/usage-report?month=2015-08&type=detail&fmt=csv", "LinkToDownloadStoreChargeReport": "rest/8283365/usage-report?month=2015-08&type=storecharge&fmt=csv", "LinkToDownloadPriceSheetReport": "rest/8283365/usage-report?month=2015-08&type=pricesheet&fmt=csv" }, { "Month": "2015-07", "LinkToDownloadSummaryReport": "rest/8283365/usage-report?month=2015-07&type=summary&fmt=csv", "LinkToDownloadDetailReport": "rest/8283365/usage-report?month=2015-07&type=detail&fmt=csv", "LinkToDownloadStoreChargeReport": "rest/8283365/usage-report?month=2015-07&type=storecharge&fmt=csv", "LinkToDownloadPriceSheetReport": "rest/8283365/usage-report?month=2015-07&type=pricesheet&fmt=csv" } ], "ContractVersion": "1.0", "ObjectType": "Usage"}?Response object view{AvailableMonths: Array of{ObjectType: ApiResourceObjectTypeContract_Version:ApiVersionMonth: string,LinkToDownloadSummaryReport: stringLinkToDownloadDetailReport: stringLinkToDownloadStoreChargeReport: stringLinkToDownloadPriceSheetReport: string}}GetUsageByMonth Call Details?Description: Get the usage report for the specified month and report type..Request:GET /rest/{enrollment}/usage-report?month={month}&type={type}&fmt={format}?Enrollment: the enrollment numberMonth -- the month of the report. Should be in the format of yyyy-MM. if not specified, default to current month.Type -- the type of the report. Should be Summary / Detail / StoreCharge / PriceSheet. If not specified, default to Summary.fmt -- the format of the report. Should be CSV or JSON. If not specified, default to CSV.?Headerapi-version: Specifies the version of the API requested. (format: yyyy-mm-dd). Note: this version number is reserved for future extension. By default, add 2014-09-02Authorization: bearer {Access key}?Response:?Status code: See status code in the All page.Status Message: See status message in the All page?Headerapi-version: Specifies the version of the API requested. (format: yyyy-mm-dd)ETag: a version number for the report. When it’s different from the client version, the server version is changed from the last time the api is calledLastModified: the last modified time of the report. Content-Type: “text/csv” or “application/json”?BodyReport file binary stream if fmt parameter is CSVJSON if fmt parameter is JSON???Client sample codeSource code: HYPERLINK "" code to call the API for small size reportHere is client code sample for how to call the APIs. The response is the json from the service. The two public methods are the entry points for the API calls. They construct web request by calling GetResponse method, which constructs the header by calling Addheaders method.string downloadUsageByMonthUrlTemplate = "{0}/usage-report?month={1}&type={2}&fmt={3}"; string getUsageListUrlTemplate = "{0}/usage-reports";public string GetEnrollmentUsageByMonth(DateTime month, UsageReportType type, string fmt, string enrollmentNumber, string jwt) { string url = string.Format(downloadUsageByMonthUrlTemplate, enrollmentNumber, month, type, fmt); string response = GetResponse(url, jwt); return response; } public string GetEnrollmentUsageList(string enrollmentNumber, string jwt) { string url = string.Format(getUsageListUrlTemplate, enrollmentNumber); string response = GetResponse(url, jwt); return response; } private string GetResponse(string url, string jwt) { WebRequest request = WebRequest.Create(url); request.Timeout = 1000 * 60 * 5; if (!string.IsNullOrEmpty(jwt)) { AddHeaders(request, jwt); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var contentType = response.Headers["Content-Type"]; StreamReader reader = new StreamReader(response.GetResponseStream()); string s = reader.ReadToEnd(); return s; } private void AddHeaders(WebRequest request, string jwt) { string bearerTokenHeader = "bearer "+jwt; request.Headers.Add("authorization", bearerTokenHeader);//looks like authorization: bearer abcdefghijklmnopqrstuvwxyzIAmHappyWhatAboutYou request.Headers.Add("api-version", "2014-09-02"); }Now you’ve got the json response and you can deserialize it into an object. Here is a sample object you may have for monthly usage report.And here is sample code for usage list.public class UsageReportListApiResponse { [DataMember] public UsageMonth[] AvailableMonths { get; set; }}[DataContract] public class UsageMonth { [DataMember] public DateTime Month { get;set; } [DataMember] public string LinkToDownloadSummaryReport { Get;set; } [DataMember] public string LinkToDownloadDetailReport { Get;set; }} [DataMember] public string LinkToDownloadStoreChargeReport { Get;set; }} [DataMember] public string LinkToDownloadPriceSheetReport { Get;set; }}Sample code to call the API for big size reportIn order to improve the customer experience and API performance, when usage report records go beyond 80K, the server responds with the streaming content, this allows customer to download as big as 1TB report. To utilize the streaming approach, replace above “GetResponse()” with below “GetResponseStream()”. Below code is compatible to the small size report. private string GetResponseStream(string url, string jwt) { WebRequest request = WebRequest.Create(url); //keep request openning for 5 minutes. the socket will close either file is downloaded or longer than 5 minutes request.Timeout = 1000 * 60 * 5; if (!string.IsNullOrEmpty(jwt)) { AddHeaders(request, jwt); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); var localfile = "c:/temp/output.txt"; FileStream writeStream = new FileStream("c:/temp/output.txt", FileMode.Create, FileAccess.Write); ReadWriteStream(response.GetResponseStream(), writeStream); } private void ReadWriteStream(Stream readStream, Stream writeStream) { int Length = 4096; Byte[] buffer = new Byte[Length]; int bytesRead = readStream.Read(buffer, 0, Length); // write the required bytes while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = readStream.Read(buffer, 0, Length); writeStream.Flush(); } readStream.Close(); writeStream.Close(); }Javascript for downloading reportfunction buttonclick() { var url = ''; var authHeader = 'bearer abcdefghijklmnopqrstuvwxyzIAmHappyWhatAboutYou'; ///the auth key for the test enrollment (EnrollmentNumber 100) can be found here. var req = new XMLHttpRequest(); req.open('GET', url, false); req.setRequestHeader('authorization', authHeader); req.overrideMimeType('application/octet-stream'); req.send(null); var response = req.response; //do things to the response. } ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download