Wolfram Language

Cloud & Web Interfaces

Upload Files to a Sales Tax Analysis API

You can upload files to a web server using URLRead.

Create a cloud object that analyzes a sales tax report from an online retailer.

show complete Wolfram Language input
Click for copyable input
salesTaxReportAsText[rawdata_] := With[{data = Map[extract, Rest[rawdata]]}, StringReplace[ ToString[ Column[{"Order Report", Grid[Join[{extract[First[rawdata]]}, Map[format, data, {2}], {{"Total:", format@Total[data[[All, 2]]], format@Total[data[[All, 3]]]}}], Alignment -> Right], "", "", Row[{"Total orders with no tax: ", Total[Cases[data, {_, n_ /; n == 0, _}][[All, 3]]]}]}], OutputForm], "\n\n" -> "\n"]] extract[r_] := {First[r], r[[20]], r[[21]]} format[x_] := Replace[x, {n_?NumericQ :> NumberForm[n, {Infinity, 2}]}] orders = CloudDeploy[ APIFunction[{"orders" -> "CSV"}, salesTaxReportAsText[#orders] &, "Text"], "orders.api", Permissions -> "Public"]

Visit https://www.amazon.com/gp/b2b/reports to run a report on orders for a time range. Download the CSV file. Or create a file with demonstration data.

Click for copyable input
Export["orders.csv", "Order Date,Order ID,Payment Instrument Type,Website,Purchase Order \ Number,Ordering Customer Email,Shipment Date,Shipping Address \ Name,Shipping Address Street 1,Shipping Address Street 2,Shipping \ Address City,Shipping Address State,Shipping Address Zip,Order \ Status,Carrier Name & Tracking Number,Subtotal,Shipping Charge,Tax \ Before Promotions,Total Promotions,Tax Charged,Total Charged,Buyer \ Name,Group Name 01/12/16,610,Visa - \ 2493,Amazon.com,,customer@example.com,01/14/16,Alf B. Charlie,34 W \ Reindeer Tr,,Slaterock,KS,66083,Shipped,SUREPOST(1ZW532553XVFG),$36.\ 11,$5.55,$0.00,$5.55,$0.00,$36.11,Alf B. Charlie,none 01/22/16,111,Visa - \ 2493,Amazon.com,,customer@example.com,01/23/16,Alf B. Charlie,34 W \ Reindeer Tr,,Slaterock,KS,66083,Shipped,QUICKSHIP(28zvW),$215.90,$3.\ 86,$0.00,$3.86,$0.00,$215.90,Alf B. Charlie,none 03/07/16,729,Visa - \ 0832,Amazon.com,,customer@example.com,03/07/16,Alf B. Charlie,34 W \ Reindeer Tr,,Slaterock,KS,66083,Shipped,QUIKSHIP(29xcdQ),$48.95,$3.86,\ $4.28,$3.86,$4.28,$48.95,Alf B. Charlie,none 08/25/16,729,Visa - \ 0832,Amazon.com,,customer@example.com,08/25/16,Alf B. Charlie,34 W \ Reindeer Tr,,Slaterock,KS,66083,Shipped,QUIKSHIP(53fGkM),$69.48,$3.86,\ $6.08,$3.86,$6.08,$69.48,Alf B. Charlie,none", "Text"]

Call the report API, providing input by uploading the orders data file.

Click for copyable input
URLRead[HTTPRequest[ orders, <|"Body" -> {"orders" -> File["orders.csv"]}|>], "Body"]

Related Examples

de es fr ja ko pt-br ru zh