Hi
We have a number of RESTful APIs that we've written and are now in use. These all seem to work fine and the POST and PUT APIs all use the built-in variables that are created from the request body. For example, if the request body is
{"display_name":"My Big Company Name"}
then the API code refers to :display_name to get the value.
To make the APIs more robust and to help support our clients we want to add some debug code to record what the users are sending in the request body. For this the obvious thing to use is :body which stores the request body as a BLOB. However, if you so much as look at :body it is set to null and so are all the built-in variables, regardless of the order you do things in.
So say we had code that used the request body above:
begin
update my_table
set display_name = :display_name
where id = :ID;
end;
ID is specified in the API URL as {ID} and this all works fine. But if we change the code to be:
begin
update my_table
set display_name = :display_name
where id = :ID;
insert into my_debug_table (request_body) values (:body);
end;
This doesn't work and :display_name is null. This can be seen in a simpler example, if you have a POST API and pass anything in the body then have your API code as:
begin
htp.p(dbms_lob.getlength(:body)||' - '||dbms_lob.getlength(:body));
end;
You will see the output as n - 0 where n is the length of your request body and 0 is what it's set to after you've touched it.
Obviously all this code is greatly simplified. Our API requests have large JSON objects, lots of variables, validations and processing which is why storing the request body would be so useful to us. What I can't figure out is why all the variables are set to null even if you reference :body at the end of the code.
I have tried googling and searching the forum, but there is very little information available on these variables.
So is there a way to use the variables and also the :body? And why does everything get set to null?
Many thanks for your help
Sara
PS. Also posted in APEX forum Restful API :body variable as using APEX 4.2.5 and also tested in APEX 5.