Submit form responses with Node.js
Learn how to send easily submit form responses from your apps, or server-side applications.
Prerequisites
To get the most out of this guide, you’ll need to:
- Create an API key
- Create a form
Install
Submit with Node.js
import { PokettoClient } from 'poketto-sdk';
const client = new PokettoClient({
apiKey: 'your-api-key'
});
await client.submitResponse(
'form-id',
[
{ field_id: 'name', value: 'John Doe' },
{ field_id: 'email', value: 'john@example.com' },
{ field_id: 'feedback', value: 'Great product!' }
],
{
name: 'John Doe',
email: 'john.doe@example.com'
}
);
Methods
submitResponse(
formId,
fieldResponses,
respondent?,
)
Submit a form response with manual data.
await client.submitResponse(
'form-123',
[
{ field_id: 'name', value: 'John Doe' },
{ field_id: 'email', value: 'john@example.com' }
],
{
name: 'John Doe',
email: 'john@example.com'
}
);
Submit a form response with auto-detected browser information.
await client.submitResponseWithBrowserInfo(
'form-123',
[{ field_id: 'feedback', value: 'Great service!' }],
{
email: 'user@example.com'
}
);
Error Handling
import { PokettoError } from 'poketto-sdk';
try {
await client.submitResponse('form-id', responses);
} catch (error) {
if (error instanceof PokettoError) {
console.error('Poketto Error:', {
message: error.message,
code: error.code,
statusCode: error.statusCode,
details: error.details
});
} else {
console.error('Unknown error:', error);
}
}