---
title: "View source for Interacting With Api - DreamFactory Wiki"
source: "https://wiki.dreamfactory.com/index.php?action=edit&title=Interacting_With_Api"
canonical_url: "https://wiki.dreamfactory.com/index.php?action=edit&title=Interacting_With_Api"
converted_at: "2026-10-23T20:50:43.873Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for Interacting With Api

	
		
		← [Interacting With Api](/Interacting_With_Api)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=Interacting With Api - DreamFactory Documentation
|title_mode=replace
|canonical=https://wiki.dreamfactory.com/Interacting_With_Api
|og:title=Interacting With Api
|og:type=article
|og:site_name=DreamFactory Documentation
}}
'''Learn to interact with DreamFactory APIs using HTTP clients for CRUD operations, filtering, joins, and stored procedures'''

&lt;span id="interacting-with-the-api">&lt;/span>
= Interacting with the API =

The following topic contains examples to help you become familiar with the many ways you can interact with a database-backed API. For these examples we're using the Insomnia HTTP client, however you can use any similar client or even cURL to achieve the same results.

&lt;span id="retrieving-all-records">&lt;/span>
=== Retrieving all records ===

Let's begin by retrieving all of a particular table's records just as was done within the API Docs example. Open your client and in the address bar set the URL to &lt;code>/api/v2/{service_name}/{table_name}&lt;/code>, replacing &lt;code>{service_name}&lt;/code> with the name of your API and &lt;code>{table_name}&lt;/code> with the name of a table found within the database (and to which your API key's associated role has access). For the remainder of this example we use &lt;code>mysql&lt;/code> as the service name, and in this particular example the table we're querying is called &lt;code>employees&lt;/code> so the URL looks like this:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees&lt;/syntaxhighlight>
Also, because we're retrieving records the method is set to &lt;code>GET&lt;/code>.

Next, you must set the header which defines the API key. This header should be named &lt;code>X-DreamFactory-Api-Key&lt;/code>. You might have to hunt around for a moment within your HTTP client to figure out where this is placed, but we promise it is definitely there. In the case of Insomnia select the '''Header''' tab found directly below the address bar:

[[File:insomnia-api-key.png|thumb|Setting DreamFactory API Key Header]]

With the URL and header in place, request the URL and you should see the table records returned in JSON format:

[[File:insomnia-all-records.png|thumb|JSON response of GET Request for All Records]]

The equivalent SQL query would look like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees;&lt;/syntaxhighlight>
&lt;span id="limiting-results">&lt;/span>
=== Limiting results ===

The previous example returns all records found in the &lt;code>employees&lt;/code> table. But what if you only wanted to return five or ten records? You can use the &lt;code>limit&lt;/code> parameter to do so. Modify your URL to look like this:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?limit=10&lt;/syntaxhighlight>
The equivalent SQL query would look like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees LIMIT 10;&lt;/syntaxhighlight>
&lt;span id="offsetting-results">&lt;/span>
=== Offsetting results ===

The above example limits your results found in the &lt;code>employees&lt;/code> table to 10, but what if you want to select records 11 - 20? You would use the &lt;code>offset&lt;/code> parameter like this:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?limit=10&amp;offset=10&lt;/syntaxhighlight>
The equivalent SQL query would look like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees LIMIT 10 OFFSET 10;&lt;/syntaxhighlight>
&lt;span id="ordering-results">&lt;/span>
=== Ordering results ===

You can order results by any column using the &lt;code>order&lt;/code> parameter. For instance to order the &lt;code>employees&lt;/code> tab by the &lt;code>emp_no&lt;/code> field, modify your URL to look like this:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?order=emp_no&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees ORDER BY emp_no;&lt;/syntaxhighlight>
To order in descending fashion, just append &lt;code>desc&lt;/code> to the &lt;code>order&lt;/code> string:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?order=emp_no%20desc&lt;/syntaxhighlight>
{{Note|title=Note The space separating &lt;code>emp_no&lt;/code> and &lt;code>desc&lt;/code> has been HTML encoded. Most programming languages offer HTML encoding capabilities either natively or through a third-party library so there's no need for you to do this manually within your applications. The equivalent SQL query looks like this: :::|&lt;syntaxhighlight lang="sql">SELECT * FROM employees ORDER BY emp_no DESC;&lt;/syntaxhighlight>
&lt;span id="selecting-specific-fields">&lt;/span>
=== Selecting specific fields ===

Often you only require a few of the fields found in a table. To limit the fields returned, use the &lt;code>fields&lt;/code> parameter:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?fields=emp_no%2Clast_name&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT emp_no, last_name FROM employees;&lt;/syntaxhighlight>
&lt;span id="filtering-records-by-condition">&lt;/span>
=== Filtering records by condition ===

You can filter records by a particular condition using the &lt;code>filter&lt;/code> parameter. For instance to return only those records having a &lt;code>gender&lt;/code> equal to &lt;code>M&lt;/code>, set the &lt;code>filter&lt;/code> parameter like so:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?filter=(gender=M)&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees where gender='M';&lt;/syntaxhighlight>
You're free to use any of the typical comparison operators, such as &lt;code>LIKE&lt;/code>:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?filter=(last_name%20like%20G%25)&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees where last_name LIKE 'G%';&lt;/syntaxhighlight>
&lt;span id="combining-parameters">&lt;/span>
=== Combining parameters ===

The REST API's capabilities really begin to shine when combining multiple parameters together. For example, let's query the &lt;code>employees&lt;/code> table to retrieve only those records having a &lt;code>last_name&lt;/code> beginning with &lt;code>G&lt;/code>, ordering the results by &lt;code>emp_no&lt;/code>:

&lt;syntaxhighlight lang="text">http://localhost/api/v2/_table/employees?filter=(last_name%20like%20G%25)&amp;order=emp_no&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees where last_name LIKE 'G%' ORDER BY emp_no;&lt;/syntaxhighlight>
&lt;span id="querying-by-primary-key">&lt;/span>
=== Querying by primary key ===

You may want to select a specific record using a column that uniquely defines it. Often (but not always) this unique value is the ''primary key''. You can retrieve a record using its primary key by appending the value to the URL like so:

&lt;syntaxhighlight lang="text">/api/v2/_table/supplies/45&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM supplies where id = 5;&lt;/syntaxhighlight>
If you'd like to use this URL format to search for another unique value not defined as a primary key, you must also pass along the &lt;code>id_field&lt;/code> and &lt;code>id_type&lt;/code> fields like so:

&lt;syntaxhighlight lang="text">/api/v2/_table/employees/45abchdkd?id_field=guid&amp;id_type=string&lt;/syntaxhighlight>
&lt;span id="joining-tables">&lt;/span>
=== Joining tables ===

One of DreamFactory's most interesting database-related features is the automatic support for table joins. When DreamFactory creates a database-backed API, it parses all of the database tables, learning everything it can about the tables, including the column names, attributes, and relationships. The relationships are assigned aliases, and presented for referential purposes within DreamFactory's &lt;code>Schema&lt;/code> tab. For instance, the following screenshot contains the list of relationship aliases associated with the &lt;code>employees&lt;/code> table:

[[File:mysql-relationships.png|thumb|Joining Tables with DreamFactory]]

Using these aliases along with the &lt;code>related&lt;/code> parameter we can easily return sets of joined records via the API. For instance, the following URI would be used to join the &lt;code>employees&lt;/code> and &lt;code>departments&lt;/code> tables together:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/employees?related=dept_emp_by_emp_no&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">SELECT * FROM employees
    LEFT JOIN departments on employees.emp_no = departments.emp_no;&lt;/syntaxhighlight>
The joined results are presented within a JSON array having a name matching that of the alias:

&lt;syntaxhighlight lang="json">    {
        "emp_no": 10001,
        "birth_date": "1953-09-02",
        "first_name": "Georgi",
        "last_name": "Facello",
        "gender": "M",
        "hire_date": "1986-06-26",
        "birth_year": "1953",
        "dept_emp_by_emp_no": [
            {
                "emp_no": 10001,
                "dept_no": "d005",
                "from_date": "1986-06-26",
                "to_date": "9999-01-01"
            }
        ]
    }&lt;/syntaxhighlight>
&lt;span id="inserting-records">&lt;/span>
=== Inserting records ===

To insert a record, send a &lt;code>POST&lt;/code> request to the API, passing along a JSON-formatted payload. For instance, to add a new record to the &lt;code>supplies&lt;/code> table, send a &lt;code>POST&lt;/code> request to the following URI:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/supplies&lt;/syntaxhighlight>
The body payload would look like this:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "name": "Stapler"
            }
        ]
    }&lt;/syntaxhighlight>
