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
MimiranMimiran 

Code to enable API token for Professional Edition (so don't get API_DISABLED_FOR_ORG)

Hi, after our security review I was given an API token to enable Professional edition API support.  Let's say that token is "My.Secret.Token".  I put in code to use that token but it doesn't work. :(  Salesforce support says the token is active so it must be my code.

 

First, is it possible to mix the Partner API and Enterprise API?  I've been using the Enterprise API throughout our code as it's much simpler, but this one part requires the Partner API.  It compiles & runs fine but I wonder if this is why it's not working.  Do I now have to convert the rest of my code to the Partner API?

 

Second, is the below code correct?

 

// Everything uses Enterprise API except CallOptions (which only exists in Partner API)

import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.partner.CallOptions;

 

final String TOKEN_FOR_PROFESSIONAL_EDITION = "My.Secret.Token";

SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
CallOptions co = new CallOptions();
co.setClient(TOKEN_FOR_PROFESSIONAL_EDITION);
binding.setHeader("SforceService", "CallOptions", co);

LoginResult lr = binding.login(user, pass); // Professional Ed's throw exception!

 

 Thanks for your help!

 

Best Answer chosen by Admin (Salesforce Developers) 
MimiranMimiran

I figured it out.  I'd taken code from some official example which cleared the binding headers somewhere.  Clearly we shouldn't clear the headers after we set the token in the header. ;)  Silly code bug...

 

For those that are interested:

 

    YES, you can mix the Partner API & Enterprise API.  My code above now works fine.

 

    NO, you do not have to set the token every API call as Simon claimed.  Just set it once in the binding and continue to use that binding without clearing the headers.

 

    YES, my string "SforceService" is correct.   It's not wrong as Simon claimed.

 

All Answers

SuperfellSuperfell
Your token is required on every single api call.
MimiranMimiran
Ok, but that won't fix the problem above, as I only run a single login call...
SuperfellSuperfell
Your entire integration is one call to login ?
SuperfellSuperfell
Remember to use the right namespace when you setup the header, SforceService, is not correct. (this may or may not be the problem). 
MimiranMimiran

I figured it out.  I'd taken code from some official example which cleared the binding headers somewhere.  Clearly we shouldn't clear the headers after we set the token in the header. ;)  Silly code bug...

 

For those that are interested:

 

    YES, you can mix the Partner API & Enterprise API.  My code above now works fine.

 

    NO, you do not have to set the token every API call as Simon claimed.  Just set it once in the binding and continue to use that binding without clearing the headers.

 

    YES, my string "SforceService" is correct.   It's not wrong as Simon claimed.

 

This was selected as the best answer
SuperfellSuperfell

I said you need to send the header on every api call. depending on your soap stack, that may map to creating it once per binding object, or may not.

 

the namespace is wrong, check the WSDL, don't confuse it works with its correct. 

GoForceGoGoForceGo

If you certify your App and get a token, is Data Loader available for Professional Edition?

 

If not, what would be the alternative for loading data in batch mode?