---
title: "retrieveCredentials(forBorderAgent:completion:)"
framework: threadnetwork
role: symbol
role_heading: Instance Method
path: "threadnetwork/thclient/retrievecredentials(forborderagent:completion:)"
---

# retrieveCredentials(forBorderAgent:completion:)

Requests Thread credentials for a Border Agent.

## Declaration

```swift
func retrieveCredentials(forBorderAgent borderAgentID: Data, completion: @escaping @Sendable (THCredentials?, (any Error)?) -> Void)
```

```swift
func credentials(forBorderAgentID borderAgentID: Data) async throws -> THCredentials
```

## Parameters

- `borderAgentID`: The identifer of a Thread network Border Agent.
- `completion`: The completion handler the framework calls when the credentials become available.

## Mentioned in

Managing Thread network credentials

## Discussion

Discussion note: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func credentials(forBorderAgentID borderAgentID: Data) async throws -> THCredentials For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously. The framework identifies the developer by the team ID. When calling this method, you receive credentials for your team ID only. Call the method as follows: func obtainCredentials(borderAgentID: Data) async -> (cred: THCredentials? ,err: Error? ) {     let client = THClient()     var credential: THCredentials?     var err:Error?     do {         credential = try await client.credentials(forBorderAgentID: borderAgentID as Data)     } catch {         err = error     }     return (credential, err) }

## See Also

### Retrieving Credentials

- [isPreferredNetworkAvailable(completion:)](threadnetwork/thclient/ispreferrednetworkavailable(completion:).md)
- [checkPreferredNetwork(forActiveOperationalDataset:completion:)](threadnetwork/thclient/checkpreferrednetwork(foractiveoperationaldataset:completion:).md)
- [retrieveCredentials(forExtendedPANID:completion:)](threadnetwork/thclient/retrievecredentials(forextendedpanid:completion:).md)
- [retrieveAllCredentials(_:)](threadnetwork/thclient/retrieveallcredentials(_:).md)
- [retrievePreferredCredentials(_:)](threadnetwork/thclient/retrievepreferredcredentials(_:).md)
- [retrieveAllActiveCredentials(_:)](threadnetwork/thclient/retrieveallactivecredentials(_:).md)
