Chilkat Online Tools

SQL Server / Microsoft Graph / Subscription validation

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequest', @resp OUT, 'POST', 'http://localhost:5000/api/notification?validationToken=something'
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
http://localhost:5000/api/notification?validationToken=something

Postman Collection Item JSON

{
  "name": "Subscription validation",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "function decodeQueryParam(p) {\r",
          "    return decodeURIComponent(p.replace(/\\+/g, \" \"));\r",
          "}\r",
          "\r",
          "pm.test(\"Status test\", function () {\r",
          "    pm.response.to.have.status(200);\r",
          "});\r",
          "pm.test(\"Content type test\", function () {\r",
          "    pm.response.to.have.header(\"Content-Type\");\r",
          "    pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"text/plain\");\r",
          "});\r",
          "pm.test(\"Response body test\", function () {\r",
          "    pm.response.to.have.body(decodeQueryParam(pm.request.url.query.get(\"validationToken\")));\r",
          "});"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
    ],
    "url": {
      "raw": "http://localhost:5000/api/notification?validationToken=something",
      "protocol": "http",
      "host": [
        "localhost"
      ],
      "port": "5000",
      "path": [
        "api",
        "notification"
      ],
      "query": [
        {
          "key": "validationToken",
          "value": "something",
          "description": "random validation token passed by the Microsoft Graph when validating the notificationURL"
        }
      ]
    },
    "description": "Allows you to validate whether the notification endpoint you are building properly passed Microsoft Graph Subscription creation validation.\nThe response content type should be text/plain, code 200 OK and the body the information passed by the validationToken query parameter"
  },
  "response": [
  ]
}