File Metadata Instance - Create
Create metadata instance for a file in a Box.com account using SQL Server
- See SQLHTTP easy setup for Box.com
- See API Call documentation for parameter values and other information
- Create the stored procedure documented below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
CREATE PROCEDURE usp_Box_v2_File_Metadata_Create( @Profile nvarchar(100), @FileID bigint, @Scope varchar(50), @Template varchar(50), @Body varchar(MAX), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @URL nvarchar(MAX) DECLARE @HTTPSessionID uniqueidentifier SET @URL = 'https://https://api.box.com/2.0' EXEC SQLHTTP.net.UrlBuilder @URL OUTPUT, @Profile, 'files', @FileID, 'metadata', @Scope, @Template EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT EXEC usp_Box_v2_Auth_Header @Profile, @HTTPSessionID EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'POST', @Body = @Body, @ContentType = 'application/json', @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) DECLARE @Body varchar(MAX) DECLARE @Profile nvarchar(100) SET @Profile = 'My Box' --Box.com Oauth2 is token is valid for only one hour EXEC usp_Box_v2_Auth_Refresh @Profile SET @Body = '{ "audience1": "global", "documentType": "Q1 plans", "competitiveDocument": "no", "status": "active", "author": "Jones", "currentState": "proposal" }' EXEC usp_Box_v2_File_Metadata_Create @Profile = @Profile, @FileID = '172981593468', @Scope = 'global', @Template = 'properties', @Body = @Body, @Response= @Response OUTPUT, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE BEGIN DECLARE @X xml SET @X = SQLHTTP.net.Json_To_Xml(@Response, '0') --The XPath syntax below was easily generated by executing the following commands: --EXEC SQLHTTP.net.XQueryHelper @X --and then executing: --EXEC SQLHTTP.net.XQueryHelper @X, 'JsonObject' SELECT T.C.value(N'@_x0024_id', N'nvarchar(MAX)') AS [$id] ,T.C.value(N'@_x0024_parent', N'nvarchar(MAX)') AS [$parent] ,T.C.value(N'@_x0024_scope', N'nvarchar(MAX)') AS [$scope] ,T.C.value(N'@_x0024_type', N'nvarchar(MAX)') AS [$type] FROM @X.nodes(N'/JsonObject') T(C) END |
1 2 3 4 5 6 |
$id $parent $scope $type ------------------------------------ ----------------- ----------- ------------ 4a58dff6-3c46-4adc-873b-d1e0134ee3c3 file_172981593468 global properties |
- Box Content – Search
- Collaboration – Create
- Collaboration – Delete
- Collaboration – Fetch
- Collaboration – Update
- Collection Items – Add or Delete
- Collection Items – Fetch
- Collections – Fetch
- Comment – Create
- Comment – Delete
- Comment – Fetch
- Comment – Update
- Current User – Fetch
- Device Pin – Delete
- Device Pin – Fetch
- Enterprise Device Pins – Fetch
- Enterprise Events – Fetch
- Enterprise Templates – Fetch
- File – Copy
- File – Delete
- File – Download
- File – Lock or Unlock
- File – Upload
- File Collaborations – Fetch
- File Comments – Fetch
- File Embed Link – Fetch
- File Info – Fetch
- File Info – Update
- File Metadata Instance – Create
- File Metadata Instance – Fetch
- File Metadata Instances – Fetch
- File Tasks – Fetch
- File Thumbnail – Fetch
- File Watermark – Fetch
- File Watermark – Remove
- File Watermark – Update
- Folder – Copy
- Folder – Create
- Folder – Delete
- Folder – Fetch
- Folder – Update
- Folder Collaborations – Fetch
- Folder Info – Fetch
- Folder Metadata Instance – Create
- Folder Metadata Instance – Fetch
- Folder Metadata Instances – Fetch
- Folder Watermark – Fetch
- Folder Watermark – Remove
- Folder Watermark – Update
- Group – Create
- Group – Delete
- Group – Fetch
- Group – Update
- Group Membership – Create
- Group Membership – Delete
- Group Membership – Fetch
- Group Membership – Update
- Group Memberships – Fetch
- Groups – Fetch
- Metadata Template – Create
- Metadata Template – Fetch
- Metadata Template – Update
- Pending Collaborations – Fetch
- Recent Items – Fetch
- Task – Create
- Task – Fetch
- Task – Update
- Task Assignment – Create
- Task Assignment – Fetch
- Task Assignment – Update
- Task Assignments – Fetch
- Trashed Item – Delete
- Trashed Item – Fetch
- Trashed Item – Restore
- Trashed Items – Fetch
- User – Create
- User – Fetch
- User – Update
- User Events – Fetch
- User Memberships – Fetch
- Users – Fetch
- Web Link – Create
- Web Link – Delete
- Web Link – Fetch
- Web Link – Update
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.