Smartsheet Connector
Documentation
Version: 1
Documentation

Smartsheet Connector - Using Stored Procs


T-SQL is a programming language used for managing and querying data in Microsoft SQL Server databases. We provides tools for data integration, automation, and connectivity.

If you want to use T-SQL with ZappySys, you can use our Connector, which allows you to connect to SQL Server databases and execute T-SQL queries from Smartsheet.

Create Data Source in ZappySys Data Gateway based on API Driver

  1. Download and install ZappySys ODBC PowerPack.

  2. Search for gateway in start menu and Open ZappySys Data Gateway:
    Open ZappySys Data Gateway

  3. Go to Users Tab to add our first Gateway user. Click Add; we will give it a name tdsuser and enter password you like to give. Check Admin option and click OK to save. We will use these details later when we create linked server:
    ZappySys Data Gateway - Add User

  4. Now we are ready to add a data source. Click Add, give data source a name (Copy this name somewhere, we will need it later) and then select Native - ZappySys API Driver. Finally, click OK. And it will create the Data Set for it and open the ZS driver UI.

    SmartsheetDSN

    ZappySys Data Gateway - Add Data Source

  5. When the Configuration window appears give your data source a name if you haven't done that already, then select "Smartsheet" from the list of Popular Connectors. If "Smartsheet" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:

    SmartsheetDSN
    Smartsheet
    ODBC DSN Template Selection

  6. Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.

    Steps to get Smartsheet Credentials

    OAuth Walkthrough

    Apps connect to Smartsheet using OAuth 2.0 to authenticate and authorize users. If you are building an app, this documentation will walk you through the steps you need to authenticate your users. The Smartsheet SDKs contain APIs for OAuth 2.0.

    NOTE: For users of apps like AWS AppFabric, you will need a Tenant ID. You can find your Tenant ID in Admin Center under Security & Controls. There is a Smartsheet Tenant ID pane.

    First Steps

    Before you can start using OAuth 2.0 with your app, Smartsheet needs the following information:

    1. You must register with Smartsheet to get a developer account*. The developer account gives you access to "Developer Tools", which is where you manage your app.
    2. In "Developer Tools", complete any required fields in your developer profile.
    3. In "Developer Tools", register your app so Smartsheet can assign a client Id and a client secret to the app.
    4. Review the list of access scopes. You'll need to choose which ones your app needs to get to a user's Smartsheet data, and then ask the user to consent to that access.
    5. After you've worked through these steps, you'll be ready to implement the OAuth Flow.

    Open Developer Tools

    1. Log in to Smartsheet with your developer account.
    2. Click the "Account" button in the lower-left corner of your Smartsheet screen, and then click "Developer Tools".
    3. Do one of the following:
      • If you need to register an app, click "Create New App".
      • If you need to manage an app, click "view/edit" for the app.

    Register Your App Using Developer Tools

    1. Log in to Smartsheet with your developer account.
    2. Click the "Account" button in the upper-right corner of your Smartsheet screen, and then click "Developer Tools".
    3. In the "Create New App" form, provide the following information:
      • Name: the name the user sees to identify your app
      • Description: a brief description intended for the user
      • URL: the URL to launch your app, or the landing page if not a web app
      • Contact/support: support information for the user
      • Redirect URL: also known as a callback URL. The URL within your application that will receive the OAuth 2.0 credentials After you click "Save", Smartsheet assigns a client Id and secret to your app. Make a note of these Ids for the next steps; however, you can always look them up again in "Developer Tools".

    Fill in all required parameters and set optional parameters if needed:

    SmartsheetDSN
    Smartsheet
    OAuth (Dynamic Token) [OAuth]
    https://api.smartsheet.com/2.0
    Required Parameters
    ClientId Fill in the parameter...
    ClientSecret Fill in the parameter...
    Scope Fill in the parameter...
    Optional Parameters
    RetryMode Fill in the parameter...
    RetryStatusCodeList Fill in the parameter...
    RetryCountMax Fill in the parameter...
    RetryMultiplyWaitTime Fill in the parameter...
    ODBC DSN Oauth Connection Configuration
    Steps to get Smartsheet Credentials

    Raw Token Requests

    If you want to get started quickly, or are developing a standalone application that can run with your credentials, follow these instructions:

    1. Click the "Account" button in the lower-left corner of the Smartsheet screen, and then click "Personal Settings".
    2. Click the "API Access" tab.
    3. Click the "Generate new access token" button to obtain an access token.

    The access token must be sent with every API call in an HTTP authorization header (except for therequests to Get Access Token or Refresh Access Token). Once you have an access token, include it in the Authorization header for every request you make:

    Authorization: Bearer JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789

    The header name is Authorization and the value of the header is Bearer JKlMNOpQ12RStUVwxYZAbcde3F5g6hijklM789. Since the access token is being transmitted in clear text, all API calls are done over HTTPS.

    NOTE: A best practice is to use a shared account, such as ticket-processor@example.com, rather than your individual work account.

    Fill in all required parameters and set optional parameters if needed:

    SmartsheetDSN
    Smartsheet
    Static Token [Http]
    https://api.smartsheet.com/2.0
    Required Parameters
    Access Token Fill in the parameter...
    Optional Parameters
    RetryMode Fill in the parameter...
    RetryStatusCodeList Fill in the parameter...
    RetryCountMax Fill in the parameter...
    RetryMultiplyWaitTime Fill in the parameter...
    ODBC DSN HTTP Connection Configuration

  7. Once the data source has been configured, you can preview data. Select the Preview tab and use settings similar to the following to preview data:
    ODBC ZappySys Data Source Preview

  8. Click OK to finish creating the data source.

