0

I try to call retrieve in SOAP using PHP but I need to login before. For login, I have a token that I get from "https://test.salesforce.com/services/oauth2/token"

So, I try to pass this token in the header of my SOAP request

    $wsdl = PUBLIC_PATH . '/wsdl-metadata.xml'; // le fichier wsdl

    $apiVersion = 44.0;
    $singlePackage = true;
    $members = 'ServiceSetting.' . $service;
    $name = 'customMetadata';

    $params = new StdClass();
    $params->retrieveRequest = new StdClass();
    $params->retrieveRequest->apiVersion = $apiVersion;
    $params->retrieveRequest->singlePackage = $singlePackage;
    $params->retrieveRequest->unpackaged = new StdClass();
    $params->retrieveRequest->unpackaged->version = $apiVersion;
    $params->retrieveRequest->unpackaged->type = new stdClass();
    $params->retrieveRequest->unpackaged->type->members = $members;
    $params->retrieveRequest->unpackaged->type->name = $name;

    $option = [
        'trace' => TRUE,
    ];
    // Namespaces
    $namespace = 'http://soap.sforce.com/2006/04/metadata';
    $client = new SoapClient($wsdl, $option);

    $header = new SoapHeader($namespace, "SessionHeader", array ('sessionId' => $token));
    $client->__setSoapHeaders($header);
    $serviceResult = $client->retrieve($params);

The Error is

UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

0

You need more than just a session ID; you also need the correct endpoint. The default endpoint in the SOAP client is only for logging in. When you get a token (or session ID), you'll have a serverUrl attribute. You'll need to store this so you can set it later, something like:

$client->setEndPoint($serverUrl);
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.