Is it possible to send custom XML messages from oracle service cloud while maintaining HTTP session?
So far I've managed to send a single message using cURL:
<?php
use \Rightnow\Connect\v1_2 as RNCPHP;
use \Rightnow\CPM\v1 as RNCPM;
$url1 = "";
$startInterviewHeaders = array("SOAPAction: http://oracle");
$startInterview;
// session
//$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
if(!function_exists("\curl_init")){
\load_curl();
echo "curl loaded";
} else {
echo "curl already exists ";
}
$ch = curl_init();
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POSTFIELDS, $startInterview);
curl_setopt($ch, CURLOPT_HTTPHEADER, $startInterviewHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$startInterviewresponse = curl_exec($ch);
//echo $response;
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errno= curl_errno($ch);
echo "</br> HTTP status: " . $http_status . "</br> cURL error: " .$curl_errno . "</br>";
curl_close($ch); // close cURL
echo $startInterviewresponse;
?>
EDIT: Code above sends a single message and gets a response, but when I try to maintain HTTP session with CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE, second cURL message response complains that there is no active session.
sessions.com.oracle.determinations.server.exceptions.NoActiveInterviewExceptionaction "Investigate" can not be performed without an active interview
Code I used to maintain session (worked when testing outside Rightnow environment)
curl_setopt($ch,CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name'); //could be empty, but cause problems on some hosts
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/ip4.x/file/tmp'); //could be empty, but cause problems
Thanks!
Your code sample is a Custom Process Model. CPMs do not allow persistence and will be closed once the CPM completes. You can run multiple curl calls from one CPM, but that is not recommended; you should use an integration middleware if you need multiple calls per CPM.
As long as you're running this code from an asynchronous CPM (synchronous CPMs don't expose curl, so that should be the case here), then an error on the OSvC side is likely an issue connecting to your "local test server", which is almost always not exposed to the public internet in an enterprise environment. Therefore, your "crash" is likely a connection error.
Per #drew010, you need to include your error in the context of this question as well.
Related
The scenario like this, I deployed my laravel app to heroku. The third-party api needs my production IP for whitelisting in order to use their resources. Heroku doesn't provide ip, I use add on to get ip. It connected ok between my app to third-party now. The problem is that, when I clone my app to local and start to run and test locally, it give error. (Undefined index: host) My code is below
$testparam = 'q='.$q.'&s='.$s;
$quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
$quotaguard = parse_url($quotaguard_env);
$proxyUrl = $quotaguard['host'].":".$quotaguard['port'];
$proxyAuth = $quotaguard['user'].":".$quotaguard['pass'];
$url = "http://xxxxx.com/api/resource";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_POSTFIELDS,$testparam);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_
decode($json,TRUE);
dd($array);
Currently, I have to push my file to heroku after I write one or two lines of code in order to see the result. Is there any way to write and test locally?
You need to set the QUOTAGUARDSTATIC_URL environment variable to what is in the QuotaGuard Admin dashboard or in Heroku's heroku config -a APPNAME command.
I'm getting the following error:
HTTP Status Code: 500
HTTP Status Message: The request was unsuccessful due to an unexpected condition encountered by the server.
Error Code : 5006
Error Description : Unable to redirect to Vendor's web site. The Vendor failed to provide a RedirectionURL.
I've looked at the help offered on this page:
Sagepay 5006 error code fix
but the problem is that the response is never reaching my Notification page, which I have checked is reachable, so I can't proceed to check many of the suggestions as I have no idea what the Sage Pay post contains.
here's the data i'm posting (I'm posting without the line breaks, and with a realVendor name!)
VPSProtocol=3.00&
TxType=PAYMENT&
Vendor=name&
VendorTxCode=2a5e86f2a8609ff996e6&
Amount=50&
Currency=GBP&
Description=Something about stuff&
NotificationURL=https%3A%2F%2Four-site.co.uk%2Fecodes%2Forder-confirmation.php&
BillingFirstnames=sdsdsd&
BillingSurname=sdsdsd&
BillingAddress1=sdsds&
BillingAddress2=sdsds&
BillingCity=sdsdsd&
BillingPostCode=dsdsdd&
BillingCountry=GB&
BillingEMail=sdfsf#adsad.com&
BillingPhone=12112121211&
DeliveryFirstnames=sdsdsd&
DeliverySurname=sdsdsd&
DeliveryAddress1=sdsds&
DeliveryAddress2=sdsds&
DeliveryCity=sdsdsd&
DeliveryPostCode=dsdsdd&
DeliveryCountry=GB
I'm posting this using code lifted from the Sage Pay exmaple:
set_time_limit(60);
$output = array();
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, 0);
curl_setopt($curlSession, CURLOPT_POST, 1);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curlSession, CURLOPT_TIMEOUT, $ttl);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, arrayToQueryString($data));
if (!empty($caCertPath))
{
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curlSession, CURLOPT_CAINFO, $caCertPath);
}
else
{
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 0);
}
$rawresponse = curl_exec($curlSession);
$response = queryStringToArray($rawresponse, "\r\n");
header('Location: '. $response['NextURL']]);
I'm trying to pipe support emails from my production mail server (Plesk 12 and Postfix) to send them to another VPS hosting my helpdesk installation, I have chosen ostickets helpdesk for many reasons (Open source,PHP/MySQL...)
So, the idea is to trigger email reception on some adresses such as contact#company.com, support#company.com... then resend them to ostickets via its API in order to create a new ticket there.
I tried this way
http://blog.absolutedisaster.co.uk/osticket-plesk-9-postfix-pipe-mail-to-a-progr/
It explains how to create a pipe to trigger email, lunch php script ...etc
Because of some permission issues, I kept all this configuration and change just the last thing : php script
So I've replaced this php script by a simple bash script doing the same thing : send a request to API to create a new ticket via CURL.
Now In my production mail server the pipe is recognized and the email is trigged successfully :
The same in the other side, osticket API is receiving the request:
The problem is that the http response is 400 as you can see, which means ans error code #66 in ostickets (malformed email).
So, I think the problem is in my bash script :
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data - 'http://support.company.com/api/tickets.email'
the original PHP script I have replaced by this is :
#!/usr/bin/php -q
<?php
# Configuration: Enter the url and key. That is it.
# url => URL to api/tickets.email e.g http://yourdomain.com/support/api/tickets.email
# key => API's Key (see admin panel on how to generate a key)
#
$config = array(
'url'=>'http://support.company.com/api/tickets.email',
'key'=>'API_KEY_HERE'
);
#pre-checks
function_exists('file_get_contents') or die('upgrade php >=4.3');
function_exists('curl_version') or die('CURL support required');
#read stdin (piped email)
$data=file_get_contents('php://stdin') or die('Error reading stdin. No message');
#set timeout
set_time_limit(10);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);
//Use postfix exit codes...expected by MTA.
$code = 75;
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status)) {
switch($status[1]) {
case 201: //Success
$code = 0;
break;
case 400:
$code = 66;
break;
case 401: /* permission denied */
case 403:
$code = 77;
break;
case 415:
case 416:
case 417:
case 501:
$code = 65;
break;
case 503:
$code = 69;
break;
case 500: //Server error.
default: //Temp (unknown) failure - retry
$code = 75;
}
}
exit($code);
?>
What is missing in my bash script ? (especially the stdin input)
thank you so much,
UPDATE
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'
I'm working on a script that send a POST request to an URL, actually I'm sending the cookies manually in the header.. but how to take it from the current browser session?
I used tcpdump and grep but it's really the wrong choice :,D
Some suggestions?
I wont take them from a file but from the browser session and without enter in the cookie path of the browser
Curl can handle that for you; there is an option to store the cookies in a cookiejar and use those in subsequent requests.
Here is an example from the main curl site, which uses cookies from a file cookies.txt to set some and at the same time stores new cookies in newcookies.txt.
http://curl.haxx.se/docs/httpscripting.html#Cookie_Basics
curl --cookie cookies.txt --cookie-jar newcookies.txt http://www.example.com
When going through a login process, for example, one would reuse the cookies from cookie jar.
I had found a link now broken with an example from snipplr.com. I'll post it here for future references (credits to the owner):
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (isset($_COOKIE[session_name()])) {
curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.$_COOKIE[session_name()].'; path=/');
}
session_write_close();
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'curl error: '.curl_error($ch);
}
curl_close($ch);
session_start();
I successfully posted an activity to the activity feed using the activity API and open graph. However, I do not see a post on the actor's Yammer feed when I click the user's name. I assumed that the activity API would post there as well because of what I read in the documentation:
This activity will appear in the Yammer Activity Stream Ticker (shown above) and will be delivered to the actor, the actor’s followers and the people specified in the “users” list
Here is the data I'm posting to the API. You can see that I'm also adding the actor as one of the 'users' who should get the post (look right after "private"=>"false"). Still no good.
$text=array("activity"=>
array("actor"=>
array("name"=>$res->user->full_name,
"email"=>$res->user->contact->email_addresses[0]->address),
"action"=>"domain:action",
"object"=>array("url"=>"https://website.com","type"=>"domain:object","title"=>"post"),
"private"=>"false",
"users"=>array("email"=>$res->user->contact->email_addresses[0]->address,"name"=>$res->user->full_name),
"message"=>"my first post"));
$text is then json_encoded. Here is the curl call:
$url="https://www.yammer.com/api/v1/activity.json";
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$jtext);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$accToken,'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
Here is the response to the above curl request:
stdClass Object
(
[action_id] => xxxxxxxxx
[object_id] => xxxxxxxxxxxxxxx
[actor_id] => xxxxxxxxxx
)
The Activity Stream Post is working fine as far as I can see, just wondering what code I'm missing (or API call) to post on the user's feed. This is written in PHP and needs to stay in PHP. Thanks in advance for the help.
The solution to my problem was that I wasn't using the messages API for posting to the user's wall.Here is working code based on the current API specification. I hope this helps someone else.
NOTE- the message has to be called 'body' and you need to set the 'Content-Type: application/json' in the header:
$text=array("body"=>"This is a test post");
$jtext=json_encode($text);
$url="https://www.yammer.com/api/v1/messages.json";
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$jtext);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$accToken,'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);