I am building an app that will work with Plaid. Plaid provides a nice little LinkKit that I need to use to grab my link_token
. I provide that link_token
to authenticate to a bank. I have written a request using Alamofire to send the .post
to get the new link_token
when someone would want to add another account. My issue is when I decode the JSON to a struct that I have built I cant seem to use that stored link_token
value.
Code to retrieve link_token
let parameters = PlaidAPIKeys(client_id: K.plaidCreds.client_id,
secret: K.plaidCreds.secret,
client_name: K.plaidCreds.client_name,
language: K.plaidCreds.language,
country_codes: [K.plaidCreds.country_codes],
user: [K.plaidCreds.client_user_id: K.plaidCreds.unique_user_id],
products: [K.plaidCreds.products])
func getLinkToken() {
let linkTokenRequest = AF.request(K.plaidCreds.plaidLinkTokenURL,
method: .post,
parameters: parameters,
encoder: JSONParameterEncoder.default).responseDecodable(of: GeneratedLinkToken.self) { response in
print(response)
}
}
Struct I have built:
struct GeneratedLinkToken: Decodable {
let expiration: String
let linkToken: String
let requestID: String
enum CodingKeys: String, CodingKey {
case expiration = "expiration"
case linkToken = "link_token"
case requestID = "request_id"
}
}
I have tested by calling the function getLinkToken()
when pressing my add account or dummy button, I do get the data back that I am needing. Why wouldnt I be able to access GeneratedLinkToken.linkToken
directly after the request?