def main(): openbanking_endpoint = "https://developer-api-sandbox.dnb.no" aws_signing_v4 = AwsSigningV4( aws_access_key_id=client_id, aws_secret_access_key=client_secret, aws_host="developer-api-sandbox.dnb.no", aws_region="eu-west-1", aws_service="execute-api", ) request_handler = RequestHandler(endpoint=openbanking_endpoint, aws_signing_v4=aws_signing_v4, api_key=api_key) api_token_params = {"customerId": '{"type":"SSN", "value":"29105573083"}'} api_token_path = "/token" api_token_response = request_handler.get_request(path=api_token_path, params=api_token_params) api_token = api_token_response.json()["tokenInfo"][0]["jwtToken"] print("api_token: " + api_token)
class Dnb_res_handler(object): def __init__(self, client_id, client_secret, api_key, endpoint): self.endpoint = endpoint self.aws_signing_v4 = AwsSigningV4( aws_access_key_id=client_id, aws_secret_access_key=client_secret, aws_host="developer-api-sandbox.dnb.no", aws_region="eu-west-1", aws_service="execute-api", ) self.request_handler = RequestHandler( endpoint=self.endpoint, aws_signing_v4=self.aws_signing_v4, api_key=api_key) def get_customers(self): all_customer_path = "/testCustomers" all_customer_res = self.request_handler.get_request( path=all_customer_path, params={}) all_customers = all_customer_res.json() return all_customers["customers"] def get_customer_token(self, ssn): value = "{\"type\":\"SSN\", \"value\":\"%s\"}" % ssn token_params = {"customerId": value} token_path = "/token" customer_token_res = self.request_handler.get_request( path=token_path, params=token_params) token = customer_token_res.json() return token["tokenInfo"][0] def get_accounts(self, token): all_accounts_path = "/accounts" all_accounts_res = self.request_handler.get_request( path=all_accounts_path, params={}, api_token=token) all_accounts = all_accounts_res.json() return all_accounts["accounts"] def get_transactions(self, accountNumber, token, from_date, to_date): transactions_path = "/transactions/%s" % accountNumber time_interval = {"fromDate": from_date, "toDate": to_date} # print(time_interval) all_transactions_res = self.request_handler.get_request( path=transactions_path, params=time_interval, api_token=token) # print(all_transactions_res) all_transactions = all_transactions_res.json()["transactions"] out_going = [] for trans in all_transactions: trans.pop("externalReference") trans.pop("textLines") trans.pop("details") trans.pop("bookingDate") trans.pop("valueDate") trans.pop("accountNumber") trans.pop("transactionDate") trans.pop("transactionId") for trans in all_transactions: if (trans["amount"] < 0): out_going.append(trans) return out_going