from typing import Any, Optional import dlt from dlt.common.pendulum import pendulum from dlt.sources.rest_api import ( RESTAPIConfig, check_connection, rest_api_resources, rest_api_source, ) from dlt.sources.helpers.rest_client.paginators import PageNumberPaginator dlt.config["runtime.log_level"] = "DEBUG" @dlt.source(name="github") def netsuite_source(access_token: Optional[str] = dlt.secrets.value) -> Any: config: RESTAPIConfig = { "client": { "base_url": "https://7429932.app.netsuite.com/app/site/hosting", # we add an auth config if the auth token is present "headers": ( {"Authorization": f"NLAuth nlauth_account=7429932,nlauth_email=yanice.zhang@pingcap.com,nlauth_signature=pcpczy&102501,nlauth_role=1002"} ), "paginator": PageNumberPaginator( total_path=None, maximum_page=13 ) }, # The default configuration for all resources and their endpoints "resource_defaults": { "write_disposition": "replace", "endpoint": { "params": { "per_page": 200, }, }, }, "resources": [ { "name": "rates_old", "endpoint": { "path": "scriptlet.nl?script=561&deploy=1", # Query parameters for the endpoint # "params": { # "sort": "updated", # "direction": "desc", # "state": "open", # # Define `since` as a special parameter # # to incrementally load data from the API. # # This works by getting the updated_at value # # from the previous response data and using this value # # for the `since` query parameter in the next request. # "since": { # "type": "incremental", # "cursor_path": "updated_at", # "initial_value": pendulum.today().subtract(days=60).to_iso8601_string(), # }, # }, }, }, { "name": "transactions", "endpoint": { "path": "scriptlet.nl?script=457&deploy=1", # Query parameters for the endpoint "params": { "startdate": "03/26/2025", "enddate": "03/27/2025" # "sort": "updated", # "direction": "desc", # "state": "open", # # Define `since` as a special parameter # # to incrementally load data from the API. # # This works by getting the updated_at value # # from the previous response data and using this value # # for the `since` query parameter in the next request. # "since": { # "type": "incremental", # "cursor_path": "updated_at", # "initial_value": pendulum.today().subtract(days=60).to_iso8601_string(), # }, }, }, }, { "name": "subsidiaries", "endpoint": { "path": "scriptlet.nl?script=456&deploy=1", } } ], } yield from rest_api_resources(config) def load_netsuite() -> None: pipeline = dlt.pipeline( pipeline_name="rest_api_github", destination='bigquery', dataset_name="netsuite", ) load_info = pipeline.run(netsuite_source()) print(load_info) # noqa: T201 if __name__ == "__main__": load_netsuite()