How to use Retrieve Poll trigger when all API calls require a session id from an inital login?
I’m a bit new to this and working with an API that requires a separate username/password login process in order to establish a session ID as a keytoken for use in authentication with all other API calls. Each session only lasts 60 minutes after the last API call.
I know I could use a scheduled trigger to automate the login process first, but my preference would be to only run the zap when a new record is found in the data I would like to poll.
Is this a common issue or something that is easily handled within the trigger fields that I’m not seeing? Thanks!
Page 1 / 1
What app API are you using?
Does the app offer Webhooks? (This would trigger the Zap each time there is a new record, rather than having to poll the app API.)
Hey @Troy Tessalone - I was attempting to use the Zapier Webhooks app to Retrieve Poll from a URL I don’t have the option to get the data sent to a Zapier webhook for use with “Catch hook” triggers.
Thanks for the article link - found the limitation here:
This trigger is one that only supports basic authentication - should you need to create your own polling triggers for APIs that offer advanced forms of authentication, you should create your own private application on the Zapier platform.
I guess it makes sense to dive into that and see what I can do. Thanks so much!
SO I got pretty far into the “session authentication” portion of building my own private app except for the returning of the session token.
// You can do any parsing you need for results here before returning them
return { 'sessionKey': results.sessionKey }; });
Here’s the response from the logs - you’ll see that the login is successful and the ‘SessionID’ is provided in the output but I have no clue how to parse the sessionID and get it into the ‘SessionKey’ using the default code above.
@ikbelkirasan - That worked great! Got the authentication piece set up and successfully tested.
Now onto the trigger - On step 1 “Configure API Request” I have the necessary headers, params, and body - also figured out how to parse the response content from another article:
// You can do any parsing you need for results here before returning them
return results.Rows; });
Then I go to the next step - Test your API request, and I’m getting a response that the SessionID is missing.
Oddly, looking at the ‘HTTP’ logs, I see a successful authentication step and another step showing a successful response with the array I’m looking for. Why would I be getting this missing session ID error if I’m seeing a valid response in the logs?
@dstepchew That’s because bundle.authData.SessionID doesn’t exist. The session ID is actually stored in bundle.authData.sessionKey.
@ikbelkirasan OK that worked. Now I’m up against the “Got a result missing the ‘id’ property” error. Looking at this response I noticed that the user was able to establish the id for result using the values provided in each result, but my issue is that the column definitions are sent in a separate array. I tried to repurpose the same method used in the login help provided above but to no avail - getting error ‘cannot ready property of ‘number’ of undefined.’