yatish27 / salesforce_bulk_api

A Ruby client for Salesforce's bulk API
MIT License
80 stars 97 forks source link

Using restforce Oauth login, got Invalid Session Id #33

Open bfagundez opened 10 years ago

bfagundez commented 10 years ago

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 commented 10 years ago

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

bfagundez commented 10 years ago

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 commented 10 years ago

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

yatish27 commented 10 years ago

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 notifications@github.com 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 commented 9 years ago

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 commented 9 years ago

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 notifications@github.com 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 https://github.com/yatish27/salesforce_bulk_api/issues/33#issuecomment-66484087 .

Yats

bfagundez commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

@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 commented 9 years ago

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

cvengros commented 9 years ago

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