If the request is successful, DreamFactory returns a &lt;code>200&lt;/code> status code and a response containing the record's primary key:

&lt;syntaxhighlight lang="json">    {
        "resource": [
          {
            "id": 9
          }
        ]
    }&lt;/syntaxhighlight>
&lt;span id="adding-records-to-multiple-tables">&lt;/span>
==== Adding records to multiple tables ====

If you want to create a new record and associate it with another table, you can use a single HTTP request. Consider the following two tables. The first, &lt;code>supplies&lt;/code>, manages a list of company supplies (staplers, brooms, etc). The company requires that all supply are closely tracked in the corporate database, and so another table, &lt;code>locations&lt;/code>, exists for this purpose. Each record in the &lt;code>locations&lt;/code> table includes a location name and foreign key reference to a record found in the &lt;code>supplies&lt;/code> table.}}note Note In the real world the location names would likely be managed in a separate table and then a join table would relate locations and supplies together. We're just trying to keep things simple for the purposes of this demonstration. :::

The table schemas look like this:

&lt;syntaxhighlight lang="sql">
CREATE TABLE `supplies` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

CREATE TABLE `locations` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `supply_id` int(10) unsigned NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `supply_id` (`supply_id`),
  CONSTRAINT `locations_ibfk_1` FOREIGN KEY (`supply_id`) REFERENCES `supplies` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
