4. Data Debits
PDA Data I/O: Reading (Data Debits)
PDA Data Debits
are the cornerstone of consented data exchange. It is the only way data can be retrieved from the PDA by anyone other than the owner and it enforces a strictly-defined format defining the specific data requested for the user to review and approve. Read more on the Data Debit API.
Fetch Data Debits
You can fetch the available Data Debits
by using the next function:
userToken
is the user's token to authenticate with thePDA
.userDomain
is the user'sPDA address
needed to form the url to fetch the availableData Debits
.succesfulCallBack
is a callback. This is called when the request is successful with a type of@escaping (([DataDebitObject], String?) -> Void)
. The first parameter is an array ofDataDebitObject
. This is the structure ofData Debits
. More on that in the next section.The second parameter is an optional
String
, the refreshed user token that thePDA
returns.failCallBack
is a callback that is called when the request has failed. The type of the function is@escaping ((Data PlugError) -> Void)
.Data PlugError
is a custom object describing the errors that have occurred during the querying of the
Data Plugs
.
A successful response will have statusCode
200 and look like this:
dataDebitKey
is the data debit key, defined when creating theData Debit
. It's unique across thePDA
.dateCreated
is the date that thisData Debit
was created. The date is inISO
format asString
.permissions
is thepermissions
info for thisData Debit
. WhatURLs
it has accessed, from which date to which date, etc.:dateCreated
is the date that thisData Bundle
was created. The date is inISO
format asString
.purpose
is a short description for theData Bundle
explaining its purpose. Optionalstart
is the start date that thisData Bundle
has become active. The date is inISO
format. Optionalend
is the start date that thisData Bundle
will surpass the assigned duration stated inperiod
. The date is inISO
format. OptionalcancelAtPeriodEnd
is a flag indicating if the permissions will auto cancel when theData Debit
will endtermsUrl
is aURL
to show the user the terms and conditions for thisData Bundle
period
is the duration that theData Bundle
can be active. Value in seconds.active
indicates if theData Bundle
is activeaccepted
indicated if theData Bundle
has been acceptedbundle
is the part where the permissions are defined. Like whatendpoints
thisData Debit
will have access to, which fields from thatendpoint
, aname
, under what circumstances etc.:name
is name of thebundle
. This has to be unique.bundle
is aDictionary
of typeDictionary<String, DataOfferRequiredDataDefinitionBundleKeyV2>
, it allows definition of multiple differentendpoints
by giving a different name. This means that you can combine multiple and differentendpoints
each with its own requirements:endpoints
is an array ofDataOfferRequiredDataDefinitionBundleKeyEndpointsV2
containing thePDA URLs
to include, a desired `mapping` or `filtering` for the fields:endpoint
the actualendpoint
that you would like access to, for examplerumpel/profile
mapping
is the selected fields from thisendpoint
that you would like to have in theData Debit
filters
lets you filter a field by some requirements. For example, you can define something likeage
between 18 and 35. Optional:field
is the field that you would like to apply filtering totransformation
is the transformation type to be done on the field. There are 4 different options: Optionalidentity
keep the value as-is, effect is the same as if transformation was not defineddatetimeExtract
withpart
– extract part of a date from an ISO 8601 formatted date fieldtimestampExtract
withpart
– extract part of a date from a UNIX timestamp date fieldsearchable
convert the field to searchable text. Must be used together with the find operator below 3.operator
is the type of the filtering. There are 4 different types with different structure each. You can read more into checking outHATOperator
class inHatForiOS
here. Optional:find
allows you to search a particularString
, field name:search
. Also, you can nest moreoperators
, field name:operator
contains
allows you to search if a particular substring is contained into aString
, field name:value
of typeBool
between
allows you to search if anInt
is between 2 values namedupper
andlower
in
together withvalue
field set to check if field is in (is contained by)value
links
eachendpoint
can contain otherendpoint
objects. Optional
orderBy
lets you define the field to order the data. Optionalordering
lets you define theordering
of the data.ascending
ordescending
. Optionallimit
is anInt
which lets you define how many data points you like from thisendpoint
. Optional
conditions
checkbundle
for the structure. The purpose is that theData Bundle
can have some conditions, that have to be fulfilled first, attached to it in order to becomeactive
. Optional
requestClientName
is the name of the client that created thisData Debit
requestClientUrl
is theURL
to the website of the clientrequestClientLogoUrl
is aURL
for the logo of the clientrequestDescription
is a description for theData Debit
. OptionalrequestApplicationId
If theData Debit
is tied to anApplication
this will be the application id. Otherwise it's nil. Optionalactive
indicates if theData Debit
is activeaccepted
indicates if theData Debit
has been acceptedstart
is the date that thisData Debit
has started. The date is inISO
format asString
. Optionalend
is the date that thisData Debit
will end. The date is inISO
format asString
. OptionalpermissionsActive
Latest activepermissions
. Look atpermissions
. OptionalpermissionsLatest
Latestpermissions
. Look atpermissions
.
A request that has failed will look like this:
error
is the error that has occurredmessage
is a more descriptive message about theerror
that has occurred
Create Data Debit
You can also create a Data Debit
by using the function below:
endpoint
is theHAT endpoint
you would like access to.DataOfferRequiredDataDefinitionBundleKeyEndpointsV2
also allows you to setup mapping and filtering if you wish. The minimum requirement is to specify the endpoint you want to use.bundle
is a grouping of differentendpoints
under one category. You can define one category, with thename
parameter, but you can have multipleendpoints
in thebundle
section. Note thatname
has to be unique.dataDebitKey
is a key to the specificData debit
. This has to be unique.purpose
is a small description of the purpose for thisData Debit
start
is the start date that thisData Debit
can become available. The date is inISO
format.period
is the duration that theData Debit
will be active in secondstermsUrl
is theURL
for the terms and conditions for thisData Debit
cancelAtPeriodEnd
is a bool flag for if theData Debit
should be cancelled with theperiod
passesrequestClientName
is the name of the client that created thisData Debit
requestClientUrl
is theURL
to the website of the clientrequestClientLogoUrl
is aURL
for the logo of the clientbundle
is the description of what endpoints we want to have access to
A successful response will have statusCode
201 and look like this:
For an explanation of what the above structure means, read here.
A failed request will look like this:
error
is the error that has occurredmessage
is a more descriptive message about theerror
that has occurred
Approve Data Debits
Not all apps can directly approve Data Debits
. This has to do with the permissions of the apps. Currently, only HAT App
and web Rumpel
can approve Data Debits
. Due to the restrictions this guide will explain how to use the generic way of doing it, that will work on all apps. To approve a Data Debit
you have to open the following URL in Safari:
hatAddress
is the (fully qualified domain) address of the PDA, e.g.postman.hubat.net
dataDebitID
is the data debit id that you want to approveappScheme
is the URL where the user should be sent to after completing authentication. Optional. For aniOS
application that would probably be:\(applicationName)://success
and has to be added in theinfo.plist
file of the project in Xcode as a known URL.You can read more here.
dataDebitHost
is a string after the://
part in the app url Scheme. For exampledataswift-sandbox://dataDebitHost
. With thedataswift-sandbox://
iOS
will launch your app. With thedataDebitHost
you will know that thisURL
is specifically for theData Debits
.
The process is the same as when logging the user in. Safari will open, user will have to complete their password, and then one of the 2 redirect URL
will be called, depending if the request was successful or has failed for some reason. The app should know how to handle both scenarios. If you aren't sure how to do it you can read here for how to redirect user to HAT login.
Getting Data Debit values
You can fetch the values of a specific Data Debit
by using the next function:
dataDebitKey
is the data debit key that we want the values from.userToken
is the user's token to authenticate with thePDA
.userDomain
is the user'sPDA address
used to form the url to fetch the values of theData Debit
.succesfulCallBack
is a callback function that is called when the request is successful, with a type of@escaping ((DataDebitValuesObject, String?) -> Void)
.This is the structure of
Data Debit Values
. More on that in the next section. The second parameter is an optionalString
, the refreshed user token that thePDA
returns.failCallBack
is a callback that is called when the request has failed. The type of the function is@escaping ((Data PlugError, String?) -> Void)
.Data PlugError
is a custom object describing the errors that have occurred during the querying of the
Data Plugs
. The second parameter is the dataDebitKey.
A successful response will have statusCode
200 and look like this:
Inside the bundle
there are 2 different values: profile
and notables
. Those 2 values are Arrays
that contain the actual data for each endpoint
specified when this Data Debit
was created. In this example the 2 structures are the profile
and notables
.
A request that has failed will look like this:
error
is the error that has occurredmessage
is a more descriptive message about theerror
that has occurred
Last updated