+ Start a Discussion

Metadata API - INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

Hi ...

I am using REST api for my application. But I also need to use Metadata api. So for metadata api calls I am trying to use the session Id of REST authentication. For now I am able to use session id of REST api for saop api calls but when I call a  metadata method I get this error:  "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"


Here is my code:

   $mySforceConnection = new SforcePartnerClient();
   $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');	
   $serverUrl = "$instance_url/services/Soap/u/27.0/00Dxxxxxxxxxxxx";
   $sessionId = $_SESSION['access_token'];
   $mylogin = $mySforceConnection->attach($serverUrl, $sessionId);
   $myMetadataConnection = new SforceMetadataClient(SOAP_CLIENT_BASEDIR.'/metadata.wsdl.xml', $myLogin, $mySforceConnection);

   /*--These 3 lines of code works fine ----*/
   $query = "SELECT Id, FirstName, LastName, Phone from Contact";
   $response = $mySforceConnection->query($query);

  $customField = new SforceCustomField();
  $customField->setDescription('Description of New Field');
  $customField->setLabel('My Custom Field Label');
  $customField->setFormula('HYPERLINK(AbdnS3__Password__c , "The Name")');

  /*-----------This line giving the Error----------*/
} catch (Exception $e) {
   echo $myMetadataConnection->getLastRequest();
   echo $e->faultstring;	




The server url for the metadata connection is different.

It should be like:



Notice the 'm' in the url instead of the 'u'.


Hope this helps!


Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.



Hi Satish....
I noticed that and that might be the problem but not sure because the error description does not tell any thing about url...
I also once tested your url 'm' instead of 'u' but no luck...