Hello all,
Does anyone have an example of an t-sql request against a REST API with a Multidata/Form? We already call several REST APIs, but not with Multidata/form. Below is a setup (which does not work). The API converts a PDF document into fields in json format. It contains 2 fields that must be included:
- name (name of the document)
- document (base64 encoded string)
Below is a first attempt, but it does not work . Thanks in advance for the reactions.
declare @response table (txt nvarchar(max));
declare @object int ,
@url_endpoint nvarchar(200) ,
@response_format nvarchar(5) ,
@request nvarchar(250) ,
@json nvarchar(max) ,
@address address ,
@body varchar(max) ,
@status int ,
@document_file_name nvarchar(200) ,
@base64_document varchar(max) ,
@content_type varchar(100) ,
@status_text nvarchar(32)
set textsize -1
set @url_endpoint = 'endpoint'
set @document_file_name = 'document.pdf'
set @base64_document = -- the base64 content
set @content_type = 'multipart/form-data';
set @body = concat('name=',@document_file_name,'&','document=',@base64_document)
exec sp_oacreate 'msxml2.xmlhttp', @object out
exec sp_oamethod @object, 'open', null, 'post', @url_endpoint, 'false'
exec sp_oamethod @object, 'AddHeader', null, 'Content-Type', @content_type
exec sp_oamethod @object, 'send', null, @body
exec sp_oagetproperty @object, 'status', @status out;
exec sp_oagetproperty @object, 'statustext', @status_text out;
insert into @response (txt)
exec sp_oamethod @object, 'responsetext'
exec sp_oadestroy @object
select @json = txt from @response;