Eliran.H
Eliran.H

Reputation: 11

ORDS RESTful oracle-apex - A formulate JSON response (POST method)

I'm new in oracle-apex and with ORDS. My problame is: when I was tried to bulid a RESTful web service on oracle apex, from a procedure, and used:

    l_response := apex_web_service.make_rest_request(
        p_url =>l_rest_url,
        p_http_method => 'POST',
        p_body => l_request_body
    );

from make a request.

On ORDS Handler Definition, I defined:

declare
 l_response_body clob;
begin
l_response_body := '{"conf_code":"'||sys_guid()|| '","status":"APPROVED"}';

INSERT INTO JSON_TIMECARD_APPROVAL (id, json_data)
VALUES (sys_guid(),l_response_body);

:xxResponse :=l_response_body;

When xxResponse was defined an a OUT prameter and scource type: RESPONSE.

I'm intrested to get the response in JSON format.

When i tried to call my web service(my web api https://apex.oracle.com/pls/apex/eliranhaa/timecards/approval/)the. Parameter IN:

p_body = 
{"timecard": [
  {
    "timecard_id":214804582301489177025033231688226094978
    ,"employee_id":214804582301403343291840593016821956482
    ,"week_of":"2020-18-03T00:00:00Z"
  }
  ]
}

The Outcome: 
{"DATA":"{\"conf_code\":\"A3695DE33828CA50E0530C4072644591\",\"status\":\"APPROVED\"}"}

I don't know why the outcome return as string instead of Json format (Respone return as CLOB TYPE).

I Have a reference from web api https://apex.oracle.com/pls/apex/timecards/timecard/approval/ By the way this outcome is what i whant for my web service.

Tnx Eliran

Upvotes: 0

Views: 2124

Answers (1)

Dan McGhan
Dan McGhan

Reputation: 4659

The first thing that stands out is that you're calling sys_guid twice. Don't you want to return the same value that you inserted?

I don't know why the outcome return as string instead of Json format

What you're seeing is your JSON data being escaped improperly because you're trying to put a single JSON value as your output. Try breaking it up instead.

For example, I created a handler that looks like this:

enter image description here

And here's the response, which is what I think you're looking for (see line 12): enter image description here

Upvotes: 2

Related Questions