I am using salesforce Enterprise api to add leads in salesforce.
$SFDCUSERNAME = "myusername";
$SFDCPASSWORD = "mypassword!";
$SFDCSECURITY_TOKEN = "mytoken";
$SFDCCLIENT = "soapclient/SforceEnterpriseClient.php";
$SFDCWSDL = "soapclient/enterprise.wsdl.xml";
require_once($SFDCCLIENT);
try {
$mySforceConnection = new SforceEnterpriseClient();
$myConnection = $mySforceConnection->createConnection($SFDCWSDL);
$myLogin = $mySforceConnection->login($SFDCUSERNAME, $SFDCPASSWORD.$SFDCSECURITY_TOKEN);
}
catch(Exception $e) {
print_r($e);
}
I can create leads using api.
Now I want to retrieve all fields which are available to a lead in salesforce(not only the custom fields but also the default/in_built fields) and show it in a HTML drop down field.
Is it possible to retrieve all fields of a lead using salesforce api?
After a long search I got an answer and it worked for me. I am posting it here , hoping it may be helpful to someone some other time.
try {
$mySforceConnection = new SforceEnterpriseClient();
$myConnection = $mySforceConnection->createConnection($SFDCWSDL);
$myLogin = $mySforceConnection->login($SFDCUSERNAME, $SFDCPASSWORD.$SFDCSECURITY_TOKEN);
echo "<pre>";
print_r($mySforceConnection->describeSObject('Lead'));
echo "</pre><br>";
}
catch(Exception $e) {
print_r($e);
}
There is a function in salesforce api describeSObject() which outputs the complete details about the object including the field details.
REFERENCE
Related
I want to use shopify order webhook to store order data into mysql database. I am beginner in webhooks. Googled many times to find the guidance about how to achieve it.I found this solutions is very close for me.I wrote the php code but I am getting error like this error img.I don't know why I am getting this error and how to resolve it.Please suggest us.
I followed these steps
I created the webhook from shopify admin dashboard
Point the webhook to my own domain
And write the following code in the pointed link
here is my code
my code is
<?php
$webhook_content = NULL;
// Get webhook content from the POST
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhook_content .= fread($webhook, 4096);
}
fclose($webhook);
// Decode Shopify POST
$webhook_content = json_decode($webhook_content, TRUE);
$servername = "localhost";
$database = "xxxxxxxx_xxxhalis";
$username = "xxxxxxxx_xxxhalis";
$password = "***********";
$sql = "mysql:host=$servername;dbname=$database;";
// Create a new connection to the MySQL database using PDO, $my_Db_Connection is an object
try {
$db = new PDO($sql, $username, $password);
//echo "<p> DB Connect = Success.</p>";
} catch (PDOException $error) {
echo 'Connection error: ' . $error->getMessage();
}
$order_num= $webhook_content['name'];
$order_date = $webhook_content['created_at'];
$order_mode = "Online";
$location= $webhook_content['default_address']['province'];
$cust_name = $webhook_content['billing_address']['name'];
$address = $webhook_content['default_address']['address1']['address2']['city']['province']['zip'];
$phone_num = $webhook_content['default_address']['phone'];
$special_note= $webhook_content['note'];
$total_mrp = $webhook_content['current_subtotal_price'];
$total_discount= $webhook_content['current_total_discounts'];
$sub_total = $webhook_content['current_subtotal_price'];
$delivery_charges = $webhook_content['presentment_money']['amount'];
$totalOrderValues= $webhook_content['total_price'];
$discount_approval = "NA";
$invoice_status= "NA";
$punching_status = "NA";
$order_source = "Shopify";
$payment_mode= $webhook_content['payment_gateway_names'];
$payement_status = "Done";
$payement_recieve_date= $webhook_content['processed_at'];
$reference_number = $webhook_content['reference'];
$cash_handover_status = "NA";
$my_Insert_Statement = $my_Db_Connection->prepare("INSERT INTO `customer_order_sab`( `order_num`, `order_datetime`, `modeOfOrder`, `location`, `customer_name`, `address`, `phone_number`, `special_note`, `total_mrp`, `total_discount`, `sub_total`, `delivery_charges`, `totalOrderValues`, `discount_approval`, `invoice_status`, `punching_status`, `order_source`, `payment_mode`, `payement_status`, `payement_recieve_date`, `reference_number`, `cash_handover_status`) VALUES (:order_num, :order_date, :order_mode, :location, :cust_name, :address, :phone_num, :special_note, :total_mrp, :total_discount, :sub_total, :delivery_charges, :totalOrderValues, :discount_approval, :invoice_status, :punching_status, :order_source, :payment_mode, :payement_status, :payement_recieve_date, :reference_number, :cash_handover_status)");
$my_Insert_Statement->bindParam(':order_num', $order_num);
$my_Insert_Statement->bindParam(':order_date', $order_date);
$my_Insert_Statement->bindParam(':order_mode', $order_mode);
$my_Insert_Statement->bindParam(':location', $location);
$my_Insert_Statement->bindParam(':cust_name', $cust_name);
$my_Insert_Statement->bindParam(':address', $address);
$my_Insert_Statement->bindParam(':phone_num', $phone_num);
$my_Insert_Statement->bindParam(':special_note', $special_note);
$my_Insert_Statement->bindParam(':total_mrp', $total_mrp);
$my_Insert_Statement->bindParam(':total_discount', $total_discount);
$my_Insert_Statement->bindParam(':sub_total', $sub_total);
$my_Insert_Statement->bindParam(':delivery_charges', $delivery_charges);
$my_Insert_Statement->bindParam(':totalOrderValues', $totalOrderValues);
$my_Insert_Statement->bindParam(':discount_approval', $discount_approval);
$my_Insert_Statement->bindParam(':invoice_status', $invoice_status);
$my_Insert_Statement->bindParam(':punching_status', $punching_status);
$my_Insert_Statement->bindParam(':order_source', $order_source);
$my_Insert_Statement->bindParam(':payment_mode', $payment_mode);
$my_Insert_Statement->bindParam(':payement_status', $payement_status);
$my_Insert_Statement->bindParam(':payement_recieve_date', $payement_recieve_date);
$my_Insert_Statement->bindParam(':reference_number', $reference_number);
$my_Insert_Statement->bindParam(':cash_handover_status', $cash_handover_status);
if ($my_Insert_Statement->execute()) {
echo "New record created successfully";
} else {
echo "Unable to create record";
}
?>
You are doing it wrong in one giant respect, but I respect you for trying!
If you expect webhooks to be sent to your App from some store where you installed your App, and you expect to save data from the webhooks in your database you cannot create the webhooks from the Shopify Admin and then process them in your App due to security. Instead, you install a webhook from your App, instructing Shopify to send your App webhooks. This way, Shopify can use your App API token to secure the webhooks. Your App then receives webhooks and decides if they are legit or not. You cannot do that if you use the Admin.
Read up on creating webhooks for use with your App! You can choose RestAPI or GraphQL and go from there.
Similar issues -
INVALID_SESSION_ID using partner/enterprise wsdl for two different SF users - Tried solution but didn't work.
I was trying to use Salesforce PHP toolkit with ZF 2. I have added namespace to php files in salesforce soap client and used it in zend controller.
Added follwing line to all php files in Salesforce SOAP client library.
namespace Salesforce\Soapclient;
Then included it in ZF controller.
use Salesforce\Soapclient;
Here is the connetion code -
$empid = 'e1234567';
$sf_WSDL = 'C:\wamp\www\myapp\app\vendor\salesforce\wsdl\enterprise.wsdl.xml';
$sf_username = $config['salesforce']['username'];
$sf_password = $config['salesforce']['password'];
$sf_token = $config['salesforce']['token'];
/***********/
try {
// Create SOAP client instance
$sfSoapClient = new Soapclient\SforceEnterpriseClient();
// Create connection
$sfSoapClient->createConnection($sf_WSDL);
var_dump($_SESSION['enterpriseSessionId']);
if (isset($_SESSION['enterpriseSessionId'])) {
$location = $_SESSION['enterpriseLocation'];
$sessionId = $_SESSION['enterpriseSessionId'];
$sfSoapClient->setEndpoint($location);
$sfSoapClient->setSessionHeader($sessionId);
} else {
// Login to SF
$sfSoapClient->login($sf_username,$sf_password . $sf_token);
$_SESSION['enterpriseLocation'] = $sfSoapClient->getLocation();
$_SESSION['enterpriseSessionId'] = $sfSoapClient->getSessionId();
}
var_dump($_SESSION['enterpriseSessionId']);
// Get candidate profile by employee id
$candidate_profile = $this->getCandidateTable()->getCandidateByEmpId($empid);
$ids = array();
array_push($ids, $empid);
// If no profile for logged internal employee
if (!$candidate_profile){
$query = "SELECT Id, First_Name__c from Employee__c";
$response = $sfSoapClient->query($query);
echo "Results of query '$query'<br/><br/>\n";
foreach ($response->records as $record) {
echo $record->Id . ": " . $record->First_Name__c . "<br/>\n";
}
}
} catch (Exception $exc) {
//TODO Handle error login exception
die('Connection could not established.');
}
But I'm getting following error -
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal
Session
Note that "Lock sessions to the IP address from which they originated" setting is turned off.
I have downloaded 2012_2 PHP Toolkit for Netsuite. With less or no documentation it would be great if someone can give me headstart on how to connect to a Custom Record List Created in Netsuite
The list is labs under lists->support in netsuite.
Through PHP i want to enter data to that list I dont need the entire code, I just need a headstart on how to connect to that custom record I created in netsuite. I have the internal id of the custom record and the name of the custom record in netsuite.
For others to refer later on this could be helpful
$service = new NetSuiteService();
// Create a object for lab name in netsuite
$labName = new SelectCustomFieldRef();
$labName->value = new ListOrRecordRef();
$labName->value->internalId = $lab_number; // your input
$labName->internalId = "xxxxxx"; // internal id of the input in Netsuite
$labCustomRecord = new CustomRecord();
$labCustomRecord->recType = new RecordRef();
$labCustomRecord->customForm = "xxxx"; // form id
$labCustomRecord->recType->internalId = "xx"; // internal id
$labCustomRecord->customFieldList = new CustomFieldList();
$labCustomRecord->customFieldList->customField = $labName
$addRequest = new AddRequest();
$addRequest->record = $labCustomRecord;
if(!$addResponse[$i]->writeResponse->status->isSuccess) {
echo "<pre>"; print_r("Error"); echo "</pre>"; exit();
} else {
echo "<pre>"; print_r("Success"); echo "</pre>"; exit();
}
Below is a sample code on how to add new record for a custom record type using PHP Toolkit 2012.2
//create an instance of the fields of the custom record
$customFieldList = new StringCustomFieldRef();
$customFieldList->internalId = "custrecord_name";
$customFieldList->value = "Test from PHP toolkit";
$basicCustomRecord = new CustomRecord();
$basicCustomRecord->name = "PHP Toolkit 2012.2";
$basicCustomRecord->recType = new RecordRef();
$basicCustomRecord->recType->internalId = "14"; //Record Type's internal ID (Setup > Customization > Record Types > Basic Record Type (Internal ID=14)
$basicCustomRecord->customFieldList = new CustomFieldList();
$basicCustomRecord->customFieldList->customField = $customFieldList;
$addRequest = new AddRequest();
$addRequest->record = $basicCustomRecord;
$addResponse = $service->add($addRequest);
if (!$addResponse->writeResponse->status->isSuccess) { echo "ADD ERROR"; exit();}
else { echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;}
?>
this same code is available in SuiteAnswers. There are a number of other sample codes for PHP Toolkit 2012.2 in SuiteAnswers as well. If you have time, you can review those code for your future reference.
Regards!
I am using gigya php sdk, It works well I am able to post to user's wall or profile using socialise.setStatus method but I am have problems when I try to use the publishuseraction method. I get an error Invalid request signature.
$method = "socialize.publishUserAction";
$request = new GSRequest($apiKey,$secretKey,$method);
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\", \"linkBack\":\"http://google.com\", \"mediaItems\":[{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
$request->setParam("userAction", $userAction);
$request->setParam("uid", $userUID);
$response = $request->send();
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
}
UPDATED AFTER USING $response->getLog()
apiMethod=socialize.publishUserAction
apiKey=correct_api_key
params={"userAction":{},uid":"MY_UID","format":"json","httpStatusCodes":"false"}
URL=http://socialize.gigya.com/socialize.publishUserAction postData=uid=urlencoded(MY_UID)&format=json&httpStatusCodes=false&apiKey=correct_api_keyĆtamp=1296229876&nonce=1.29622987636E%2B12&sig=HEdzy%2BzxetV8QvTDjdsdMWh0%2Fz8%3D
server= web504
I used both put method
$userAction = new GSDictionary();
$userAction->put("title", "This is my title");
$userAction->put("userMessage", "This is my user message");
$userAction->put("description", "This is my description");
$userAction->put("linkBack", "http://google.com");
$mediaItems = array();
$mediaItems[0] = new GSDictionary("{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}");
& JSON method
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\",
\"linkBack\":\"http://google.com\", \"mediaItems\":[ {\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
I get the same error. And User action is empty using both methods. I appreciate any help.
Thanks.
Try calling getLog() for a bit more information about the error:
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
print "<pre>";
print_r($response->getLog());
print "</pre>";
}
Also, are you able to run getUserInfo w/ the SDK? This is a simple test that also requires a signature. Use the example on the PHP SDK page (about 1/2 way down).
I have modified my PHP web app to add events to a Google Calendar. Currently, it adds successfully.
However, now I wish to delete and edit events. This seems easy to do, except for the fact that I don't know what event URL is associated with each event.
Am I supposed to set this event URL (or ID?) upon adding an event? How am I supposed to figure out what it is?
I can't seem to find this information anywhere else...
Thanks!
EDIT:
I have been using the Zend Framework for this (Gdata package)...
EDIT:
$newIncludePath = array();
$newIncludePath[] = '../ZendGdata-1.8.4PL1/library';
$newIncludePath = implode($newIncludePath);
set_include_path($newIncludePath);
// load classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// connect to service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "********#gmail.com";
$pass = "*****";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
// construct event object
// save to server
try {
$event = $gcal->newEventEntry();
$event->title = $gcal->newTitle($title);
$event->content = $gcal->newContent($desc);
$when = $gcal->newWhen();
$when->startTime = $date;
$when->endTime = $date;
$event->when = array($when);
$gcal->insertEvent($event);
echo $event->getEditLink()->href;
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: Unable to add event to Google Calendar" . $e->getResponse();
}
This is plainly documented in the Zend_Gdata documentation:
http://framework.zend.com/manual/en/zend.gdata.calendar.html#zend.gdata.calendar.deleting_events
// Option 1: Events can be deleted directly
$event->delete();
or
// Option 2: Events can be deleted supplying the edit URL of the event
// to the calendar service, if known
$service->delete($event->getEditLink()->href);
It sounds like you need the latter.
Edit:
Get the edit link from your $event. It's shown in the code above:
$event->getEditLink()->href;
This will be available on a saved event. e.g.
$newEvent = $service->insertEvent($event);
echo $newEvent->getEditLink()->href;
You could have a look at Zend_Gdata and Zend_Gdata_Calendar : those would probably help for all the hard work -- and if you don't have to spend code to communicate with Google's API, it gives you more time to develop other things ;-)
And it seems it can be used outsid of the Zend FRamework : it's even available as a standalone download : http://framework.zend.com/download/gdata
(If you really want to do it yourself, you can still try to understand how Zend_Gdata does it ^^ )
Here's a GREAT resource to help you with this:
Integrate your PHP application with Google Calendar
Here's how I obtain the unique ID of the calendar event after publishing the event with newEventEntry. I store the $id value in the database, in case I have to edit it later with update or delete.
try {
$event = $gcal->newEventEntry();
$event->title = $gcal->newTitle($title);
$when = $gcal->newWhen();
$when->startTime = $start;
$when->endTime = $end;
$event->when = array($when);
$gcal->insertEvent($event);
$id = substr($event->id, strrpos($event->id, '/')+1); // trim off everything but the id
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
// Do mysql Insert functions here to store the record in db (removed for clarity)
echo 'Event '. $id. 'successfully added!';
Then, when I need to access that particular event I can use it to target just that event for updating/deleting using a $_POST of the ID:
try {
$event = $gcal->getCalendarEventEntry('http://www.google.com/calendar/feeds/default/private/full/' . $_POST['id']);
$event->title = $gcal->newTitle($title);
$when = $gcal->newWhen();
$when->startTime = $start;
$when->endTime = $end;
$event->when = array($when);
$event->save();
} catch (Zend_Gdata_App_Exception $e) {
die("Error: " . $e->getResponse());
}
echo 'Event successfully modified!';
Hope this answers your question - I struggled with getting this working, but share my findings with you here, if it helps I'm happy to have assisted.
Scott
Well if you dont want to store event ids in local database, here another good way to deleting event if you have infomration about start time, end time and calendar id(specific calendar for which you want to delete event between start time and end time)
function deleteEvent($client,$startDate,$endDate,$startTime,$endTime,$tzOffset,$cal_id)
{
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser($cal_id);
$query->setVisibility('private');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setStartMin("{$startDate}T{$startTime}:00.000{$tzOffset}");
$query->setStartMax("{$endDate}T{$endTime}:00.000{$tzOffset}");
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
$event->delete();
}
}
Hope it helps to somebody, like it did to me.