• RedSquirrel
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies

I recently created a ruby script to login to salesforce and create some objects. It has worked for about a week and all of a sudden the same script will no longer login. It says that I have the wrong name, password, or security token or that I may be locked out.

 

To verify I have the correct security token, I reset it and put it in the script as [password][security token]. Still fails to login. 

 

I tried downloaded the wsdl again to see if the endpoint I need changed. It is still the same.

 

In case of being logged out, I checked and it says a the user will be locked out for 15 minutes. I went to lunch for an hour came back and still failed to login.

 

I don't know what could be going wrong, does anyone have advice to a solution?

 

I created a new contact with the code below. Got the successful response from the xml shown below. But, I logged into salesforce and do not see the contact I created. Is something wrong with the code? does it take a while for new candidates to appear?

 

Thanks.

 

client.create! do |s|

  s.namespace = 'urn:enterprise.soap.sforce.com'

  s.namespaces["xmlns:urn1"] = 'urn:sobject.enterprise.soap.sforce.com'

  s.namespaces["xmlns:xsi"] = 'http://www.w3.org/2001/XMLSchema-instance'

  s.header = {'xsi:SessionHeader' => {'xsi:sessionId' => 'session id'}}

  s.body = {"xsi:sObjects" => {"FirstName" => 'Test', "LastName" => 'Tester'}, :attributes! => {"xsi:sObjects" => {"xsi:type" => 'urn1:Contact'}}}.to_soap_xml

end

 

 

SOAP request: https://na2-api.salesforce.com/services/Soap/c/19.0/00D400000008UpO/0DF400000004Ge0

SOAPAction: create, Content-Type: text/xml;charset=UTF-8

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:wsdl="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><xsi:SessionHeader><xsi:sessionId>session id</xsi:sessionId></xsi:SessionHeader></env:Header><env:Body><wsdl:create><xsi:sObjects xsi:type="urn1:Contact"><LastName>Tester</LastName><FirstName>Test</FirstName></xsi:sObjects></wsdl:create></env:Body></env:Envelope>

SOAP response (status 200):

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com"><soapenv:Body><createResponse><result><id>0034000000fdcHQAAY</id><success>true</success></result></createResponse></soapenv:Body></soapenv:Envelope>

 => #<Savon::Response:0xb678bad4 @http=#<Net::HTTPOK 200 OK readbody=true>, @soap_fault_message=nil, @hash={:create_response=>{:result=>{:success=>true, :id=>"0034000000fdcHQAAY"}}}>

 

I am trying to create a new Contact.

 

The soap error says: "The prefix "wsdl" for element "wsdl:create" is not bound."

 

 

 

s.namespaces["xmlns:urn"] = 'urn:enterprise.soap.sforce.com'

s.namespaces["xmlns:urn1"] = 'urn1:sobject.enterprise.soap.sforce.com'

s.namespaces["xmlns:xsi"] = 'http://www.w3.org/2001/XMLSchema-instance'

s.header = {'urn:SessionHeader' => {'urn:sessionId' => 'my session id'}}

s.body = {"urn:sObjects" => {"FirstName" => 'Test', "LastName" => 'Tester'}, :attributes! => {"urn:sObjects" => {"xsi:type" => 'urn1:Contact'}}}.to_soap_xml

 

The xml being sent is:

<?xml version="1.0" encoding="UTF-8"?>

<env:Envelope

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:urn1="urn1:sobject.enterprise.soap.sforce.com"

xmlns:urn="urn:enterprise.soap.sforce.com"

xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">

<env:Header>

<urn:SessionHeader>

<urn:sessionId>my session id</urn:sessionId>

</urn:SessionHeader>

</env:Header>

<env:Body>

<wsdl:create>

<urn:sObjects xsi:type="urn1:Contact">

<LastName>Tester</LastName>

<FirstName>Test</FirstName>

</urn:sObjects>

</wsdl:create>

</env:Body>

</env:Envelope>

 

I believe it needs to be <urn:create> not <wsdl:create> but I cannot figure out how to do that. I am using ruby and the savon libraray. Are my namespaces correct?

I am trying to create a new custom object. But even before I do that I am trying to make a new Contact just to verify I know how to create something.

 

I keep getting an error about the xsi:type not being bound to a specific element. I looked in the enterprise wsdl and I believe I found what the xsi type is.

 