&lt;/syntaxhighlight>
Remember from the last example that DreamFactory creates convenient join aliases which can be used in conjunction with the &lt;code>related&lt;/code> parameter. In this case, that alias is &lt;code>locations_by_supply_id&lt;/code>. To create the relationship alongside the new &lt;code>supplies&lt;/code> record, use that alias to nest the location name within the payload, as demonstrated here:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "name": "Broom",
                "locations_by_supply_id": [
                    {
                        "name": "Broom Closet"
                    }
                ]
            }
        ]
    }&lt;/syntaxhighlight>
With the payload sorted out, all that remains is to make a request to the &lt;code>supplies&lt;/code> table endpoint:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/supplies&lt;/syntaxhighlight>
If the nested insert is successful, a &lt;code>200&lt;/code> status code is returned along with the primary key ID of the newly inserted &lt;code>supplies&lt;/code> record:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "id": 15
            }
        ]
    }&lt;/syntaxhighlight>
&lt;span id="updating-records">&lt;/span>
=== Updating records ===

Updating database records is a straightforward matter in DreamFactory. However to do so you first need to determine which type of REST update you wany to perform. Two options are supported:

* '''PUT''': The &lt;code>PUT&lt;/code> request replaces an existing resource in its entirety. This means you need to pass along ''all'' of the resource attributes regardless of whether the attribute value is actually being modified.
* '''PATCH''': The &lt;code>PATCH&lt;/code> request updates only part of the existing resource, meaning you only need to supply the resource primary key and the attributes you'd like to update. This is typically a much more convenient update approach than &lt;code>PUT&lt;/code>, although both have their uses.

Let's work through update examples involving each method.

&lt;span id="updating-records-with-put">&lt;/span>
==== Updating records with PUT ====

