Initialization

To initialize the SDK,create an instance of NfigClient with your API key. This connects your application to Nfig and allows interaction with the platform. During initialization, you can enable debug mode to assist with troubleshooting.

import { NfigClient } from 'nfig-sdk';
const nfig = new NfigClient({
  apiKey: "YOUR_API_KEY",
  debug: true          
});

ParameterTypeDescription
apiKeystringrequired. Your API key from the Nfig Portal.
debugbooleanoptional. Enables debug logging if set to true.

Session Management

Note: A managed session in Nfig is active for 15 minutes.

(async ()=>{
const nfig = new NfigClient({
debug:true
});
const { previewUrl } = await nfig.createSession()
try{
await nfig.act('Go to google.com')
}
catch(error){
await nfig.endSession()
}
}())

Creating a session

Use the createSession method to initialize a session.

Usage Example:

(async () => {
  const nfig = new NfigClient({ apiKey: "YOUR_API_KEY", });
  const session = await nfig.createSession();
  console.log(session.previewUrl);
})();

Ending a Session

Use the endSession method to end a session.

await nfig.endSession();

EndSessionResponse

FieldTypeDescription
successbooleanIndicates if the session was ended successfully.
messagestringInformational message about the session termination.

Note: Ending a session is a necessary action to avoid unexpected billing.

SDK Methods

Act method

act method performs specific actions on a webpage.

Basic usage

const response = await nfig.act("Go to google.com");

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.

Ask method

ask method helps you retrieve information from a page in a structured way using Zod schemas.

const response = await nfig.ask("Extract the pricing informations", {
  schema: priceSchema, 
});

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.
optionsObjectoptional. Additional options to customize the ask action.

AskOptions

PropertyTypeDescription
schemaZodSchemaoptional. Zod schema to validate the extracted data against.

Initialization

To initialize the SDK,create an instance of NfigClient with your API key. This connects your application to Nfig and allows interaction with the platform. During initialization, you can enable debug mode to assist with troubleshooting.

import { NfigClient } from 'nfig-sdk';
const nfig = new NfigClient({
  apiKey: "YOUR_API_KEY",
  debug: true          
});

ParameterTypeDescription
apiKeystringrequired. Your API key from the Nfig Portal.
debugbooleanoptional. Enables debug logging if set to true.

Session Management

Note: A managed session in Nfig is active for 15 minutes.

(async ()=>{
const nfig = new NfigClient({
debug:true
});
const { previewUrl } = await nfig.createSession()
try{
await nfig.act('Go to google.com')
}
catch(error){
await nfig.endSession()
}
}())

Creating a session

Use the createSession method to initialize a session.

Usage Example:

(async () => {
  const nfig = new NfigClient({ apiKey: "YOUR_API_KEY", });
  const session = await nfig.createSession();
  console.log(session.previewUrl);
})();

Ending a Session

Use the endSession method to end a session.

await nfig.endSession();

EndSessionResponse

FieldTypeDescription
successbooleanIndicates if the session was ended successfully.
messagestringInformational message about the session termination.

Note: Ending a session is a necessary action to avoid unexpected billing.

SDK Methods

Act method

act method performs specific actions on a webpage.

Basic usage

const response = await nfig.act("Go to google.com");

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.

Ask method

ask method helps you retrieve information from a page in a structured way using Zod schemas.

const response = await nfig.ask("Extract the pricing informations", {
  schema: priceSchema, 
});

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.
optionsObjectoptional. Additional options to customize the ask action.

AskOptions

PropertyTypeDescription
schemaZodSchemaoptional. Zod schema to validate the extracted data against.