Read data in SQL Server from the ZappySys Data Gateway

  1. To read the data in SQL Server the first thing you have to do is create a Linked Server. Go to SQL Server Management Studio and configure it in a similar way:
    SSMS SQL Server Configure Linked Server

  2. Then click on Security option and configure username we created in ZappySys Data Gateway in one of the previous steps:
    SSMS SQL Server Configure Linked Server User Name

  3. Optional: Under the Server Options, Enable RPC and RPC Out and Disable Promotion of Distributed Transactions(MSDTC).

    RPC and MSDTC Settings

    You need to enable RPC Out if you plan to use EXEC(...) AT [MY_LINKED_SERVER_NAME] rather than OPENQUERY.
    If don't enabled it, you will encounter the Server 'MY_LINKED_SERVER_NAME' is not configured for RPC error.

    Query Example:

    EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]


    If you plan to use 'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]' in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
    If don't disabled it, you will encounter the The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction. error.

    Query Example:

    Insert Into dbo.Products
     EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]
    


  4. Finally, open a new query and execute a query we saved in one of the previous steps:

    SELECT * FROM OPENQUERY([MY_LINKED_SERVER_NAME], 'SELECT * FROM Products');

    SSMS SQL Server Query Data Results

Create Linked Server using Code

In previous section you saw how to create a Linked Server from UI. You can do similar action by code too (see below). Run below script after changing necessary parameters. Assuming your Data Source name on ZappySys Data Gateway UI is 'SmartsheetDSN'

    USE [master]
    GO
    --///////////////////////////////////////////////////////////////////////////////////////
    --Run below code in SSMS to create Linked Server and use ZappySys Drivers in SQL Server
    --///////////////////////////////////////////////////////////////////////////////////////

    //Replace YOUR_GATEWAY_USER, YOUR_GATEWAY_PASSWORD
    //Replace localhost with IP/Machine name if ZappySys Gateway Running on different machine other than SQL Server
    //Replace Port 5000 if you configured gateway on a different port


    --1. Configure your gateway service as per this article https://zappysys.com/links?id=10036

    --2. Make sure you have SQL Server Installed. You can download FREE SQL Server Express Edition from here if you dont want to buy Paid version https://www.microsoft.com/en-us/sql-server/sql-server-editions-express

    --Uncomment below if you like to drop linked server if it already exists
    --EXEC master.dbo.sp_dropserver @server=N'LS_SmartsheetDSN', @droplogins='droplogins'

    --3. Create new linked server

    EXEC master.dbo.sp_addlinkedserver
      @server = N'LS_SmartsheetDSN'  --Linked server name (this will be used in OPENQUERY sql
    , @srvproduct=N''
    ---- For MSSQL 2012,2014,2016 and 2019 use below (SQL Server Native Client 11.0)---
    , @provider=N'SQLNCLI11'
    ---- For MSSQL 2022 or higher use below (Microsoft OLE DB Driver for SQL Server)---
    --, @provider=N'MSOLEDBSQL'
    , @datasrc=N'localhost,5000' --//Machine / Port where Gateway service is running
    , @provstr=N'Network Library=DBMSSOCN;'
    , @catalog=N'SmartsheetDSN' --Data source name you gave on Gateway service settings

    --4. Attach gateway login with linked server

    EXEC master.dbo.sp_addlinkedsrvlogin
    @rmtsrvname=N'LS_SmartsheetDSN'  --linked server name
    , @useself=N'False'
    , @locallogin=NULL
    , @rmtuser=N'YOUR_GATEWAY_USER' --enter your Gateway user name
    , @rmtpassword='YOUR_GATEWAY_PASSWORD'  --enter your Gateway user's password
    GO

    --5. Enable RPC OUT (This is Optional - Only needed if you plan to use EXEC(...) AT YourLinkedServerName rather than OPENQUERY
    EXEC sp_serveroption 'LS_SmartsheetDSN', 'rpc', true;
    EXEC sp_serveroption 'LS_SmartsheetDSN', 'rpc out', true;

    --Disable MSDTC - Below needed to support INSERT INTO from EXEC AT statement
    EXEC sp_serveroption 'LS_SmartsheetDSN', 'remote proc transaction promotion', false;

    --Increase query timeout if query is going to take longer than 10 mins (Default timeout is 600 seconds)
    --EXEC sp_serveroption 'LS_SmartsheetDSN', 'query timeout', 1200;
    GO

Create Custom Stored Procedure in ZappySys Driver

You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.

Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

  1. Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
    ZappySys Driver - Add Stored Procedure

  2. Enter the desired Procedure name and click on OK:
    ZappySys Driver - Add Stored Procedure Name

  3. Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver:
    Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

    CREATE PROCEDURE [usp_get_orders]
        @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>'
     AS
        SELECT * FROM Orders where OrderDate >= '<@fromdate>';
    

    ZappySys Driver - Create Custom Stored Procedure

  4. That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:

    Exec usp_get_orders '1996-01-01';

    ZappySys Driver - Execute Custom Stored Procedure

  5. Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
    As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.

    SELECT * FROM OPENQUERY([MY_API_SERVICE], 'EXEC usp_get_orders @fromdate=''1996-07-30''')

    ZappySys Driver - Generate SQL Server Query

  6. Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
    ZappySys Driver - Generate SQL Server Query