When updating records with &lt;code>PUT&lt;/code> you must send along ''all'' of the record attributes within the request payload:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "emp_no": 500015,
                "birth_date": "1900-12-15",
                "first_name": "Johnny",
                "last_name": "Football",
                "gender": "m",
                "hire_date": "2007-01-01"
            }
        ]
    }&lt;/syntaxhighlight>
With the payload in place, send a &lt;code>PUT&lt;/code> request to the &lt;code>employees&lt;/code> table endpoint:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/employees&lt;/syntaxhighlight>
If successful, DreamFactory returns a &lt;code>200&lt;/code> status code and a response body containing the primary key of the updated record:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "emp_no": 500015
            }
        ]
    }&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">    UPDATE supplies SET first_name = 'Johnny', last_name = 'Football',
    birthdate = '1900-12-15', gender = 'm', hire_date = '2007-01-01' WHERE emp_no = 500015;&lt;/syntaxhighlight>
&lt;span id="updating-records-with-patch">&lt;/span>
==== Updating records with PATCH ====

To update one or more (but not all) attributes associated with a particular record found in the &lt;code>supplies&lt;/code> table, send a &lt;code>PATCH&lt;/code> request to the &lt;code>supplies&lt;/code> table endpoint, accompanied by the primary key:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/supplies/8&lt;/syntaxhighlight>
Suppose the &lt;code>supplies&lt;/code> table includes attributes such as &lt;code>name&lt;/code>, &lt;code>description&lt;/code>, and &lt;code>purchase_date&lt;/code>, but we only want to modify the &lt;code>name&lt;/code> value. The JSON request body would look like this:

&lt;syntaxhighlight lang="json">    {
      "name": "Silver Stapler"
    }&lt;/syntaxhighlight>
If successful, DreamFactory returns a &lt;code>200&lt;/code> status code and a response body containing the primary key of the updated record:

&lt;syntaxhighlight lang="json">    {
      "id": 8
    }&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;code>UPDATE supplies SET name = 'Silver Stapler' WHERE id = 8;&lt;/code>

&lt;span id="deleting-records">&lt;/span>
=== Deleting records ===

To delete a record, send a &lt;code>DELETE&lt;/code> request to the table endpoint associated with the record you'd like to delete. For instance, to delete a record from the &lt;code>employees&lt;/code> table, reference this URL:

&lt;syntaxhighlight lang="text">/api/v2/mysql/_table/employees/500016&lt;/syntaxhighlight>
If deletion is successful, DreamFactory returns a 200 status code with a response body containing the deleted record's primary key:

&lt;syntaxhighlight lang="json">    {
        "resource": [
            {
                "emp_no": 500016
            }
        ]
    }&lt;/syntaxhighlight>
The equivalent SQL query looks like this:

&lt;syntaxhighlight lang="sql">DELETE FROM employees WHERE emp_no = 500016;&lt;/syntaxhighlight>
&lt;span id="working-with-stored-procedures">&lt;/span>
== Working with stored procedures ==

Stored procedure support via the REST API is just for discovery and calling what you have already created on your database, it is not for managing the stored procedures themselves. They can be accessed on each database service by the &lt;code>_proc&lt;/code> resource.

As with most database features, there are a lot of common things about stored procedures across the various database vendors, with some notable exceptions. DreamFactory's blended API defines the difference between stored procedures and how they are used in the API as follows.

Procedures can use input parameters ('IN') and output parameters ('OUT'), as well as parameters that serve both as input and output ('INOUT'). They can, except in the Oracle case, also return data directly.

:::warning Database Vendor Exceptions * SQLite does not support procedures (or indeed functions). * PostgreSQL calls procedures and functions the same thing (a function) in PostgreSQL. DreamFactory calls them procedures if they have OUT or INOUT parameters or don't have a designated return type, otherwise they are referred to as functions. * SQL Server treats OUT parameters like INOUT parameters, and therefore require some value to be passed in. :::

&lt;span id="listing-available-stored-procedures">&lt;/span>
=== Listing available stored procedures ===

