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
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:
And here's the response, which is what I think you're looking for (see line 12):
Related
I have a URL I need to call.
http://myurl.mycompany.net/api/people?filter=(cn=kxxxxx)
"cn" is the logon of the user, and it returns user details.
However I need to formulate this type of URL:
http://myurl.mycompany.net/api/people?filter=(cn=kxxxxx)&appid=GPVC
i.e. to send in the app_id.
I may also want to specify which fields I want to return:
http://myurl.mycompany.net/api/people?filter=(cn=kxxxxx)&appid=GPVC&attrs=sn,displayName
i.e. return only the surname and display name in the response
declare
l_clob clob;
l_buffer varchar2(32767);
l_amount number;
l_offset number;
begin
l_clob := apex_web_service.make_rest_request(
p_url => 'http://myurl.mycompany.net/api/people?filter=(cn=kxxxxx)',
p_http_method => 'GET',
p_parm_name => apex_util.string_to_table('appid'),
p_parm_value => apex_util.string_to_table('GPVC')
);
DBMS_OUTPUT.put_line(l_clob);
end;
But the response I get is:
{
"error": {
"message": "Consumer application identification is now enforced - please go to http://myurl.mycompany.net and contact us to obtain an appid for your requests."
}
}
So I am hitting the web service, just probably not creating a URL in the right format.
If I add the &appid=GPVC to the URL in the PLSQL, I get a pop up box asking me to pass in the bind parameter at run time.....
l_clob := apex_web_service.make_rest_request(
p_url => 'http://myurl.mycompany.net/api/people?filter=(cn=kxxxxx)&appid=GPVC',
p_http_method => 'GET'
);
"set define off" (as people are suggesting) to ignore the ampersand doesn't work. I would really like to know why make_rest_request isnt working with the parameters. "set define off" just generates this error:
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
The url is good....works fine in the browser and gives me a response
I have a hosted http service that accepts a trend data and returns some output. This service is accessed in siddhi query language as follows:
#sink(type='http-request', sink.id='trends',
publisher.url='${SERVICE_URL}', #map(type='json', #payload(""" {"trend":{{trendArray}} } """) ) )
define stream Request(item string, trendArray string);
#source(type='http-response' , sink.id='trends', http.status.code='200',
#map(type='json', #attributes(stock = '<HOW_TO_GET_THIS_VALUE>', output = "<HOW_TO_GET_THIS_VALUE>")
) )
define stream Response(item string, output string);
The http request(and response) payload doesn't include item name.
when the response comes we would like to assign item name against which we scored the output - marked as HOW_TO_GET_THIS_VALUE above.
How to accomplish this in siddhi query ?
How to treat the response data of as-is as pass to the field ?
I did not see a description of this scenario in siddhi. If not supported, it will good to know details of a custom extension (based out of http extension) for this scenario. Solution to add a proxy layer for http call is less desired.
After some experiments , HOW_TO_GET_THIS_VALUE = 'trp:item'. The http sink should also have this field even though its not used in payload.
I am trying to call the EBS REST webservice 'assign_role' from Oracle APEX. I have deployed this webservice in EBS and got the WADL link.
Now, with this link I am able to successfully call the webservice using Postman tool by providing below JSON message :
{
"InputParameters": {
"P_REGISTRATION_DATA": [{
"P_REGISTRATION_DATA_ITEM": [{
"ATTR_NAME": "requested_for_user_id",
"ATTR_VALUE": 4901
},
{
"ATTR_NAME": "wf_role_name",
"ATTR_VALUE": "FND_RESP|XXA|CUSTOM_ADFIN|STANDARD"
},
{
"ATTR_NAME": "requested_start_date",
"ATTR_VALUE": "2019/01/09 15:00:00"
},
{
"ATTR_NAME": "justification",
"ATTR_VALUE": "TEST BRLEBRUYN"
}
]
}
]
}
}
But when I am trying to call the APEX_WEB_SERVICE.make_rest_request process, I am not sure, how can I provide the list of parameters (p_parm_name), as the parameters are of Table type. (The webservice internally calls standard EBS ORacle package UMX_REGISTRATION_PVT.assign_role)
apex_web_service.make_rest_request(
p_url => 'https://ofd.ntwerpen.be/webservices/rest/XXUA_UMX_PUB/assign_role/',
p_http_method => 'POST',
**p_parm_name** => apex_util.string_to_table('requested_for_user_id:wf_role_name:requested_start_date:justification'),
p_parm_value => apex_util.string_to_table(l_user_id||':'||l_role_name||':'||l_requested_start_date||':'||l_justification));
Can somebody please help me write the correct code to call this procedure.
I beleive, If I am able to give the parameters name correctly in
p_parm_name => apex_util.string_to_table('requested_for_user_id:wf_role_name:requested_start_date:justification')
then it will work fine.
Please suggest.
Thanks
As you mentioned that you are calling the web service using the POST method by providing the JSON as input. You can construct the JSON with values to be passed and pass it to the P_BODY parameter of APEX_WEB_SERVICE.MAKE_REST_REQUEST procedure.
For constructing JSON, you can use APEX_JSON package.
Hope it works..
I am having problem with grape.
I have tried to look into their docs and google around.
I could not find any solution or sample regarding this.
Let say I am sending this kind of format to the POST request of grape:
{
"preferences": {
"play": {
"weekdays": "5",
"weekend": "8"
},
"grow": {
"weekdays": "4",
"weekend": "8"
}
}
}
Questions:
How do I setup the Grape params to receive this post?
I have tried something like this:
params do
optional :preferences, type: Hash do
optional :play do
optional :weekdays
optional :weekend
end
optional :grow, type: Hash do
optional :weekdays
optional :weekend
end
end
end
I am using postman to do the POST on my chrome. My question is, How do I set the Hash kind of params ? There are 3 options on postman which are form-data, form-urlencoded, and raw. I have tried with form-data and raw (json) it does not work for the raw json, it gave me an error saying that
The requested content-type 'text/plain' is not supported
Any idea how do I fix these problems?
Thank you very much
Answering question 1: If all parameters are optional then you don't even need the params block. Get rid of it and, for example, use params[:preferences][:play][:weekdays] to access the weekdays attribute. Just use the same idea to access other values.
Answering question 2: On Postman, use RAW but don't forget to set the header Content-Type to application/json. I've written the code below to play around with this example.
require 'grape'
class API < Grape::API
version 'v1', :using => :header, :vendor => 'alienlabz', :format => :json
format :json
resource :preferences do
post do
puts params[:preferences][:play][:weekdays]
end
end
end
run API
I am moving from SQL to Couch DB from my web application, my very first application.
While i can not say why I do not like SQL queries, not sure that i don not, the idea of making CURL requests to access my database sound must better than using PHPs PDO .
I have spent a little over a day and a half trying to acquaint myself with the couch DB HTTP API. I can not claim I have throughly read the API , but who thoroughly reads an API before beginning to code. So my, possibly silly, question is - how do I pass an variable other than doc to a map function while making a http request to the view. The API clearly says that a map function only takes a single parameter which is "doc", in which case the function below itself is wrong but I can't find any section in the API that lets me query a database using end-user provided input.
my map function is
function(doc, pid2){
if (doc.pid === pid2)
{
emit(doc._id, doc) ;
}
}
pid2 is a number that will be provided by a front end user.
<?php
$pid2 = file_get_contents(facebook graphi api call_returns a Profile ID) ;
$user_exists = HTTP request to couch DB view to return
in JSON format the list of JSON documents with pid = $pid2
?>
Let your view emit the documents with doc.pid as the key
function(doc) {
emit(doc.pid, doc);
}
and use the key parameter to retrieve the right document:
http://localhost:5984/<database>/_design/<designdoc>/_view/<viewname>?key=<pid2>
This should return all documents with doc.pid === pid2.