The definition at the top of the enterpise.wsdl looks like this:

 

<definitions targetNamespace="urn:enterprise.soap.sforce.com" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:enterprise.soap.sforce.com" xmlns:fns="urn:fault.enterprise.soap.sforce.com" xmlns:ens="urn:sobject.enterprise.soap.sforce.com">

 

So the type is ens?

Here is the code after a successful login:

 

I am trying to create a new Contact using the salesforce api with the savon client using ruby.

 

 

client.create! do |s|

    s.namespace = 'urn:enterprise.soap.sforce.com'

    s.header = {'wsdl:SessionHeader' => {'wsdl:sessionId' => mysessionid'}}

    s.body = {"wsdl:sObjects" => {"FirstName" => 'Test', "LastName" => 'Tester'}, :attributes! => {"wsdl:sObjects" => {"xsi:type" => 'ens:Contact'}}}.to_soap_xml

end

 

 

Here is the full error:

 

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Client</faultcode><faultstring>The prefix &quot;xsi&quot; for attribute &quot;xsi:type&quot; associated with an element type &quot;wsdl:sObjects&quot; is not bound.</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>Savon::SOAPFault: (soapenv:Client) The prefix "xsi" for attribute "xsi:type" associated with an element type "wsdl:sObjects" is not bound.

I recently created a ruby script to login to salesforce and create some objects. It has worked for about a week and all of a sudden the same script will no longer login. It says that I have the wrong name, password, or security token or that I may be locked out.

 

To verify I have the correct security token, I reset it and put it in the script as [password][security token]. Still fails to login. 

 

I tried downloaded the wsdl again to see if the endpoint I need changed. It is still the same.

 

In case of being logged out, I checked and it says a the user will be locked out for 15 minutes. I went to lunch for an hour came back and still failed to login.

 

I don't know what could be going wrong, does anyone have advice to a solution?

 

I created a new contact with the code below. Got the successful response from the xml shown below. But, I logged into salesforce and do not see the contact I created. Is something wrong with the code? does it take a while for new candidates to appear?

 

Thanks.

 

client.create! do |s|

  s.namespace = 'urn:enterprise.soap.sforce.com'

  s.namespaces["xmlns:urn1"] = 'urn:sobject.enterprise.soap.sforce.com'

  s.namespaces["xmlns:xsi"] = 'http://www.w3.org/2001/XMLSchema-instance'

  s.header = {'xsi:SessionHeader' => {'xsi:sessionId' => 'session id'}}

  s.body = {"xsi:sObjects" => {"FirstName" => 'Test', "LastName" => 'Tester'}, :attributes! => {"xsi:sObjects" => {"xsi:type" => 'urn1:Contact'}}}.to_soap_xml

end

 

 

SOAP request: https://na2-api.salesforce.com/services/Soap/c/19.0/00D400000008UpO/0DF400000004Ge0

SOAPAction: create, Content-Type: text/xml;charset=UTF-8

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:wsdl="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><xsi:SessionHeader><xsi:sessionId>session id</xsi:sessionId></xsi:SessionHeader></env:Header><env:Body><wsdl:create><xsi:sObjects xsi:type="urn1:Contact"><LastName>Tester</LastName><FirstName>Test</FirstName></xsi:sObjects></wsdl:create></env:Body></env:Envelope>

SOAP response (status 200):

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com"><soapenv:Body><createResponse><result><id>0034000000fdcHQAAY</id><success>true</success></result></createResponse></soapenv:Body></soapenv:Envelope>

 => #<Savon::Response:0xb678bad4 @http=#<Net::HTTPOK 200 OK readbody=true>, @soap_fault_message=nil, @hash={:create_response=>{:result=>{:success=>true, :id=>"0034000000fdcHQAAY"}}}>

 

I am trying to create a new custom object. But even before I do that I am trying to make a new Contact just to verify I know how to create something.

 

I keep getting an error about the xsi:type not being bound to a specific element. I looked in the enterprise wsdl and I believe I found what the xsi type is.

 

The definition at the top of the enterpise.wsdl looks like this:

 

<definitions targetNamespace="urn:enterprise.soap.sforce.com" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:enterprise.soap.sforce.com" xmlns:fns="urn:fault.enterprise.soap.sforce.com" xmlns:ens="urn:sobject.enterprise.soap.sforce.com">

 

So the type is ens?