Been fighting with this one for days. Hopefully, I'm being thick and there's a semicolon missing from somewhere.
I've been trying to setup a reference to my REST-enabled SQL (RESS) on my local box, and Apex refuses to acknowledge it.
I'm using the article at https://docs.oracle.com/database/apex-18.1/HTMDB/rest-enabled-sql-creating.htm#HTMDB-GUID-0906921E-AF79-49D4-B909-1C090F805D9D, which seems quite straightforward.
Before you ask:
Yes, I've enabled the schema for REST
Yes, I've enabled RESS in the defaults.xml file
Yes, I've tested the RESS away from APEX, using a curl command like curl -i -X POST --user testuser1:testuser1 --data-binary "select sysdate from dual" -H "Content-Type: application/sql" -k http://localhost:8080/ords/hr2/_/sql, and it works.
Then in APEX->Shared Components->Data Sources->REST Enabled SQL, I've setup this reference:
and it uses these credentials:
However, when I initially created the reference, and when I test it, I get the following message:
What on earth am I doing wrong?
Using Oracle APEX 21.2.0 and ORDS Version 21.4.1.r0250904
the screen shots look good. I would now check whether the database can reach the ORDS endpoint with APEX_WEB_SERVICE, as follows (you can use either SQL*Plus or SQL Workshop for this):
declare
l_result clob;
begin
apex_web_service.set_request_headers(
p_name_01 => 'Content-Type',
p_value_01 => 'application/sql' );
l_result := apex_web_service.make_rest_request(
p_url => 'http://localhost:8080/ords/hr2/_/sql',
p_http_method => 'POST',
p_username => 'TESTUSER1',
p_password => 'testuser1',
p_body => 'select sysdate from dual' );
dbms_output.put_line( l_result );
end;
Possible errors are ...
the PL/SQL Network ACL was not set up for the APEX_XXXXXX user
the database has a proxy server defined, which is not valid
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'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):
I am working on a project where I generate and store pdf in the database using apex_util.get_print_document.
It looks like this,
begin
l_report := apex_util.get_print_document (
p_application_id => :APP_ID,
p_report_query_name => 'query_name',
p_report_layout_name => 'layout_name',
p_report_layout_type => 'xsl-fo',
p_document_format => 'pdf' );
Update table_blob
Set report = l_report,
mimetype = 'application/pdf',
filename = :P1_INVOICE_NO||'.pdf',
report_saved_by = :USER,
report_saved_on = sysdate
Where Job_id = :P1_JOB;
End;
This works perfectly in http connection. So when I access the same page over https I am getting the below error. Please help!
ORA-20001: The printing engine could not be reached because either the URL specified is incorrect or a proxy URL needs to be specified.
For APEX to be able to make outbound HTTP calls over SSL, a database wallet must be created and the configuration of it must be specified in APEX Instance Administration:
http://docs.oracle.com/cd/E59726_01/doc.50/e39151/adm_wrkspc002.htm#sthref384
I am using the Amazon API and get this error while updating my stock from my database to Amazon website:
Caught Exception: Internal Error
Response Status Code: 0
Error Code:
Error Type:
Request ID:
XML:
I read this thread (amazonsellercommunity . com/forums/thread.jspa?messageID=2194823) and then get the error explanation:
<Error><Type>Sender</Type><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message><Detail/></Error>
So I thought my MARKETPLACE_ID, MERCHANT_ID, AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY could be wrong. But I checked and these informations are correct.
Actually, I don't understand why this error happens... Before, it worked perfectly and since a couple of days it just crash. And I don't change anything in my code. Strange, isn't it?
Edit :
Here is my section code for signature.
define ('DATE_FORMAT', 'Y-m-d\TH:i:s\Z');
define('AWS_ACCESS_KEY_ID', 'ABC...'); // My AWS Access Key Id (20 characters)
define('AWS_SECRET_ACCESS_KEY', 'ABCDEF...'); // My AWS Secret Access Key (40 characters)
define('APPLICATION_NAME', 'MyCompany_AmazonMWS');
define('APPLICATION_VERSION', '0.0.1');
define ('MERCHANT_ID', 'XXXXXXX'); // My Merchant ID
define ('MARKETPLACE_ID', 'XXXXXXX'); // My Marketplace ID
$config = array (
'ServiceURL' => "https://mws.amazonservices.fr",
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
$config,
APPLICATION_NAME,
APPLICATION_VERSION
);
$parameters = array (
'Marketplace' => MARKETPLACE_ID,
'Merchant' => MERCHANT_ID,
'FeedType' => '_POST_INVENTORY_AVAILABILITY_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false,
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
);
// and then I do this:
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
invokeSubmitFeed($service, $request);
If you want to see some parts of my code, just ask.
If I recall correctly, the authentication mechanism for Amazon APIs is sensitive to the current date/time on your machine (which is used in the process of signing the request). Check to see if your date/time is set correctly.
For me it was just an error with my web app passing url escaped strings. The special characters weren't like by amazon and this (not so useful) error came up. Make sure your file names have no url escaped characters.
I solved it (on Ubuntu 14.04 Server) using ntpdate:
First make sure it is installed:
apt-get install ntpdate
And then execute:
ntpdate ntp.ubuntu.com
What I'd like
I want to be able to reset a users password without emailing them. I also need to do this via REST (it's for a kiosk system).
So I need to:
Get user with a specific username
Reset the password of that user
Try as I might, I can't get the user with a username.
The problem
After I've logged in using the admin user via REST I do:
GET on http://mydomain.com/rest/user?name=user.
According to REST documentation, this should get the user with name user.
I get a 200 response, but nothing is returned in the body.
What I've Tried
Get node from ID
Once I've logged in as admin, I can do:
GET on http://mydomain.com/rest/user/1
This works, returning the details of user 1 in the response. But I need to search for a user by username.
Different GETs
GET on http://mydomain.com/rest/user/admin
GET on http://mydomain.com/rest/user/account/name/admin
GET on http://mydomain.com/rest/user?account[name]=admin
GET on http://mydomain.com/rest/user?uid=1
GET on http://mydomain.com/rest/user/retrieve?uid=1
GET on http://mydomain.com/rest/user?account[uid]=1
All these fail.
Nodes instead of users
GET on http://mydomain.com/rest/node/1 works, but http://mydomain.com/rest/node?nid=1 gives me a 200 response with nothing in the body.
List of all users
GET on http://mydomain.com/rest/user/ doesn't show a list of all users either. I get a 200 with empty body again.
Further Details
I'm working with a Drupal 6.22 install.
I've installed the services module (3.0 RC1) and REST Server (2.0 beta 1).
I've got the session authentication module installed.
I've tried the above with the session authentication switched on and with it off.
I've enabled all node resources and user resources for the REST endpoint I've set up.
I've tried the above with and without clean URLs and nothing seems to make a difference.
Question
How do I get a user with a specific username? What am I doing wrong?
Update
I've uninstalled then reinstalled Services module, I've done the same with the REST server. I've also rolled back my version of CTools to the latest recommended one. I've added a brand new service in case it was corrupted. Nothing I do works. Frustrating!
Update 2
I've found the problem, but would like a more permanent solution. It turns out it was an error because of table naming. See my current accepted answer.
Im sorry this is so frustrating for you. Im the maintainer for services module and were really working on the documentation but I thought I would answer here to just get you moving along.
The reason you are not getting any of the data you want is because the parameters you are passing are wrong.
If you look at user_resource.inc index is defined as follows
'index' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/user_resource'),
'callback' => '_user_resource_index',
'args' => array(
array(
'name' => 'page',
'optional' => TRUE,
'type' => 'int',
'description' => 'The zero-based index of the page to get, defaults to 0.',
'default value' => 0,
'source' => array('param' => 'page'),
),
array(
'name' => 'fields',
'optional' => TRUE,
'type' => 'string',
'description' => 'The fields to get.',
'default value' => '*',
'source' => array('param' => 'fields'),
),
array(
'name' => 'parameters',
'optional' => TRUE,
'type' => 'array',
'description' => 'Parameters',
'default value' => array(),
'source' => array('param' => 'parameters'),
),
),
'access arguments' => array('access user profiles'),
'access arguments append' => FALSE,
),
Notice the third argument, parameters.
You can do all sorts of fun stuff with the index query as long as it is turned on, but what you havnt tried is ?parameters[name]=user Example below
When I make a request to http://test/api/user?parameters[name]=gdsfgsdfgsdfg&fields=name,uid
I get returned
[
{
"name":"gdsfgsdfgsdfg",
"uid":"36",
"uri":"http:\/\/test\/api\/user\/36"
}
]
Notice i also added some fields, uid and name. Obviously these are optional but it shows you the power of the index query. The same applies to nodes.
I hope this helps.
Try something like:
GET on http://mydomain.com/rest/user?parameters[name]=admin
This worked for me in Drupal7. Not sure if it'll be the same for 6. But I also had no issues with getting the index of all users using GET on http://mydomain.com/rest/user/
I found the issue. It's an error/bug with the Services module in the setup I have.
From the services.module file
449 // Now implode that array into an actual WHERE clause.
450 $where = !empty($where) ? ' WHERE '. implode(' AND ', $where) : '';
451 // Run through db_rewrite_sql to make sure proper access checks are applied.
// **** Error logged for this next line ****
452 $sql = "SELECT $fields FROM {$table} $where ORDER BY $order"; // <-- Error was logged for this line
453 $sql = db_rewrite_sql($sql);
454 $result = db_query_range($sql, $parameters, $page * 20, 20);
455 return $result;
The error
Table '<REDACTED>_drup1.users' doesn't exist query: SELECT * FROM users ORDER BY created DESC LIMIT 0, 20 in /<REDACTED>/sites/all/modules/services/services.module on line 455.
The users table in my installation is called drup_users. When I change line 452 to
452 $sql = "SELECT $fields FROM drup_{$table} $where ORDER BY $order";
It works. I'd be interested in knowing how I can have a more permanent solution. I ran update.php several times and it didn't fix this.