I am attempting to build a set of tools in PHP designed to "smoke text" various data transmissions to and from our Salesforce org, using PHP Toolkit 20.0. Here is my PHP:


$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection('enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login(USERNAME, PASSWORD); // constants

The enterprise.wsdl.xml file exists and was generated by the tool in our org. Later, I use cURL in order to send a POST request with our test data JSON, like so:

// Parse data for POST; this is an associative array of sample data
// from a real request on our Salesforce website front end
$data = json_encode($data);

// Open cURL connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // set elsewhere
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);

However, this is the response that we get back from Salesforce:

        "statusCode": 402,
        "type": "exception",
        "ref": false,
        "action": "Unknown",
        "method": "Unknown",
        "message": "Unable to determine from which page the request originated",
        "where": "",
        "data": "",
        "vfTx": true,
        "vfDbg": true
  1. What is a 402 error? Does that even exist? What does it mean in terms of Salesforce HTTP requests?

  2. What does this error message mean, and why am I getting that in response? What am I doing wrong?

EDIT: Here are the contents of $mylogin:

stdClass Object
    [metadataServerUrl] => https://xxxxx.my.salesforce.com/services/Soap/m/38.0/00D30000000YOmO
    [passwordExpired] => 
    [sandbox] => 
    [serverUrl] => https://xxxxx.my.salesforce.com/services/Soap/c/38.0/00D30000000YOmO/0DF50000000GvWu
    [sessionId] => 00D30000000YOmO!ARsAQAekh1PIkZKIwGd_QnGO1YP0dc3b9zbFeAQMscaEz.Ml8hbeuJxevikdD5f4f4zYZXHLgyrnrIeDnLUXJ0nlDeC7ujMz
    [userId] => 005a000000CoBAjAAN
    [userInfo] => stdClass Object
            [accessibilityMode] => 
            [currencySymbol] => $
            [orgAttachmentFileSizeLimit] => 5242880
            [orgDefaultCurrencyIsoCode] => USD
            [orgDefaultCurrencyLocale] => en_US
            [orgDisallowHtmlAttachments] => 
            [orgHasPersonAccounts] => 
            [organizationId] => 00D30000000YOmOEAW
            [organizationMultiCurrency] => 
            [organizationName] => My Org Name
            [profileId] => 00ea00000024IAaAAM
            [roleId] => 00Ea0000001N13kEAC
            [sessionSecondsValid] => 3600
            [userDefaultCurrencyIsoCode] => 
            [userEmail] => xxxx@xxxxx.com
            [userFullName] => Richard Brum
            [userId] => 005a000000CoBAjAAN
            [userLanguage] => en_US
            [userLocale] => en_US
            [userName] => xxxx@xxxxx.com
            [userTimeZone] => America/New_York
            [userType] => Standard
            [userUiSkin] => Theme3
  • When you're creating a connection here: $mySforceConnection->login(USERNAME, PASSWORD), what's in $mylogin? – Dan Jones Jan 17 '17 at 14:50
  • @DanJones I added it to the question above. Was too long for a comment. :) – TerranRich Jan 17 '17 at 14:58
  • What's the URL you're trying to post the JSON data to? – superfell Jan 17 '17 at 15:08
  • I am posting to https://mxw-qa.force.com/apexremote. I took that from all of the AJAX requests that our regular site makes to the Salesforce back end. – TerranRich Jan 17 '17 at 15:10
  • Update! I sent new header information (host, origin, referer, etc.) and now am getting “No access to QuestionSet with ID ...”. I think I might have the wrong user. I will comment with more as I figure things out. – TerranRich Jan 17 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.