function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
abdnabdn 

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:

try{
   $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'];
   $mySforceConnection->setSessionHeader($sessionId);
   $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);
   print_r($response);
   /*--------------------------------------*/

  $customField = new SforceCustomField();
  $customField->setFullName('Contact.MyCustomFieldb__c');
  $customField->setDescription('Description of New Field');
  $customField->setLabel('My Custom Field Label');
  $customField->setType('Text');
  $customField->setFormula('HYPERLINK(AbdnS3__Password__c , "The Name")');
  $customField->setLength(100);
  //Contact->nameField=$customField;

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

 thanks

Satish_SFDCSatish_SFDC

Hi,

The server url for the metadata connection is different.

It should be like:

 

$instance_url/services/Soap/m/27.0/00Dxxxxxxxxxxxx

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

 

Hope this helps!

 

Regards,
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.

 

abdnabdn

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...