0

I am attempting to use a connected app to upload a lot of data to our Salesforce instance using our API but am running into an issue with not receiving an access token every time I request one.

In our external system, we have about 15,000 Students with a bunch of data we are trying to upload into Salesforce. Each student takes 3 API requests to upload: one to create/update the student, one to create/update their course enrollments, and one to create/update data from a game they play. To do this, for each student I retrieve the access token via services/oauth2/token and then use that access token to make the next three calls.

When I kick this upload process off, it it working just fine, however, when finished I check my logs and notice that 1 or 2 thousand times it doesn't work with the error:

RESPONSE CODE: 400
RESPONSE ERROR: Bad Request
RESPONSE DATA: {"error":"invalid_grant","error_description":"authentication failure"}

I checked the construction of the request and it all is exactly the same as when it works. After X amount of requests, does this endpoint just reject the request?

0

You are limited to one login per second (3600 calls per hour). You should cache the token and continue to use it until you're done. Also, each login call counts towards your API limit. Also, concurrent login calls may invalidate earlier sessions. You're limited to five sessions per app per user.

3
  • So I was going to cache the token but then saw by default that the token expires after 15 minutes by default. I guess I'll just have to let it fail and then get a new one after a call fails and retry that call..
    – BlondeSwan
    May 18 '20 at 23:21
  • @BlondeSwan No, it times out after 15 minutes. If you're making calls back to back, it shouldn't expire until you're done. Also, you can go in to the Connected App and bump it up as high as 24 hours. You will need to watch out for 403 (Forbidden) errors and reauthenticate then anyways, since that's the normal flow, but logging in for every request is wasteful.
    – sfdcfox
    May 18 '20 at 23:24
  • Ah, okay the 15 minutes makes more sense now.
    – BlondeSwan
    May 18 '20 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.