# Sinch Node.js SDK for Numbers

The Sinch Node.js SDK allows you to quickly interact with the  from inside your Node.js applications. When using the Node.js SDK, the code representing requests and queries sent to and responses received from the  are structured similarly to those that are sent and received using the .

The fastest way to get started with the SDK is to check out our [getting started](/docs/number-lookup-api-v2/getting-started/) guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK.

## Syntax

Note:
This guide describes the syntactical structure of the Node.js SDK for the Number Lookup API, including any differences that may exist between the API itself and the SDK. For a full reference on Number Lookup API calls and responses, see the [Number Lookup API Reference](/docs/number-lookup-api-v2/api-reference/number-lookup-v2).

This code sample is an example of how to use the Node.js SDK to lookup a specified number. We've also provided an example that accomplishes the same task using the REST API.

SDK
NumberLookupSample.js
```javascript NumberLookupSample.js
// This code looks up a specified number. 
/**
 * Class to lookup a number through the NumberLookup API using the Sinch Node.js SDK.
 */
export class NumberLookupSample {
  /**
   * @param { import('@sinch/sdk-core').NumberLookupService } numberLookupService - the NumberLookupService instance from the Sinch SDK containing the API methods.
   */
  constructor(numberLookupService) {
    this.numberLookupService = numberLookupService;
  }

  async start() {
    // The phone number to lookup in E.164 format
    const phoneNumber = 'PHONE_NUMBER_TO_LOOKUP';

    const response = await this.numberLookupService.lookup({
      numberLookupRequestBody: {
        number: phoneNumber,
      },
    });

    console.log('Response:', response);
  }
}
```

REST API
```java

package app;

import java.net.*;
import java.net.http.*;
import java.util.*;

public class App {
  private static final String key = "";
  private static final String secret = "";
  private static final String projectId = "";
  private static final String number = "";

  
  public static void main(String[] args) throws Exception {
    var httpClient = HttpClient.newBuilder().build();

    var payload = String.join("\n"
      , "{"
      , " \"number\": \"" + number + "\","
      , "}"
    );

    var host = "https://lookup.api.sinch.com/v2/projects";
    var pathname = "/" + projectId + "/lookups";
    var request = HttpRequest.newBuilder()
      .POST(HttpRequest.BodyPublishers.ofString(payload))
      .uri(URI.create(host + pathname ))
      .header("Content-Type", "application/json")
      .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((key + ":" + secret).getBytes()))
      .build();

    var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

    System.out.println(response.body());
  }
}
```

This example highlights the following required to successfully make a Number Lookup API call using the Sinch Node.js SDK:

- [Client initialization](#client)
- [Numbers domain access](#numbers-domain)
- [Endpoint usage](#endpoint-categories)
- [Field population](#request-and-query-parameters)


## Client

When using the Sinch Node.js SDK, you initialize communication with the Sinch backend by initializing the Node.js SDK's main client class. This client allows you to access the the functionality of the Sinch Node.js SDK.

### Initialization

To start using the SDK, you need to initialize the main client class with your credentials from your Sinch [dashboard](https://dashboard.sinch.com/dashboard).

```javascript
const {SinchClient} = require('@sinch/sdk-core');

const sinchClient = new SinchClient({
    projectId: "YOUR_project_id",
    keyId: "YOUR_access_key",
    keySecret: "YOUR_access_secret"
});
```

Note
For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:

**`.env` File**

```shell
PROJECTID="YOUR_project_id"
ACCESSKEY="YOUR_access_key"
ACCESSSECRET="YOUR_access_secret"
```

**`app.js` File**

```javascript
const {SinchClient} = require('@sinch/sdk-core');

const sinchClient = new SinchClient({
    projectId: process.env.PROJECTID,
    keyId: process.env.ACCESSKEY,
    keySecret: process.env.ACCESSSECRET
});
```

## Number Lookup domain

The Sinch Node.js SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `sinch.numberLookup().[method()]`.

In the Sinch Node.js SDK, Number Lookup API endpoints are accessible through the client:

- [`lookup().v2()`![external](/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg)](https://developers.sinch.com/sdk/sinch-sdk-node/1.5.0/classes/NumberLookupApi.html)


For example:

```javascript
const response = await sinch.numberLookup.lookup({
      numberLookupRequestBody: {
        number: phoneNumber,
        features: [ 'LineType' ],
      },
    });
```

Response fields match the API responses. They are delivered as JavaScript objects.