Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using restforce Oauth login, got Invalid Session Id #33

Open
bfagundez opened this issue Nov 21, 2014 · 11 comments
Open

Using restforce Oauth login, got Invalid Session Id #33

bfagundez opened this issue Nov 21, 2014 · 11 comments

Comments

@bfagundez
Copy link

this is the response when a bulk job is submitted:

=> {"xmlns"=>"http://www.force.com/2009/06/asyncapi/dataload", "exceptionCode"=>["InvalidSessionId"], "exceptionMessage"=>["Invalid session id"]}

Restforce methods work, so login procedure may be ok.

force_client = Restforce.new :oauth_token => token,
        :refresh_token => refresh__token,
        :instance_url  => instance_url,
        :api_version   => "31.0",
        :client_id     => Rails.application.config.salesforce_app_id,
        :client_secret => Rails.application.config.salesforce_app_secret

    #instantiate salesforce bulk api gem
    salesforce_bulk = SalesforceBulkApi::Api.new(force_client)
    # here it fails!
    result = salesforce_bulk.create("Houses__c", houses_collection)
@yatish27
Copy link
Owner

Is the token Valid? does the account allow Bulk API ?
@iDiogenes @jthibeaux

@bfagundez
Copy link
Author

the token seems to be valid, If I query using force_client (Restforce instance) it works.
Only fails with bulk.
Where is bulk api enabled/disabled? is it on the connected app or the logged in user profile?
(thanks for the quick response, that was awesome)

@bfagundez
Copy link
Author

Took a look around and can't see any limitations, the account is from an administrator on a dev org.
Can do anything.

@yatish27
Copy link
Owner

Let me check it out other collaborators work on sale force actively hence they can also help

On Nov 21, 2014, at 4:38 PM, Bruno Fagundez [email protected] wrote:

Took a look around and can't see any limitations, the account is form an administrator on a dev org.
Can do anything.


Reply to this email directly or view it on GitHub.

@mezza
Copy link

mezza commented Dec 10, 2014

I get the same issue. With Restforce, the authentication middleware seems to automatically handle stale OAUTH tokens, but the salesforce_bulk_api connection fails to create a bulk job with an invalid session id.

If I reset the user's session, forcing them to login to Salesforce Oauth again, then the bulk job creation works fine.

@yatish27
Copy link
Owner

I don't have an active salesforce account so need to look into it. Any more
details on this issue will be helpful

On Wed, Dec 10, 2014 at 11:57 AM, Merul Patel [email protected]
wrote:

I get the same issue. With Restforce, the authentication middleware seems
to automatically handle stale OAUTH tokens, but the salesforce_bulk_api
connection fails to create a bulk job with an invalid session id.

If I reset the user's session, forcing them to login to Salesforce Oauth
again, then the bulk job creation works fine.

Reply to this email directly or view it on GitHub
#33 (comment)
.

Yats

@bfagundez
Copy link
Author

DK if helps but here is my code:

    #instantiate force client with restforce
    force_client = Restforce.new :oauth_token => <token>,
        :refresh_token => <rfresh_token>,
        :instance_url  => <instance_url>,
        :api_version   => "31.0",
        :client_id     => Rails.application.config.salesforce_app_id,
        :client_secret => Rails.application.config.salesforce_app_secret

    #instantiate salesforce bulk api
    salesforce_bulk = SalesforceBulkApi::Api.new(force_client)
    field_responses = Array.new

    fr.form_field_responses.each { |formfieldresp|
        form_field_resp = Hash["Content_Text__c" => formfieldresp.response_value,
          "Form_Response__c" => sf_form_response,
           "Field__c" => formfieldresp.field_sf_id ]
        field_responses.push(form_field_resp)
    }

    # boom
    result = salesforce_bulk.create("HarvestFeedback__Field_Response__c", field_responses)

@lgrig
Copy link

lgrig commented Dec 21, 2014

@bfagundez - potentially related, performing any query with the Restforce client before using it to create the bulk_api client results in a successful bulk run for me. Without the initial query, no good. The Restforce client doesn't seem to hold a session_id until it does something (i.e. a query).

Example - this works in my job:
client.query("SELECT Id FROM Lead LIMIT 1")
bulk_client = SalesforceBulkApi::Api.new(client)
...

@bfagundez
Copy link
Author

@lgrig thanks for that hint, it does work well if a query is issued before instantiating the bulk api.
Obviously is not the best solution being querying random objects to get the bulk api to work, but it looks like this is on restforce court.
thanks again.

@yatish27
Copy link
Owner

@lgrig @bfagundez Let me try to work on this for the next version. If anyone has a PR for this do send it

@cvengros
Copy link

I had this issue as well, did a few changes so that the requests are done through the restforce client, not through http: cvengros@63b866a
.. however not sure if this still works with Databasedotcom client. Not ready for PR, however someone might get some inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants