Unable to POST with Oracle Sales Cloud using Event Handler.

Tags: 

Hi,

I have to integrate Opportunities in Oracle Service Cloud with Leads in Oracle SALES Cloud. There is no ICS in this implementation so I need to configure this using an event handler in Service Cloud. Check the code I am using:

<?php

/*
* CPMObjectEventHandler: on_opportunity_create
* Package: RN
* Objects: Opportunity
* Actions: Create, Update
* Version: 1.2
*/

use \RightNow\Connect\v1_2 as RNCPHP;
use \RightNow\CPM\v1 as RNCPM;
use RightNow\Connect\v1_2\Audit as RNCPHP_Audit;

class on_opportunity_create implements RNCPM\ObjectEventHandler
{

public static function apply( $run_mode, $action, $obj, $n_cycles)
{
echo "Line 20";
if ($n_cycles !== 0) return;
if (RNCPM\ActionUpdate == $action)
{

}
elseif (RNCPM\ActionCreate == $action)
{

}
try
{
echo "Try";
$service_url = 'https://cbwt-test.crm.us2.oraclecloud.com:443/salesApi/resources/latest/leads';
load_curl();
$curl = curl_init($service_url);
$curl_post_data = array(
"name" => "OppTEst",
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 256);

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "user:pass");
header('Content-Type: ' . 'application/vnd.oracle.adf.resourceitem+json');//Only using this header the post worked using POSTMAN
echo "Before exec: ";
$curl_response = curl_exec($curl);
echo "Resp: "+ $curl_response;
curl_close($curl);
return;
}
catch (Exception $exception)
{
echo "Error "+$exception->getMessage();
}
}
}
/*
The Test Harness
*/
class on_opportunity_create_TestHarness
implements RNCPM\ObjectEventHandler_TestHarness
{
static $opp_invented;
public static function setup()
{

// For this test, create a new
// opportunity and incident as expected.
$opp = new RNCPHP\Opportunity;
$opp->Name = "PruebaPHP";
static::$opp_invented = $opp;
return;

}

public static function fetchObject( $action, $object_type )
{

// Return the object that we
// want to test with.
// You could also return an array of objects
// to test more than one variation of an object.
return static::$con_invented;
}

public static function validate( $action, $object )
{
/*echo "<pre>";
print_r( $object->prev->Name->First);
echo "<pre>";
print_r( $object->Name->First);*/
return true;
}
public static function cleanup()
{
// Destroy every object invented
// by this test.
// Not necessary since in test
// mode and nothing is committed,
// but good practice if only to
// document the side effects of
// this test.
//static::$inc_invented->destroy().
//static::$con_invented = NULL;
//static::$inc_invented = NULL;
return;
}
}

I am not getting anything. Not even something in the logs. Could you help me solve this problem?

thanks

Comments

I did a contact creation/updation in OSvc - OSC using CPMs. It is possible. Your SOAP request must be proper.

Hi Surena,

Try below type of request,

$input = "{\"FirstName\" : \"$fst_name\",\"LastName\":\"$lst_name\",\"EmailAddress\" : \"$mail\",\"MobileNumber\":\"$mobile_num\",\"Address\": [{\"Address1\":\"$sddress\",\"Address2\":\"$address2\",\"City\":\"$city\",\"Country\": \"$cntry\"}]}";

$data_json = json_encode($input);

echo $input;

Change ur header as below one,

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/vnd.oracle.adf.resourceitem+json','Content-Length: ' . strlen($input)));

Can u create lead using the url in postman?
https://cbwt-test.crm.us2.oraclecloud.com:443/salesApi/resources/latest/leads

"443" needs to be remove.

Please try the above things.

Thanks,
S.Saravanan

S.Saravanan

Zircon - This is a contributing Drupal Theme
Design by WeebPal.