Test
The test method verifies if the authentication credentials are valid by making a simple API request to the external service.
This method is crucial for validating connections and providing immediate feedback to users during the connection setup process.
Implementation
Supported implementation types
JavaScript Implementation
The test method is typically implemented in JavaScript:
# Connector definition: Verify credentials by fetching user profile and checking account status
test:
type: javascript
code: |
export default async function test({ apiClient }) {
try {
const responseData = await apiClient.get('/user/profile')
if (responseData.accountStatus === 'active') {
return true
}
return false
} catch (error) {
console.error('Authentication test failed:', error)
return false
}
}REST API Mapping Implementation
The test method can also be implemented by defining an API request and response mapping:
# Connector definition: Verify credentials by checking if current user endpoint returns an id
test:
type: rest-api-mapping
mapping:
path: /current-user
method: get
responseMapping:
$eval:
$var: $.response.id
isNotEmpty: trueInput Context
The test method receives a context object with these properties:
| Property | Description |
|---|---|
connectorParameters | Parameters configured for the connector in your workspace. |
connectionInput | Parameters provided by the user during connection setup. |
Return Value
The test method should return:
trueor truthy value when the test succeedsfalseor falsy value when the test fails- Or throw an error with a descriptive message for more detailed failure information
Best Practices
Endpoint Selection
Choose an endpoint for testing that:
- Is Lightweight: Uses minimal API resources and quota
- Requires Authentication: Actually tests credentials are valid
- Has Minimal Permissions: Works even with restricted access
- Is Stable: Unlikely to change or be deprecated
- Returns Quickly: Provides fast feedback
Common test endpoints include:
- User profile or account information
- API status endpoints
- Organization or workspace information
- Simple list endpoints with limits (e.g., first 1-2 items)
Updated 2 days ago
