How can I use pagination in an Import Data Source Rest Step
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 08:34 AM
I'm trying to build an Import integration that retrieves node data from a REST api. I can make the API call and get data, but I need to paginate the calls so I don't crash the platform I'm retrieving from with a REST call that tried to get everything at once.
My Data Source type is REST and the format is Parse By Script. The data the API returns is JSON, but it comes back as an array and Servicenow doesn't like that, so I have to parse it with my own script.
When I enable pagination it does the requests I expect it to do, but then I can't tell the step to stop doing additional requests. When the platform I'm integrating with gets a request for a page with no data, it will return an empty array and a 200 status code. This seems to prompt Servicenow to just keep requesting additional pages.
Is there a way in the script step to tell Servicenow that there's no more data and to please stop requesting pages?
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 09:03 AM
If the problem is that the platform you're integrating with doesn't return an error status code when a request has no data, you could create a scripted REST service and scripted REST resource on your instance that makes the call to the platform and either returns the full response with a 200 status code (when there is data) or an empty response with a 400 Bad Request error code (when there is none). Then your REST data source calls your REST API instead of the platform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 09:06 AM
I had wanted some time ago to create a scripted rest service for a different reason, but I couldn't find a way to create that service on my instance in a way that was allowed to do the outbound HTTP request. I kept getting errors that the Glide HTTP object wasn't allowed in my context. If there's a way to do it I'll certainly consider doing that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 09:23 AM
Can you share an example of the full REST URL of an outbound call to the platform requesting paginated records (with the server and private details removed)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 09:29 AM
