Oracle Apex. Is it possible to Ignore Process on Error? - oracle-apex

Is it possible to ignore a process if that process does not work?
I have a process that sends an email when the user clicks the Create button on my page. But the problem is that I can send up to 50 emails per day for security reasons. If the user exceeds 50 emails, this process displays an error and stops. So I can not save the new record. Is it possible on error to ignore this process and continue to save the new record?

Create an exception "when others" that will ignore any error
for example
declare
l_id number;
begin
l_id := apex_mail.send(
p_to => 'fred#flintstone.com',
p_from => 'barney#rubble.com',
p_subj => 'APEX_MAIL with attachment',
p_body => 'Please review the attachment.',
p_body_html => '<b>Please</b> review the attachment');
for c1 in (select filename, blob_content, mime_type
from apex_application_files
where id in (123,456)) loop
apex_mail.add_attachment(
p_mail_id => l_id,
p_attachment => c1.blob_content,
p_filename => c1.filename,
p_mime_type => c1.mime_type);
end loop;
commit;
exception
when others
then
rollback;
null;
end;

Related

Oracle APEX, apex_web_service.make_rest_request unable to add query params into rest call

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

How to send mail with an attachment to all users | Oracle APEX | UTL_SMTP method

It's been a hard time not able to get proper post where I can refer and develop the code.
Need to follow only : UTL_SMTP method. This only works at my end
Following is the way I have developed my application
Select file -> as drop down -> which gets filenames to drop down from upload file table
Drop down gets values from option selected : select list of values and set my table : upload_file
Table : upload_file
create table upload_file
(
fblob blob,
filename varchar2(4000 char),
mimetype varchar2(4000 char),
created_date date
);
Issue :
Now need to send mail to all users mentioned in interactive report
xyz#gmail.com
abc#gmail.com
lkg#gmail.com
Need to develop a code in such way that iterate through the all email ids
one by one and send mail to user with details : subject , Body and attachment
Output :
Subject : Update for user !!!
Body :
Hi <Name>,
We have update the details for you. please check !!!
Thank you
Code need to be created using UTL_SMTP with hostname and port
host : abc.xmp.cc
port : 45
I have code which sends mail but how to integrate into my application.
And send mail to user which are shown in interactive report
CREATE OR REPLACE PROCEDURE send_mail (p_to IN VARCHAR2,
p_from IN VARCHAR2,
p_message IN VARCHAR2,
p_smtp_host IN VARCHAR2,
p_smtp_port IN NUMBER DEFAULT 25)
AS
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(p_smtp_host, p_smtp_port);
UTL_SMTP.helo(l_mail_conn, p_smtp_host);
UTL_SMTP.mail(l_mail_conn, p_from);
UTL_SMTP.rcpt(l_mail_conn, p_to);
UTL_SMTP.data(l_mail_conn, p_message || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.quit(l_mail_conn);
END;
/
BEGIN
send_mail(p_to => 'me#mycompany.com',
p_from => 'admin#mycompany.com',
p_message => 'This is a test message.',
p_smtp_host => 'smtp.mycompany.com');
END;
/
Note :
Interactive report as filter option as well.
If I filter any class that many people only should be sent mail on button click : Send mail

How to create a user with the Admin Directory api using the google-api-ruby-client?

I've been trying a few combinations but can't seem to come up with something that works. More information about the API I'm asking about can be found here https://developers.google.com/admin-sdk/directory/v1/reference/users/insert . I have a feeling I'm just not setting up the request correctly. The following bit of code is known to work. I use it to set up the client that is able to query all the users.
client = Google::APIClient.new(:application_name => "myapp", :version => "v0.0.0")
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => "https://www.googleapis.com/auth/admin.directory.user",
:issuer => issuer,
:signing_key => key,
:person => user + "#" + domain)
client.authorization.fetch_access_token!
api = client.discovered_api("admin", "directory_v1")
When I try to use the following code
parameters = Hash.new
parameters["password"] = "ThisIsAPassword"
parameters["primaryEmail"] = "tstacct2#" + domain
parameters["name"] = {"givenName" => "Test", "familyName" => "Account2"}
parameters[:api_method] = api.users.insert
response = client.execute(parameters)
I always get back the same error "code": 400, "message": "Invalid Given/Family Name: FamilyName"
I've observed a few things while looking into this particular API. If I print out the parameters for both the list and the insert functions e.g
puts "--- Users List ---"
puts api.users.list.parameters
puts "--- Users Insert ---"
puts api.users.insert.parameters
Only the List actually displays the parameters
--- Users List ---
customer
domain
maxResults
orderBy
pageToken
query
showDeleted
sortOrder
--- Users Insert ---
This leaves me wondering if the ruby client is unable to retrieve the api and therefore unable to submit the request correctly or if I'm just doing something completely wrong.
I'd appreciate any idea's or direction that might help set me on the right path.
Thank you,
James
You need to supply an Users resource in the request body, which is also the reason why you don't see it in the params.
So the request should look like:
# code dealing with client and auth
api = client.discovered_api("admin", "directory_v1")
new_user = api.users.insert.request_schema.new({
'password' => 'aPassword',
'primaryEmail' => 'testAccount#myDomain.mygbiz.com',
'name' => {
'familyName' => 'John',
'givenName' => 'Doe'
}
})
result = client.execute(
:api_method => api.users.insert,
:body_object => new_user
)

location_id for Facebook event creation

I am trying to use location_id , which I retrieved from my current location, as a parameter for Facebook event creation, here is my code:
I have set up all the authorization token and extended permission , and it indeed returned a valid location id; however, after I plug the location_id into the event creation parameter array, it did not create an event. (all the other fields are set through a form).Could anyone help?
Here is my code:
try{
//default location
$event_url = $my_url . 'create_group.php';
$event_location = $facebook->api('/me?fields=location');
$event_location_id = $event_location['id'];
echo $event_location_id;
}
catch(Exception $e)
{
echo $e;
}
$params= array(
"name" => "[Study Group]".$_POST['name'],
"description" => $_POST['description'],
"location_id" => $event_location_id,
"start_time" => $_POST['start_time'].$_POST['time_zone'],
"privacy_type" => $_POST['privacy_type'],
"end_time" => $_POST['end_time'].$_POST['time_zone']
);
Here is the exception I have:
Exception: The place or event you attempted to plan to attend is invalid. Please try a different place or event.
The exception is solved in the following way:
change:
$event_location_id = $event_location['id'];
to
$event_location_id= $event_location['location']['id'];
The exception tells itself that the error is the wrong value of Location Id.
And as you have debugged it by yourself that this was because of you retrieved it as
$event_location_id = $event_location['id'];
Which should instead be retrieved as
$event_location_id= $event_location['location']['id'];

How can I retrieve a user using a query string from drupal using REST?

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.