SQL Server / Razorpay APIs / Update Subscription
        
        Back to Collection Items
        -- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- 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
    DECLARE @success int
    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'username'
    EXEC sp_OASetProperty @http, 'Password', 'password'
    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
    -- The following JSON is sent in the request body.
    -- {
    --   "plan_id": "{plan_id}",
    --   "quantity": 3,
    --   "remaining_count": 6,
    --   "schedule_change_at": "now",
    --   "customer_notify": 1,
    --   "offer_id": "{offer_id}"
    -- }
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'plan_id', '{plan_id}'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'quantity', 3
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'remaining_count', 6
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'schedule_change_at', 'now'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'customer_notify', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'offer_id', '{offer_id}'
    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, 'PATCH', 'https://api.razorpay.com/v1/subscriptions/{sub_id}', @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
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @resp
END
GO
        Curl Command
        curl -X PATCH
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
  "plan_id": "{plan_id}",
  "quantity": 3,
  "remaining_count": 6,
  "schedule_change_at": "now",
  "customer_notify": 1,
  "offer_id":"{offer_id}"
}'
https://api.razorpay.com/v1/subscriptions/{sub_id}
        Postman Collection Item JSON
        {
  "name": "Update Subscription",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"plan_id\": \"{plan_id}\",\n  \"quantity\": 3,\n  \"remaining_count\": 6,\n  \"schedule_change_at\": \"now\",\n  \"customer_notify\": 1,\n  \"offer_id\":\"{offer_id}\"\n}"
    },
    "url": {
      "raw": "https://api.razorpay.com/v1/subscriptions/{sub_id}",
      "protocol": "https",
      "host": [
        "api",
        "razorpay",
        "com"
      ],
      "path": [
        "v1",
        "subscriptions",
        "{sub_id}"
      ]
    },
    "description": "You can update a specific subscription created by you using the <a href=\"https://razorpay.com/docs/api/subscriptions/#update-a-subscription\" target=\"_blank\">Update a Subscription API</a>."
  },
  "response": [
  ]
}