SQL Server Box: Get Root Folder Info

Back to Index

Gets the folder info for the root folder of a Box.com account. The root folder of a box.com account always has an id = "0".

Documentation: https://developer.box.com/reference#get-folder-info

CURL Command

curl https://api.box.com/2.0/folders/0 \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://api.box.com/2.0/folders/0
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.box.com', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Authorization', 'Bearer BOX_ACCESS_TOKEN'

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

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/2.0/folders/0', STR(@sbResponseBody)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, STR(@sbResponseBody)

    DECLARE @type nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @sequence_id int

    DECLARE @etag int

    DECLARE @name nvarchar(4000)

    DECLARE @created_at int

    DECLARE @modified_at int

    DECLARE @description nvarchar(4000)

    DECLARE @size int

    DECLARE @path_collectionTotal_count int

    DECLARE @created_byType nvarchar(4000)

    DECLARE @created_byId nvarchar(4000)

    DECLARE @created_byName nvarchar(4000)

    DECLARE @created_byLogin nvarchar(4000)

    DECLARE @modified_byType nvarchar(4000)

    DECLARE @modified_byId nvarchar(4000)

    DECLARE @modified_byName nvarchar(4000)

    DECLARE @modified_byLogin nvarchar(4000)

    DECLARE @trashed_at int

    DECLARE @purged_at int

    DECLARE @content_created_at int

    DECLARE @content_modified_at int

    DECLARE @owned_byType nvarchar(4000)

    DECLARE @owned_byId nvarchar(4000)

    DECLARE @owned_byName nvarchar(4000)

    DECLARE @owned_byLogin nvarchar(4000)

    DECLARE @shared_link int

    DECLARE @folder_upload_email int

    DECLARE @parent int

    DECLARE @item_status nvarchar(4000)

    DECLARE @item_collectionTotal_count int

    DECLARE @item_collectionOffset int

    DECLARE @item_collectionLimit int

    DECLARE @i int

    DECLARE @count_i int

    DECLARE @file_versionType nvarchar(4000)

    DECLARE @file_versionId nvarchar(4000)

    DECLARE @file_versionSha1 nvarchar(4000)

    DECLARE @sequence_id_str nvarchar(4000)

    DECLARE @etag_str nvarchar(4000)

    DECLARE @sha1 nvarchar(4000)

    DECLARE @by nvarchar(4000)

    DECLARE @direction nvarchar(4000)

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @type OUT, 'type'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'id'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @sequence_id OUT, 'sequence_id'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @etag OUT, 'etag'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @name OUT, 'name'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @created_at OUT, 'created_at'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @modified_at OUT, 'modified_at'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @description OUT, 'description'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @size OUT, 'size'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @path_collectionTotal_count OUT, 'path_collection.total_count'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @created_byType OUT, 'created_by.type'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @created_byId OUT, 'created_by.id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @created_byName OUT, 'created_by.name'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @created_byLogin OUT, 'created_by.login'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @modified_byType OUT, 'modified_by.type'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @modified_byId OUT, 'modified_by.id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @modified_byName OUT, 'modified_by.name'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @modified_byLogin OUT, 'modified_by.login'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @trashed_at OUT, 'trashed_at'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @purged_at OUT, 'purged_at'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @content_created_at OUT, 'content_created_at'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @content_modified_at OUT, 'content_modified_at'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @owned_byType OUT, 'owned_by.type'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @owned_byId OUT, 'owned_by.id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @owned_byName OUT, 'owned_by.name'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @owned_byLogin OUT, 'owned_by.login'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @shared_link OUT, 'shared_link'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @folder_upload_email OUT, 'folder_upload_email'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @parent OUT, 'parent'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @item_status OUT, 'item_status'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @item_collectionTotal_count OUT, 'item_collection.total_count'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @item_collectionOffset OUT, 'item_collection.offset'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @item_collectionLimit OUT, 'item_collection.limit'
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'path_collection.entries'
    WHILE STR(@i) < STR(@count_i)
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', STR(@i)
        SELECT @i = STR(@i) + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'item_collection.entries'
    WHILE STR(@i) < STR(@count_i)
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', STR(@i)
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @type OUT, 'item_collection.entries[i].type'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'item_collection.entries[i].id'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @file_versionType OUT, 'item_collection.entries[i].file_version.type'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @file_versionId OUT, 'item_collection.entries[i].file_version.id'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @file_versionSha1 OUT, 'item_collection.entries[i].file_version.sha1'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sequence_id_str OUT, 'item_collection.entries[i].sequence_id'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @etag_str OUT, 'item_collection.entries[i].etag'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @sha1 OUT, 'item_collection.entries[i].sha1'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @name OUT, 'item_collection.entries[i].name'
        SELECT @i = STR(@i) + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'item_collection.order'
    WHILE STR(@i) < STR(@count_i)
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', STR(@i)
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @by OUT, 'item_collection.order[i].by'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @direction OUT, 'item_collection.order[i].direction'
        SELECT @i = STR(@i) + 1
      END

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

Sample JSON Response Body

{
  "type": "folder",
  "id": "0",
  "sequence_id": null,
  "etag": null,
  "name": "All Files",
  "created_at": null,
  "modified_at": null,
  "description": "",
  "size": 826408,
  "path_collection": {
    "total_count": 0,
    "entries": [
    ]
  },
  "created_by": {
    "type": "user",
    "id": "",
    "name": "",
    "login": ""
  },
  "modified_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "trashed_at": null,
  "purged_at": null,
  "content_created_at": null,
  "content_modified_at": null,
  "owned_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "shared_link": null,
  "folder_upload_email": null,
  "parent": null,
  "item_status": "active",
  "item_collection": {
    "total_count": 2,
    "entries": [
      {
        "type": "file",
        "id": "246181882790",
        "file_version": {
          "type": "file_version",
          "id": "259636211878",
          "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18"
        },
        "sequence_id": "0",
        "etag": "0",
        "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18",
        "name": "hedgehogs.jpg"
      },
      {
        "type": "file",
        "id": "246167973161",
        "file_version": {
          "type": "file_version",
          "id": "259621592361",
          "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0"
        },
        "sequence_id": "0",
        "etag": "0",
        "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0",
        "name": "penguins.jpg"
      }
    ],
    "offset": 0,
    "limit": 100,
    "order": [
      {
        "by": "type",
        "direction": "ASC"
      },
      {
        "by": "name",
        "direction": "ASC"
      }
    ]
  }
}