SQL examples for SQL Server
The ZappySys API Driver is a user-friendly interface designed to facilitate the seamless integration of various applications with the FastSpring API. With its intuitive design and robust functionality, the ZappySys API Driver simplifies the process of configuring specific API endpoints to efficiently read or write data from FastSpring.
On this page you will find some SQL examples which can be used for API ODBC Driver or Data Gateway API Connector.
Read orders
Read all orders
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Orders';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read a single order by id
Read a single order by id
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Orders Where Id=''zzzzzzzzzz''';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read orders with date range
Read all orders within specific date range
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Orders WITH(StartDate=''2020-01-01'', EndDate=''2021-12-31'' ) --use function like today, yesterday, yearstart, monthstart, yearstart-1y';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read orders placed in last 30 days
Read all orders placed in last 30 days. This hows how to use function like today, yesterday, yearstart, monthstart, yearstart-1y etc for date parameters
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Orders
--WHERE Currency=''USD'' and TotalInPayoutCurrency>=1599
WITH(StartDate=''today-30day'', EndDate=''today'') --try today, yesterday, yearstart, yearend, monthstart, monthend, yearstart-1y so on';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read product ids
Read all orders
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM get_product_ids';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read product details
Read all products
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Products';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read a single product by id
Read a single product by id
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Products Where Id=''some-product-id''';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Read product prices
List product prices for specified currency or country. If you do not pass Country or Currency Parameter then all prices for all countries listed
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT
Product,
Country,
Currency,
Price,
PriceDisplay,
Discount2DiscountPercent,
Discount2DiscountValue,
Discount2DiscountValueDisplay,
Discount2UnitPrice,
Discount2UnitPriceDisplay,
Discount3DiscountPercent,
Discount3DiscountValue,
Discount3DiscountValueDisplay,
Discount3UnitPrice,
Discount3UnitPriceDisplay,
Discount4DiscountPercent,
Discount4DiscountValue,
Discount4DiscountValueDisplay,
Discount4UnitPrice,
Discount4UnitPriceDisplay,
Discount5DiscountPercent,
Discount5DiscountValue,
Discount5DiscountValueDisplay,
Discount5UnitPrice,
Discount5UnitPriceDisplay,
DiscountReasonEn,
DiscountPeriodCount,
AvailableStart,
AvailableEnd,
SetupFeePrice,
SetupFeePriceDisplay,
SetupFeeReasonEn
FROM ProductPrices
--WITH(Country=''US'') --//get prices for a specific country
--WITH(Currency=''USD'') --//get proces for a specific currency';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Update Product
Update product attributes by its ID
DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE Products
SET
Display=''Product ABCD''
, Sku=''PRD-ABCD-01''
, Summary=''Product Abcd **STD**''
, Description=''This product can be used to call **API** supports markdown syntax''
, Action=''**Action** supports markdown''
, TaxCode=''DC010500''
, Image=''https://zappysys.com/api/images/ZappySys-icon.png''
, FulfillmentInstructions=''Thank you for shopping. **Activate** license by using our License App''
, Format=''digital''
, PriceUSD=''101.5''
, PriceEUR=''102.5''
, PriceGBP=''103.5''
, PriceCAD=''104.5''
, PriceNZD=''105.5''
, PriceCHF=''106.5''
, PriceSEK=''107.5''
, PriceCZK=''108.5''
, PriceDKK=''109.5''
, PricePLN=''101.5''
, PriceSGD=''102.5''
, PriceJPY=''103.5''
, PriceCNY=''104.5''
, PriceHKD=''105.5''
, PriceINR=''106.5''
, PriceBRL=''107.5''
, PriceAUD=''108.5''
, Badge=''Badge-1''
, Rank=1
, Trial=14 --how many trial days
, TrialPriceUSD=10.5
--, Renew=1 --not allowed for update : Only for create (enable subscription)
, Interval=''year'' --allowed values: adhoc, day, week, year, only needed if you are creating a subscription
, IntervalLength=1
, IntervalCount=0
, QuantityBehavior=''allow'' --allowed values: allow, lock, hide
, QuantityDefault=1
, Attributes = ''{"mykey-1" : "some-value-1", "mykey-2" : "some-value-2"}''
--, Fulfillments=''[ { fullfillment }, { fullfillment } ... ]'' --JSON fragment
Where Id=''abcd''';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Update multiple Products (read from CSV file)
Update multiple products from CSV file or other external source (e.g. Microsoft SQL Server, MySQL, Postgresql, ODBC)
DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE Products
SOURCE(''ODBC'',
--File input example (use as to match Column name allowed in Products Table to write)
--''Driver={ZappySys CSV Driver};DataPath=c:\data\products.csv'',
--''select P_ID as Id,P_TAXCODE as TaxCode From $''
--Direct input example
''Driver={ZappySys CSV Driver}'',
''select ''''abcd'''' as Id, ''''DC010500'''' as TaxCode UNION
select ''''xyz'''' as Id, ''''DC010500'''' as TaxCode UNION
select ''''zzz'''' as Id, ''''DC010500'''' as TaxCode
''
)';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Create or Update Product (Upsert)
Create or Update product (Upsert)
DECLARE @MyQuery NVARCHAR(MAX) = '--Insert or Update
--UPSERT INTO Products
--Insert or Update
UPSERT INTO Products
( [Id] , [Display] , [Summary]
, [Description] , [Action] , [Format]
, [Sku] , [TaxCode] , [Image]
, [Renew] , [Interval] , [IntervalLength]
, [IntervalCount] , [QuantityBehavior] , [QuantityDefault]
, [PriceUSD] , [PriceEUR] , [PriceGBP]
, [PriceCAD] , [PriceNZD] , [PriceCHF]
, [PriceSEK] , [PriceCZK] , [PriceDKK]
, [PricePLN] , [PriceSGD] , [PriceJPY]
, [PriceCNY] , [PriceHKD] , [PriceINR] , [PriceBRL] , [PriceAUD]
, [Trial]
, [TrialPriceUSD] , [TrialPriceEUR] , [TrialPriceGBP]
, [PaymentCollected] , [PaidTrial]
, [FulfillmentInstructions]
, [DateLimitsEnabled] , [CancellationInterval] , [CancellationIntervalLength]
, [SetupFeeTitle]
, [SetupFeePriceUSD] , [SetupFeePriceEUR] , [SetupFeePriceGBP]
, [Badge] , [Rank]
, [Attributes]
)
VALUES(''test-std-id''
, ''3Year **standard** subscription edition''
, ''summary **standard edition** _some italic_ '' -- markdown syntax allowed
, ''long description **test STD** and many more lines'' --markdown syntax allowed
, ''action text with **markdown** ''
, ''digital'' -- e.g. digital OR physical OR digital-and-physical
, ''TEST-STD-001''
, ''DC010500''
, ''https://zappysys.com/api/images/ZappySys-icon.png''
, true , ''year'' , 1
, 1 , ''allow'' -- e.g. allow Or lock Or hide
, 3 --stop renewal after 3 periods
, 10.12 , 11.12 , 12.12
, 13.12 , 14.12 , 15.12
, 16.12 , 17.12 , 18.12
, 19.12 , 20.12 , 21.12
, 22.12 , 23.12 , 24.12 , 25.12 , 26.12
, 14 --how many days trial allowed
, 10.12 , 11.12 , 12.12
, ''true'', true
, ''Thank you for shopping, **here are** license instructions'' --markdown supported
, false, ''day'', 5
, ''Setup title''
--setup fees in common currencies
, 10.50 , 11.50 , 12.50
, ''badge-1'' , 1
, ''{"mykey-1" : "some-value-1", "mykey-2" : "some-value-2"}'' --JSON fragment
--, ''[... fullfillments.. ]'' --JSON fragment
)';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
List / Search Quotes
List or Search quotes. This example lists Open and Completed Quotes
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Quotes
WITH(
Statuses=''OPEN~COMPLETED'',
--SearchFor=''Test'' --quote contains word "Test" in Name or blling information
-- query more status like below
--Statuses=''OPEN~COMPLETED~CANCELED~EXPIRED'',
)';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
List Product Publish Status - Public=200, Private=404
List product publish status (200=Published, 404=Private)
DECLARE @MyQuery NVARCHAR(MAX) = 'select * from get_products_visibility';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
List all orders for a specific subscription
List all orders for a specific subscription
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM Orders
WHERE SubscriptionId_1=''iBPfMFS6TZSxrLzSOrq8PQ''
OR SubscriptionId_2=''iBPfMFS6TZSxrLzSOrq8PQ''
OR SubscriptionId_3=''iBPfMFS6TZSxrLzSOrq8PQ''
ORDER BY OrderDate';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Generate Subscription Report by Date, Product, Group By
Generate subscription report for selected group by columns, date range, products and more
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT *
FROM get_subscription_report
Order by transaction_date
WITH(
Country=''AL~UA~US''
, ProductPaths=''odbc-pp-ent-sub~odbc-pp-pro-sub~odbc-pp-std~ssis-pp-pro-sub~ssis-pp-std-sub~ssis-pp-ent-sub''
, StartDate=''monthstart-1m'' --or 2022-01-01
, EndDateDate=''monthend+2d'' --or 2022-01-01
, ReportColumns=''transaction_date~transaction_month~transaction_year~activations~average_mrr~cancellations~mrr~new_subscribers~subscriptions''
, GroupByColumns=''transaction_date~transaction_month~transaction_year''
)';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Generate Revenue Report by Date, Product, Group By
Generate revenue report for selected group by columns, date range, products and more
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT *
FROM get_revenue_report
Order by transaction_date
WITH(
Country=''AL~UA~US''
, ProductPaths=''odbc-pp-ent-sub~odbc-pp-pro-sub~odbc-pp-std~ssis-pp-pro-sub~ssis-pp-std-sub~ssis-pp-ent-sub''
, StartDate=''monthstart-1m'' --or 2022-01-01
, EndDateDate=''monthend+2d'' --or 2022-01-01
, ReportColumns=''Transaction_Year~Transaction_Month~Transaction_Date~Company_Name~Product_Path~Product_Units~Tax_in_USD~Transaction_Amount_in_USD~Grand_Total_In_USD''
, GroupByColumns=''transaction_date~transaction_month~transaction_year''
)';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Get all accounts
Get all accounts for your store
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT *
FROM Accounts
SELECT "Id"
, "ContactFirst"
, "ContactLast"
, "ContactEmail"
, "ContactCompany"
, "ContactPhone"
, "ContactSubscribed"
, "AddressLine1"
, "AddressLine2"
, "City"
, "Region"
, "RegionCustom"
, "PostalCode"
, "AddressCompany"
, "Language"
, "Country"
, "LookupGlobal"
, "Url"
, "PaymentMethods"
, "PaymentActive"
, "Orders"
, "Subscriptions"
, "Charges"
, "Subscribed"
, "TaxExemptionData"
FROM Accounts
--Use WITH clause --OR-- Key column(s) in WHERE clause
--WHERE [Id] = ''abcd''
--search by one or more parameters below
/*
WITH(
Email=''X''
, CustomKey=''X''
, GlobalKey=''X''
, OrderID=''X''
, OrderReference=''X''
, SubscriptionId=''X''
, Products=''PROD-1,PROD-2,PROD-3''
, Refunds=''true''
, SubscriptionStatus=''active''
)
*/';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Get all accounts with specific product orders
Use below query to search accounts who placed orders for specific products
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * from Accounts WITH(Products=''ssis-pp-pro,ssis-pp-pro-sub,ssis-pp-ent,ssis-pp-ent-sub'')';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Get account charges
Use below query to search account charges
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * from AccountCharges
--search by one or more parameters below
/*
WITH(
Email=''X''
, CustomKey=''X''
, GlobalKey=''X''
, OrderID=''X''
, OrderReference=''X''
, SubscriptionId=''X''
, Products=''PROD-1,PROD-2,PROD-3''
, Refunds=''true''
, SubscriptionStatus=''active''
)
*/';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Get account orders by email id
Use below query to search for accounts and orders with search criteria
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * from AccountOrders
WITH(
Email=''bob@abc.com''
)
--search by one or more parameters below
/*
WITH(
Email=''X''
, CustomKey=''X''
, GlobalKey=''X''
, OrderID=''X''
, OrderReference=''X''
, SubscriptionId=''X''
, Products=''PROD-1,PROD-2,PROD-3''
, Refunds=''true''
, SubscriptionStatus=''active''
)
*/';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Get specific order by reference number (rather than Id)
Search by Order by reference (fast way). If you have less rows then use Select * FROM Orders where Reference='BIX-123' it can be faster than below appproach
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * from AccountOrders WHERE Reference=''BIN240202-9666-28133'' WITH(OrderReference=''BIN240202-9666-28133'')
--or for handful rows use below way
--SELECT * from Orders WHERE Reference=''BIN240202-9666-28133''';
EXEC (@MyQuery) AT [LS_TO_FASTSPRING_IN_GATEWAY];
Learn more about this SQL query.
Getting Started with Examples
ZappySys API Driver is a powerful software solution designed to facilitate the extraction and integration of data from a wide range of sources through APIs. Its intuitive design and extensive feature set make it an essential asset for any organization dealing with complex data integration tasks.
To get started with examples using ZappySys API Driver, please click on the following applications:
Key features of the ZappySys API Driver include:
The API ODBC driver facilitates the reading and writing of data from numerous popular online services (refer to the complete list here) using familiar SQL language without learning complexity of REST API calls. The driver allows querying nested structure and output as a flat table. You can also create your own ODBC / Data Gateway API connector file and use it with this driver.
Intuitive Configuration: The interface is designed to be user-friendly, enabling users to easily set up the specific API endpoints within FastSpring without requiring extensive technical expertise or programming knowledge.
Customizable Endpoint Setup: Users can conveniently configure the API endpoint settings, including the HTTP request method, endpoint URL, and any necessary parameters, to precisely target the desired data within FastSpring.
Data Manipulation Capabilities: The ZappySys API Driver allows for seamless data retrieval and writing, enabling users to fetch data from FastSpring and perform various data manipulation operations as needed, all through an intuitive and straightforward interface.
Secure Authentication Integration: The driver provides secure authentication integration, allowing users to securely connect to the FastSpring API by inputting the necessary authentication credentials, such as API tokens or other authentication keys.
Error Handling Support: The interface is equipped with comprehensive error handling support, ensuring that any errors or exceptions encountered during the data retrieval or writing process are efficiently managed and appropriately communicated to users for prompt resolution.
Data Visualization and Reporting: The ZappySys API Driver facilitates the seamless processing and presentation of the retrieved data from FastSpring, enabling users to generate comprehensive reports and visualizations for further analysis and decision-making purposes.
Overall, the ZappySys API Driver serves as a powerful tool for streamlining the integration of applications with FastSpring, providing users with a convenient and efficient way to access and manage data, all through a user-friendly and intuitive interface.