Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Executing Stored Procedures

Executing Stored Procedures

You can execute a stored procedure from your code by making an HTTP request to its specific endpoint URL.

The endpoint URL has this format:

https://api.everlive.com/v1/your-app-id/Invoke/SqlProcedures/mapped-procedure-name-here

In the above URL, substitute your own App ID and the name of the function you want to execute for the placeholders.

When making the HTTP request you can use only the HTTP method POST.

Request:
    POST https://api.everlive.com/v1/your-app-id/Invoke/SqlProcedures/<procedure-name-here>
Headers:
    Content-Type: application/json
Payload - raw:
    {
        "@MyParamName": "MyParamValue"
    }
Response:
    Status: 200 OK

Response Format

The success response to executing a stored procedure has the following format:

{
    "Result": {
        "OutParameters": { },
        "Data": [ ]
    }
}
  • The OutParameters key is an object that contains the output parameters' names and values. For example:

    {
        "Result": {
            "OutParameters": {
                "@UserId": "enlcl12345"
            },
            "Data": [ ]
        }
    }
    
  • The Data key is an array of arrays of objects, each of which contains a result set returned from the stored procedure. For example:

    {
        "Result":
            {
                "OutParameters":{},
                "Data":[
                    [{...},{...}, ...], // first result set
                    [{...},{...}, ...] // second result set, etc.
                ]
            }
    }
    

When the stored procedure returns an error you still receive a success result. However, it has a different format:

{
  "Result": {
    "HasErrors": true,
    "ErrorMessage": "<error-message-here>"
  }
}

Date and Time Format

The SQL date and time objects are returned in integer format that represents the value of the date column converted to Unix time.

For example, the field LastUpdatedAt in the response below represents a date value.

{  
   "Result":{  
      "OutParameters":{  

      },
      "Data":[  
         [  
            {  
               "LastUpdatedAt":1433931826530
            },
            {  
               "LastUpdatedAt":1226394720000
            }
         ]
      ]
   }
}

You can easily convert the integer to a date in your preferred programming framework.

Examples

This section contains example invocations of stored procedures.

Calling a Stored Procedure with Input Parameters

curl -X POST -H "Content-Type: application/json" -d '{
    "@Beginning_Date": "1998-01-01T00:00:00.000Z",
    "@Ending_Date": "1998-12-31T00:00:00.000Z"
}' '<my-stored-procedure-url>'
var inputParams = {
    "@Beginning_Date": new Date(Date.UTC(1998, 0, 1)), // @Beginning_Date: "1998-01-01T00:00:00.000Z"
    "@Ending_Date": new Date(Date.UTC(1998, 11, 31)) // @Ending_Date: "1998-12-31T00:00:00.000Z"
};

$.ajax({
    type: "POST",
    url: storedProcedureUrl,
    contentType: "application/json",
    data: JSON.stringify(inputParams),
    success: function(data) {
        if (!data.Result.HasErrors) {
            var result = data.Result;
            var outParameters = result.OutParameters;
            var resultSet = result.Data[0]; // the first result set
        } else {
            alert(data.Result.ErrorMessage);
        }
    },
    error: function(error) {
        alert("Error: " + JSON.stringify(error));
    }
});

Calling a Stored Procedure without Input Parameters

curl -X POST -H "Content-Type: application/json" -d '{}' '<my-stored-procedure-url>'
 $.ajax({
     type: "POST",
     url: salesUrl,
     contentType: "application/json",
     success: function(data) {
         if (!data.Result.HasErrors) {
             var result = data.Result;
             var outParameters = result.OutParameters;
             var resultSet = result.Data[0]; // the first result set
         } else {
             alert(data.Result.ErrorMessage);
         }
     },
     error: function(error) {
         alert("Error: " + JSON.stringify(error));
     }
 });

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.