[Progress Communities] [Progress OpenEdge ABL] Forum Post: Sending JSON POST query using ABL

Status
Not open for further replies.
J

jbetts

Guest
Hello All, I am trying to consume the UPS rest API service ( https://wwwcie.ups.com/rest/Ship ) using OpenEdge, and I believe I am close but coming across issues developing the body of the request. I would like to send the following JSON query using OpenEdge: ********************************************************************************************* { "UPSSecurity":{ "UsernameToken":{ "Username":"username", "Password":"password" }, "ServiceAccessToken":{ "AccessLicenseNumber":"accesstoken" } }, "ShipmentRequest":{ "Request":{ "RequestOption":"validate", "TransactionReference":{ "CustomerContext":"Your Customer Context" } ********************************************************************************************* The current progress code I have is: ********************************************************************************************* 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 oJsonEntity AS JsonObject NO-UNDO. DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO. DEFINE VARIABLE httCust AS HANDLE NO-UNDO. DEFINE VARIABLE lReturnValue AS LOGICAL NO-UNDO. DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO. DEFINE VARIABLE cFile AS CHARACTER NO-UNDO. DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO. SESSION:DEBUG-ALERT = TRUE. httpUrl = " wwwcie.ups.com/.../Ship". oJsonEntity = NEW JsonObject(). oJsonEntity:Add oJsonEntity:Add("Username", "usernamehere"). oJsonEntity:Add("Password", "passwordhere"). oRequest = RequestBuilder:post(" wwwcie.ups.com/.../Ship" , oJsonEntity) :ContentType('application/json') :AcceptJson() :Request. oResponse = ClientBuilder:Build():Client:Execute(oRequest). MESSAGE oResponse:StatusCode SKIP oResponse:StatusReason SKIP VIEW-AS ALERT-BOX. CAST(oResponse:Entity, JsonObject):WriteFile('entity.json',TRUE). MESSAGE STRING(JsonString) VIEW-AS ALERT-BOX. ********************************************************************************************* The problem I am facing is keeping the formatting of the JSON query. Notice that there is a comma between UPSSecurity and ServiceAccessToken. My question is how do I develop program to send the JSON query in the correct format? Thanks in advance :) Kindest Regards, Joseph

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