orther
asked on
New-WebServiceProxy passing sessionId to SOAP header
Ok, I'm dieing here. Somebody help me out please. Here's what I have going on:
I am trying to design a Powershell script that will connect to salesforce and retrieve information. The script I have so far will allow me to connect to the salesforce API and login, and it returns a sessionId in "$sf.loginResponse.Session Id". I want to take this session ID and insert it into the session header so that I can run API calls. Here is what I have so far:
Yes, I know there a password in there. This is just a developer account. There's no sensitive info in it and I'll change it once we fix this.
This script gives me the following errors in Powershell ISE 3.0:
I've tried to add-member but I'll not very good at it and I can't figure it out. If anyone can help me with this step I will reward generously. I've attached the script and WSDL file (in text format) for your review.
salesforce-api-partner.wsdl.txt
soap-request2.ps1.txt
I am trying to design a Powershell script that will connect to salesforce and retrieve information. The script I have so far will allow me to connect to the salesforce API and login, and it returns a sessionId in "$sf.loginResponse.Session
$URI = "[insert-full-path-to-file]\salesforce-api-partner.wsdl"
$username = "michael1@desktopninjas.com"
$password = "testtest171XKd4g57k4KFgXHk7QbK8Kc7"
$sf = New-WebServiceProxy -Uri $URI -Namespace sf -UseDefaultCredential
$sf
$LoginResponse = $sf.login($username, $password)
$LoginResponse
$newSession = $LoginResponse.sessionId
$newSession
$newURL = $LoginResponse.serverUrl
$sf.Url = $newURL
$sf.Url
$sf.SessionHeaderValue.sessionId = $newSession
$soapQuery = $sf.query("SELECT Name FROM Lead")
$sf.logout()
Yes, I know there a password in there. This is just a developer account. There's no sensitive info in it and I'll change it once we fix this.
This script gives me the following errors in Powershell ISE 3.0:
The property 'sessionId' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\mlucas\Dropbox\Desktop Ninjas\Clients\CCC\powershell-dev\0.1\soap-request2.ps1:20 char:1
+ $sf.SessionHeaderValue.sessionId = $newSession
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Exception calling "query" with "1" argument(s): "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"
At C:\Users\mlucas\Dropbox\Desktop Ninjas\Clients\CCC\powershell-dev\0.1\soap-request2.ps1:21 char:1
+ $soapQuery = $sf.query("SELECT Name FROM Lead")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SoapException
Exception calling "logout" with "0" argument(s): "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"
At C:\Users\mlucas\Dropbox\Desktop Ninjas\Clients\CCC\powershell-dev\0.1\soap-request2.ps1:22 char:1
+ $sf.logout()
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SoapException
I've tried to add-member but I'll not very good at it and I can't figure it out. If anyone can help me with this step I will reward generously. I've attached the script and WSDL file (in text format) for your review.
salesforce-api-partner.wsdl.txt
soap-request2.ps1.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This envelope actually works from SOAP-UI to pull data:
Open in new window
Comes back as this:
Open in new window