# NinjaAuth

Request the user's Ninjapay account verification. This can be used for authentication or linking of user's wallet. Using NinjaAuth is an easy and convenient way for users to log into and grant data access to your apps and games across multiple platforms.&#x20;

#### **Step1: Method**

```

POST https://prod.ninjapay.me/api/v1/auth

```

#### **Parameters**&#x20;

```jsx

Body (application/json)
 {
  ninjatag: <string>; // sends a six digit OTP to the linked account email
  kyc?: <bool> // Add <true> if you want the user's kyc in response (only given if user approves)
}


```

#### **Response**

```json

{
   "secret": <string>, // Use this secret along with OTP sent to user's email/phone to verify in the next step, this secret is expires after 60 seconds
 } 


```

#### **Step2: Method**

```jsx

POST https://prod.ninjapay.me/api/v1/auth/verify

```

#### **Parameters**

```jsx

{
  "secret": <string>, // secret from previous response
  "OTP": <int> // OTP is sent to user's linked account email 
}

```

#### **Response**

```jsx
    {
        "user_id": "3708ccca8cdc",
        "ninjatag": "ninja",
        "profile": {
            "full_name": "satoshi nakamoto",
            "email": "sample@sample.com",
            "phone": 917995232267,
            "country": "IN"
        },
        "personal_kyc": {
            "id1": "https://useridfile.com",
            "id2": "https://useridfile.com",
            "id3": "https://useridfile.com"
        },
        "kyc_level": 1,
        "kyc_status": "verified",
        "company_kyc": {
            "company_name": "satoshi nakamoto",
            "email": "sample@sample.com",
            "company_phone": 917995232267,
            "country": "UAE",
            "doc1": "https://userdocfile.com",
            "doc2": "https://userdocfile.com",
            "doc3": "https://userdocfile.com",
            "doc4": "https://userdocfile.com"
        }
```

#### **Code Example**

```jsx
// Declare a function for the first step
async function initiateVerification(ninjatag) {
  const accountVerificationOptions = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'API_KEY'
    },
    body: JSON.stringify({
      "ninjatag": ninjatag,
      "kyc": true
    })
  };

  const response = await fetch('https://prod.ninjapay.me/api/v1/auth', accountVerificationOptions);
  const data = await response.json();

  return data.secret;
}

// Declare a function for the second step
async function verifyAccount(secret, OTP) {
  const verifyOptions = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'API_KEY'
    },
    body: JSON.stringify({
      "secret": secret,
      "OTP": OTP
    })
  };

  const response = await fetch('https://prod.ninjapay.me/api/v1/auth/verify', verifyOptions);
  const data = await response.json();

  return data;
}

// Example of how to use these functions
async function authenticateUser(ninjatag) {
  try {
    const secret = await initiateVerification(ninjatag);

    // Here you would pause and wait for the user to provide the OTP from their email
    const OTP = prompt("Please enter the OTP you received via email");

    const verificationResult = await verifyAccount(secret, OTP);

    console.log(verificationResult);
  } catch (error) {
    console.error(error);
  }
}

// Call the function
authenticateUser("nakamoto");

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ninjapay.gitbook.io/ninjapay-api-docs/coming-soon/api-reference-pro/ninjaauth.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
