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
|
DECLARE @URL NVARCHAR(MAX) = 'https://*****.*****.fr/api/partenaire/****/ordre-mission/accepte?page=1';
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
DECLARE @KeyAuthorization AS VARCHAR(8000)
DECLARE @Status as int
Declare @StatusText as varchar(34)
DECLARE @JsonData1 NVARCHAR(MAX)
set @KeyAuthorization = 'Bearer '+@OKSToken
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get', @URL,'False'
EXEC sp_OAMethod @Object, 'SetRequestHeader', NULL, 'Accept', 'application/json'
EXEC sp_OAMethod @Object, 'SetRequestHeader', NULL, 'Content-Type', 'application/json;charset=utf-8'
EXEC sp_OAMethod @Object, 'SetRequestHeader', NULL, 'Authorization', @KeyAuthorization
Exec sp_OAMethod @Object, 'send',NULL
EXEC sp_OAGetProperty @Object, 'status', @status OUT;
EXEC sp_OAGetProperty @Object, 'statusText', @statusText OUT;
EXEC sp_OAGetProperty @Object, 'responseText', @responseText OUT;
if @TestSP = 1 select @status, @statusText, @responseText
IF((Select @ResponseText) <> '')
BEGIN
DECLARE @json NVARCHAR(MAX) = (Select @ResponseText)
SELECT TOP 10*
FROM OPENJSON(@json, '$.data')
WITH(
Id_Commande nvarchar(200) '$."id_commande"',
Date_Commande datetime '$."date_commande"',
Date_RDV datetime '$."date_rdv"',
Type_commande int '$."type"',
Num_commande nvarchar(200) '$."numero_commande"',
Num_devis nvarchar(200) '$."numero_devis"',
etat_commande NVARCHAR(255) '$."etat_commande"'
);
END
ELSE
BEGIN
DECLARE @ErroMsg NVARCHAR(30) = 'No data found.';
Print @ErroMsg;
END |
Partager