ejholmes / metaforce

A ruby client for interacting with the Salesforce Metadata and Services API's.
https://github.com/ejholmes/metaforce
MIT License
65 stars 75 forks source link

Enable to log with session_id and instance url ! #70

Open RedaBenh opened 8 years ago

RedaBenh commented 8 years ago

Hi, I try to log with sesison_id instead of username+password+securtiy_token.

Metaforce.configure do |config|
  config.api_version = '36.0'
  config.host = "na13.salesforce.com"
end
client = Metaforce.new(session_id: "00Db0000000cJSi!ARQAQOA5qVoBm9atAXwi9YSLLu.Ar.LpbgbvCyKDKs7ko2IvSDrB8outoVu5gvPmfjj3GQCibyK0amdkItkxo0W5x7m8EQML")
# make a describe call to test
client.describe[:metadata_objects]

RESPONSE :

 => #<Metaforce::Client @options={:session_id=>"00Db0000000cJSi!ASXXXXxXXXXXxXXXXxXXXbyK0amdkItkxo0W5x7m8EQML"}> 
1.9.3-p551 :037 > client.describe[:metadata_objects]
D, [2016-04-23T11:34:15.605931 #14856] DEBUG -- : SOAP request: https://login.salesforce.com/services/Soap/m/26.0
D, [2016-04-23T11:34:15.606030 #14856] DEBUG -- : SOAPAction: "describeMetadata", Content-Type: text/xml;charset=UTF-8, Content-Length: 604
D, [2016-04-23T11:34:15.606062 #14856] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://soap.sforce.com/2006/04/metadata" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://soap.sforce.com/2006/04/metadata"><env:Header><ins0:SessionHeader><ins0:sessionId>00Db0000000cJSi!ASXXXXxXXXXXxXXXXxXXXbyK0amdkItkxo0W5x7m8EQML</ins0:sessionId></ins0:SessionHeader></env:Header><env:Body><ins0:describeMetadata></ins0:describeMetadata></env:Body></env:Envelope>
W, [2016-04-23T11:34:15.606107 #14856]  WARN -- : HTTPI executes HTTP POST using the httpclient adapter
D, [2016-04-23T11:34:16.049337 #14856] DEBUG -- : SOAP response (status 500):
D, [2016-04-23T11:34:16.049496 #14856] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>UNKNOWN_EXCEPTION</faultcode><faultstring>UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService</faultstring><detail><sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault"><sf:exceptionCode>UNKNOWN_EXCEPTION</sf:exceptionCode><sf:exceptionMessage>Destination URL not reset. The URL returned from login must be set in the SforceService</sf:exceptionMessage></sf:UnexpectedErrorFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
Savon::SOAP::Fault: (UNKNOWN_EXCEPTION) UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/savon-1.2.0/lib/savon/soap/response.rb:107:in `raise_errors'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/savon-1.2.0/lib/savon/soap/response.rb:18:in `initialize'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/savon-1.2.0/lib/savon/soap/request.rb:35:in `new'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/savon-1.2.0/lib/savon/soap/request.rb:35:in `response'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/savon-1.2.0/lib/savon/client.rb:86:in `request'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/metaforce-1.1.0/lib/metaforce/abstract_client.rb:54:in `perform_request'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/metaforce-1.1.0/lib/metaforce/abstract_client.rb:42:in `request'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/metaforce-1.1.0/lib/metaforce/metadata/client/file.rb:34:in `describe'
  from /Users/redabenh/.rvm/gems/ruby-1.9.3-p551/gems/metaforce-1.1.0/lib/metaforce/client.rb:23:in `method_missing'
  from (irb):37
  from /Users/redabenh/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'

As you see the request is sent to "https://login.salesforce.com/services/Soap/m/26.0" [2016-04-23T11:34:15.605931 #14856] DEBUG -- : SOAP request: https://login.salesforce.com/services/Soap/m/26.0

Can you please show me and example how to use metaforce with session id (because i already get it from a oauth authentification) ?

Thanks for your help,

Reda

RedaBenh commented 8 years ago

Hi Any update about my question ? Thanks