[Progress Communities] [Progress OpenEdge ABL] Forum Post: POST JSON

  • Thread starter Giancarlo Alberto Somma
  • Start date
Status
Not open for further replies.
G

Giancarlo Alberto Somma

Guest
Hi, for the first time I have to deal with REST JSON. In my code below, I need to POST the following JSON file : data:{ customers:[ { id_accounting:1, id_totalgest:2, error:false, message:"" }, { id_accounting:3, id_totalgest:4, error:true, message:"Some reason ..." }], products:[ { id_accounting:5, id_totalgest:6, error:false, message:"" }], services:[ { id_accounting:7, id_totalgest:0, error:true, message:"Some reason ..." }] } } Below the code. I don't understand how I can specify JSON file. I found the code in same OE example. I'm using OE 11.7. Any help is very appreciate. Many thanks. BLOCK-LEVEL ON ERROR UNDO, THROW. USING OpenEdge.Core.String. USING OpenEdge.Net.HTTP.ClientBuilder. USING OpenEdge.Net.HTTP.IHttpRequest. USING OpenEdge.Net.HTTP.IHttpResponse. USING OpenEdge.Net.HTTP.RequestBuilder. USING Progress.Json.ObjectModel.JsonObject. DEFINE VARIABLE httpUrl AS CHARACTER NO-UNDO. DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO. DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO. //DEFINE VARIABLE oRequestBody AS STRING NO-UNDO. DEFINE VARIABLE oRequestBody AS JsonObject NO-UNDO. DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO. DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO. DEFINE VARIABLE jsonReq AS NO-UNDO. SESSION:DEBUG-ALERT = TRUE. httpUrl = " www.googleapis.com/.../token". oRequestBody = NEW JsonObject(). //jsonReq ='~{" "~}'. oRequestBody = NEW String(jsonReq). ?????????? /* oRequestBody = NEW String('{ data:{ customers:[ { id_accounting:1, id_totalgest:2, error:false, message:"" }, { id_accounting:3, id_totalgest:4, error:true, message:"Some reason ..." }], products:[ { id_accounting:5, id_totalgest:6, error:false, message:"" }], services:[ { id_accounting:7, id_totalgest:0, error:true, message:"Some reason ..." }] } } '). */ //oRequestBody = new JsonObject(). //oRequestBody:Add("CustNum", "200"). //oRequestBody:Add("Name", "Excellent Sports Apparel"). oRequest = RequestBuilder:post(" tg03a.bweb.ch/.../ , oRequestBody) :ContentType('application/json') :AcceptJson() :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIP oResponse:ContentType skip oResponse:ContentLength skip vIEW-AS ALERT-BOX. oJsonEntity = CAST(oResponse:Entity, JsonObject). oJsonEntity:Write(JsonString, TRUE). MESSAGE STRING(JsonString) VIEW-AS ALERT-BOX.

Continue reading...
 
Status
Not open for further replies.
Top