The following call lists the available stored procedures, based on role access allowed:

&lt;syntaxhighlight lang="text">GET http(s)://&lt;dfServer>/api/v2/&lt;serviceName>/_proc&lt;/syntaxhighlight>
&lt;span id="getting-stored-procedure-details">&lt;/span>
=== Getting stored procedure details ===

We can use the &lt;code>ids&lt;/code> url parameter and pass a comma delimited list of resource names to retrieve details about each of the stored procedures. For example if you have a stored procedure named &lt;code>getCustomerByLastName&lt;/code> a GET call to &lt;code>http(s)://&amp;lt;dfServer&amp;gt;/api/v2/&amp;lt;serviceName&amp;gt;?ids=getCustomerByLastName&lt;/code> returns the following:

&lt;syntaxhighlight lang="json">{
  "resource": [
    {
      "alias": null,
      "name": "getCustomerByLastName",
      "label": "GetCustomerByLastName",
      "description": null,
      "native": [],
      "return_type": null,
      "return_schema": [],
      "params": [
        {
          "name": "LastName",
          "position": 1,
          "param_type": "IN",
          "type": "string",
          "db_type": "nvarchar",
          "length": 25,
          "precision": null,
          "scale": null,
          "default": null
        }
      ],
      "access": 31
    }
  ]
}&lt;/syntaxhighlight>
&lt;span id="calling-a-stored-procedure">&lt;/span>
=== Calling a stored procedure ===

&lt;span id="using-get">&lt;/span>
==== Using GET ====

When passing no payload is required, any IN or INOUT parameters can be sent by passing the values in the order required inside parentheses:

&lt;syntaxhighlight lang="text">/api/v2/&lt;serviceName>/_proc/myproc(val1, val2, val3)&lt;/syntaxhighlight>
Or as URL parameters by parameter name:

&lt;syntaxhighlight lang="text">/api/v2/&lt;serviceName>/_proc/myproc?param1=val1&amp;param2=val2&amp;param3=val3&lt;/syntaxhighlight>
In the below example, there is a stored procedure &lt;code>getUsernameByDepartment&lt;/code> which takes two input parameters, a department code, and a userID. Making the following call:

&lt;syntaxhighlight lang="text">/api/v2/&lt;serviceName>/_proc/getUserNameByDepartment(AB,1234)&lt;/syntaxhighlight>
In the above example, AB is the department code and 1234 is the userID, which returns:

&lt;syntaxhighlight lang="json">{
  "userID": "1234",
  "username": "Tomo"
}&lt;/syntaxhighlight>
&lt;span id="using-post">&lt;/span>
==== Using POST ====

If a payload is required, i.e. passing values that are not url compliant, or passing schema formatting data, include the parameters directly in order. The same call as above can be made with a POST request with the following in the body:

&lt;syntaxhighlight lang="json">{
  "params": ["AB", 1234]
}&lt;/syntaxhighlight>
&lt;span id="formatting-results">&lt;/span>
=== Formatting results ===

For procedures that do not have INOUT or OUT parameters, the results can be returned as is, or formatted using the returns URL parameter if the value is a single scalar value, or the schema payload attribute for result sets.

If INOUT or OUT parameters are involved, any procedure response is wrapped using the configured (a URL parameter wrapper) or default wrapper name (typically "resource"), and then added to the output parameter listing. The output parameter values are formatted based on the procedure configuration data types.

Note that without formatting, all data is returned as strings, unless the driver (i.e. mysqlnd) supports otherwise. If the stored procedure returns multiple data sets, typically via multiple "SELECT" statements, then an array of datasets (i.e. array of records) is returned, otherwise a single array of records is returned.

''schema'' - When a result set of records is returned from the call, the server uses any name-value pairs, consisting of &lt;code>&amp;quot;&amp;lt;field_name&amp;gt;&amp;quot;: &amp;quot;&amp;lt;desired_type&amp;gt;&amp;quot;&lt;/code>, to format the data to the desired type before returning.

