# Lookup email

Quick example: <https://loginwithlink.com/api/lookup-email?email=m@rkmoriarty.com&STRIPE_PUBLIC_KEY=pk_live_51JocsEAGmp0k5LnwNUl7SJzZMhMMcMJ4X4PWg928nJLm5ocPpzHLhBOBMbTLBrXPYdkepbg9HX0AJFY8ixt2bXTV00vg5Ja3DP> <- That uses my public key — please use your own once you get the idea!

## Request

This is a GET request.

```
GET https://loginwithlink.com/api/lookup-email
```

Include the following query parameters

| Parameter           | Example                                                                                                       |
| ------------------- | ------------------------------------------------------------------------------------------------------------- |
| email               | <m@rkmoriarty.com>                                                                                            |
| STRIPE\_PUBLIC\_KEY | pk\_live\_51JocsEAGmp0k5LnwNUl7SJzZMhMMcMJ4X4PWg928nJLm5ocPpzHLhBOBMbTLBrXPYdkepbg9HX0AJFY8ixt2bXTV00vg5Ja3DP |
|                     |                                                                                                               |

In total, your request will look like this

```
GET 
https://loginwithlink.com/api/lookup-email?email=m@rkmoriarty.com&STRIPE_PUBLIC_KEY=pk_live_51JocsEA_YOUR_KEY_HERE
```

e.g., if using \`fetch\`, you might compose a request like so:

```javascript
const url = "https://loginwithlink.com/api/lookup-email";
const queryParams = {
  email: "m@rkmoriarty.com",
  STRIPE_PUBLIC_KEY: "pk_live_51JocsEAGmp0k5LnwNUl7SJzZMhMMcMJ4X4PWg928nJLm5ocPpzHLhBOBMbTLBrXPYdkepbg9HX0AJFY8ixt2bXTV00vg5Ja3DP"
};

const queryString = Object.entries(queryParams)
  .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
  .join("&");

const fullUrl = `${url}?${queryString}`;

fetch(fullUrl)
  .then(response => response.json())
  .then(data => {
    // Handle the response data here
    console.log(data);
  })
  .catch(error => {
    // Handle any errors that occur during the fetch request
    console.error(error);
  });
```

##

## Response

The response will look something like this, if a match is found:

```json
{
  "result": "success",
  "parametersSubmitted": {
    "email": "m@rkmoriarty.com",
    "STRIPE_PUBLIC_KEY": "pk_live_51JocsEAGredacted [you provided in your request]"
  },
  "userExistsOnLink": true, // or false, if user not found on Link
  "client_secret": "ABCD1234redacted" // Keep this handy; you'll need to re-submit in the final step
  "redacted_phone_number": "+3*********90" // you may wish to display this: "SMS has been sent to…"
}
```

You will see `"userExistsOnLink": false` if user is not found on Link.
