[SOLVED] Cosmos DB Emulator and Uniface
Author: tommy.balkis@gmail.com (tommyb42)
Hi all , I am trying to develop a Restfull Api call with Uniface to microsoft Cosmos Db emulator. They have a complex Authorization token which i construct it according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine Please find below the uniface code for the http call ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources I would appreciate every help to make it work from uniface. Regards Thomas