''wrapper'' - Just like the URL parameter, the wrapper designation can be passed in the posted data.

Request with formatting configuration:

&lt;syntaxhighlight lang="json">{
  "schema": {
    "id": "integer",
    "complete": "boolean"
  },
  "wrapper": "data"
}&lt;/syntaxhighlight>
Response without formatting:

&lt;syntaxhighlight lang="json">{
  "resource": [
    {
      "id": "3",
      "name": "Write an app that calls the stored procedure.",
      "complete": 1
    },
    {
      "id": "4",
      "name": "Test the application.",
      "complete": 0
    }
  ],
  "inc": 6,
  "count": 2,
  "total": 5
}&lt;/syntaxhighlight>
Response with formatting applied:

&lt;syntaxhighlight lang="json">{
  "data": [
    {
      "id": 3,
      "name": "Write an app that calls the stored procedure.",
      "complete": true
    },
    {
      "id": 4,
      "name": "Test the application.",
      "complete": false
    }
  ],
  "inc": 6,
  "count": 2,
  "total": 5
}&lt;/syntaxhighlight>
&lt;span id="using-symmetric-keys-to-decrypt-data-in-a-stored-procedure-sql-server">&lt;/span>
=== Using symmetric keys to decrypt data in a stored procedure (SQL Server) ===

SQL Server has the ability to perform column level encryption using symmetric keys which can be particularly useful for storing sensitive information such as passwords. A good example of how to do so can be found [https://www.sqlshack.com/an-overview-of-the-column-level-sql-server-encryption/ here]

Typically, you would then decrypt this column (assuming the user has access to the certificate) with a statement in your sql server workbench such as:

&lt;syntaxhighlight lang="sql">OPEN SYMMETRIC KEY SymKey
DECRYPTION BY CERTIFICATE &lt;CertificateName>;

SELECT &lt;encryptedColumn> AS 'Encrypted data',
CONVERT(varchar, DecryptByKey(&lt;encryptedColumn>)) AS 'decryptedColumn'
FROM SalesLT.Address;&lt;/syntaxhighlight>
Now, we cannot call our table endpoint (e.g &lt;code>/api/v2/&amp;lt;serviceName&amp;gt;/_table/&amp;lt;tableWithEncryptedField&amp;gt;&lt;/code>) and add this logic with DreamFactory, however we could put the same logic in a stored procedure, and have DreamFactory call that to return our decrypted result. As long as the SQLServer user has permissions to the certificate used for encryption, they are able to decrypt the field. You could then use [[System_Settings/Dreamfactory_Platform_Apis|roles]] to make sure only certain users have access to this stored procedure.

The stored procedure looks something like this:

&lt;syntaxhighlight lang="sql">CREATE PROCEDURE dbo.&lt;procedureName>
AS
BEGIN
  SET NOCOUNT on;
  OPEN SYMMETRIC KEY SymKey
  DECRYPTION BY CERTIFICATE &lt;CertificateName>;

  SELECT &lt;oneField>, CONVERT(nvarchar, DecryptByKey(&lt;encryptedField>)) AS 'decrypted'
  FROM &lt;table>;
END
return;&lt;/syntaxhighlight>
It can be called by DreamFactory with &lt;code>/_proc/&amp;lt;procedureName&amp;gt;&lt;/code>.

== See also ==
* [[Event_Scripts|Event Scripts]]
* [[Api_Keys|API Keys]]
* [[Advanced_Database_Api_Features|Advanced Database API Features]]

[[Category:Rest_Api]]
[[Category:Crud_Operations]]
[[Category:Database_Api]]
[[Category:API]]
[[Category:Difficulty_Beginner]]

[[Category:API]]
Template used on this page:

- [Template:Note](/Template:Note) ([view source](/index.php?title=Template:Note&action=edit))

Return to [Interacting With Api](/Interacting_With_Api).

Retrieved from "[https://wiki.dreamfactory.com/Interacting_With_Api](https://wiki.dreamfactory.com/Interacting_With_Api)"