Call generic API request
Calls a generic Shopify REST API endpoint (e.g. /products.json) using the generic_request table. This allows accessing any REST endpoint by specifying the URL, RequestMethod, and other parameters.
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
SELECT * FROM generic_request
WITH (
URL='/products.json'
--OR Use full URL
--URL='https://MY-STORE-HERE.myshopify.com/admin/api/2023-01/products.json'
, RequestMethod='GET'
, Body='{}' --needed if you call PUT, POST
, Filter='$.products[*]' --change table name here
, Headers='Content-Type: application/json'
, PagingMode='ByResponseHeaderRfc5988'
--Use metadata to speed up execution. To get Metadata Run query without Meta clause.
--Then click View Metadata button found in Botttom Result Grid Toolbar. Get Compact format and paste below
, Meta='id:String(255); title:String(255); created_at:DateTime; '
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_SHOPIFY_IN_GATEWAY], 'SELECT * FROM generic_request
WITH (
URL=''/products.json''
--OR Use full URL
--URL=''https://MY-STORE-HERE.myshopify.com/admin/api/2023-01/products.json''
, RequestMethod=''GET''
, Body=''{}'' --needed if you call PUT, POST
, Filter=''$.products[*]'' --change table name here
, Headers=''Content-Type: application/json''
, PagingMode=''ByResponseHeaderRfc5988''
--Use metadata to speed up execution. To get Metadata Run query without Meta clause.
--Then click View Metadata button found in Botttom Result Grid Toolbar. Get Compact format and paste below
, Meta=''id:String(255); title:String(255); created_at:DateTime; ''
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_SHOPIFY_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM generic_request
WITH (
URL=''/products.json''
--OR Use full URL
--URL=''https://MY-STORE-HERE.myshopify.com/admin/api/2023-01/products.json''
, RequestMethod=''GET''
, Body=''{}'' --needed if you call PUT, POST
, Filter=''$.products[*]'' --change table name here
, Headers=''Content-Type: application/json''
, PagingMode=''ByResponseHeaderRfc5988''
--Use metadata to speed up execution. To get Metadata Run query without Meta clause.
--Then click View Metadata button found in Botttom Result Grid Toolbar. Get Compact format and paste below
, Meta=''id:String(255); title:String(255); created_at:DateTime; ''
)'
EXEC (@MyQuery) AT [LS_TO_SHOPIFY_IN_GATEWAY]