Sample code for 30+ languages & platforms
SQL Server

CallRail API - Update a Call

See more CallRail Examples

Updates a call object in the target account. You can use the API to add a Tag or a Note to a call, or to set the call’s lead status.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Implements the following CURL command:

    -- curl -H "Authorization: Token token={api_token}" \
    --      -X PUT \
    --      -H "Content-Type: application/json" \
    --      -v \
    --      -d '{
    --            "note": "Call customer back tomorrow",
    --            "tags": ["New Client"],
    --            "lead_status": "good_lead",
    --            "value": "$1.00",
    --            "append_tags": true,
    --          }' \
    --         "https://api.callrail.com/v3/a/{account_id}/calls/{call_id}.json"

    -- Use the following online tool to generate HTTP code from a CURL command
    -- Convert a cURL Command to HTTP Source Code

    -- Use this online tool to generate code from sample JSON:
    -- Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "note": "Call customer back tomorrow",
    --   "tags": [
    --     "New Client"
    --   ],
    --   "lead_status": "good_lead",
    --   "value": "$1.00",
    --   "append_tags": true
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'note', 'Call customer back tomorrow'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tags[0]', 'New Client'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'lead_status', 'good_lead'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'value', '$1.00'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'append_tags', 1

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'Token token={api_token}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    EXEC sp_OAMethod @http, 'HttpSb', @success OUT, 'PUT', 'https://api.callrail.com/v3/a/{account_id}/calls/{call_id}.json', @sbRequestBody, 'utf-8', 'application/json', @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "answered": false,
    --   "business_phone_number": null,
    --   "customer_city": "Denver",
    --   "customer_country": "US",
    --   "customer_name": "RUEGSEGGER SIMO",
    --   "customer_phone_number": "+13036231131",
    --   "customer_state": "CO",
    --   "direction": "inbound",
    --   "duration": 4,
    --   "id": "CAL8154748ae6bd4e278a7cddd38a662f4f",
    --   "recording": "https://api.callrail.com/v3/a/227799611/calls/213472384/recording.json",
    --   "recording_duration": "27",
    --   "start_time": "2017-01-24T11:27:48.119-05:00",
    --   "tracking_phone_number": "+13038163491",
    --   "voicemail": false
    -- }

    -- Sample code for parsing the JSON response...
    -- Use the following online tool to generate parsing code from sample JSON:
    -- Generate Parsing Code from JSON

    DECLARE @answered int
    EXEC sp_OAMethod @jResp, 'BoolOf', @answered OUT, 'answered'
    DECLARE @business_phone_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @business_phone_number OUT, 'business_phone_number'
    DECLARE @customer_city nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @customer_city OUT, 'customer_city'
    DECLARE @customer_country nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @customer_country OUT, 'customer_country'
    DECLARE @customer_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @customer_name OUT, 'customer_name'
    DECLARE @customer_phone_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @customer_phone_number OUT, 'customer_phone_number'
    DECLARE @customer_state nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @customer_state OUT, 'customer_state'
    DECLARE @direction nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @direction OUT, 'direction'
    DECLARE @duration int
    EXEC sp_OAMethod @jResp, 'IntOf', @duration OUT, 'duration'
    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @recording nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @recording OUT, 'recording'
    DECLARE @recording_duration nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @recording_duration OUT, 'recording_duration'
    DECLARE @start_time nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @start_time OUT, 'start_time'
    DECLARE @tracking_phone_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_phone_number OUT, 'tracking_phone_number'
    DECLARE @voicemail int
    EXEC sp_OAMethod @jResp, 'BoolOf', @voicemail OUT, 'voicemail'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @resp
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO