> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.feedonomics.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.feedonomics.com/_mcp/server.

# Generate an API token

POST https://meta.feedonomics.com/api.php/login
Content-Type: application/json

Call this endpoint twice to generate an API token.

1. **Request a 2FA token.** Send your `username`, `password`, and `method: token`. A two-factor authentication (2FA) token is emailed to the address on your account.
2. **Exchange the 2FA token for an API token.** Send the same credentials again and add the `twofa_token` from the email. The response contains your API token.
3. **Use the API token.** Send it as the value of the `x-api-key` header on every authenticated request.

Select a request body variant below to see the fields for step 1 or step 2.


Reference: https://docs.feedonomics.com/developer/api-reference/rest/authentication-api/login

## Request

### Body (application/json)

This endpoint expects an Authentication_login_Request.

- `Authentication_login_Request`
  - twofa_token_request: twofa_token_request
  - api_token_request: api_token_request

## Response

### 200

Successful operation

- `Authentication_login_Response_200`
  - twofa_token_response: twofa_token_response
  - api_token_response: api_token_response

## Errors

### 400 Bad Request Error

The username, password, or 2FA token was not accepted

- `message` (string, optional) — Describes why authentication failed

## Types

### twofa_token_request

Step 1: request a 2FA token. Omit twofa_token on this call. The 2FA token is emailed to the address on your account.

- `username` (string, required) — Account username
- `password` (string, required) — Account password
- `method` (enum, required) — Authentication method. Use token for API integrations.
  - Allowed values: `token`, `cookie`
- `name` (string, optional) — Optional label for the token. Useful to tell tokens apart when one user creates several.

### api_token_request

Step 2: exchange the emailed 2FA token for an API token. Send the same credentials as step 1 and add twofa_token.

- `username` (string, required) — Account username
- `password` (string, required) — Account password
- `method` (enum, required) — Authentication method. Use token for API integrations.
  - Allowed values: `token`, `cookie`
- `twofa_token` (string, required) — The 2FA token emailed to you after the step 1 request
- `name` (string, optional) — Optional label for the token. Useful to tell tokens apart when one user creates several.

### twofa_token_response

Step 1 response. Confirms that a 2FA token was emailed.

- `message` (string, optional) — Tells you where to find the 2FA token

### api_token_response

Step 2 response. Contains the API token to send in the x-api-key header.

- `status` (string, optional) — success when the token was generated
- `token` (string, optional) — API token. Send as the value of the x-api-key header.

## Examples

### Step 1: request a 2FA token

**Request**

```json
{
  "method": "token",
  "password": "password123",
  "username": "user123"
}
```

**Response**

```json
{
  "message": "Check your email for a 2FA token, login again with twofa_token param"
}
```

**SDK Code**

```python Step 1: request a 2FA token
import requests

url = "https://meta.feedonomics.com/api.php/login"

payload = {
    "method": "token",
    "password": "password123",
    "username": "user123"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Step 1: request a 2FA token
const url = 'https://meta.feedonomics.com/api.php/login';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"method":"token","password":"password123","username":"user123"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Step 1: request a 2FA token
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://meta.feedonomics.com/api.php/login"

	payload := strings.NewReader("{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"username\": \"user123\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Step 1: request a 2FA token
require 'uri'
require 'net/http'

url = URI("https://meta.feedonomics.com/api.php/login")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"username\": \"user123\"\n}"

response = http.request(request)
puts response.read_body
```

```java Step 1: request a 2FA token
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://meta.feedonomics.com/api.php/login")
  .header("Content-Type", "application/json")
  .body("{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"username\": \"user123\"\n}")
  .asString();
```

```php Step 1: request a 2FA token
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://meta.feedonomics.com/api.php/login', [
  'body' => '{
  "method": "token",
  "password": "password123",
  "username": "user123"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Step 1: request a 2FA token
using RestSharp;

var client = new RestClient("https://meta.feedonomics.com/api.php/login");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"username\": \"user123\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Step 1: request a 2FA token
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "method": "token",
  "password": "password123",
  "username": "user123"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://meta.feedonomics.com/api.php/login")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Step 2: generate an API token

**Request**

```json
{
  "method": "token",
  "password": "password123",
  "twofa_token": "abc123321cba",
  "username": "user123"
}
```

**Response**

```json
{
  "status": "success",
  "token": "abc123321cba"
}
```

**SDK Code**

```python Step 2: generate an API token
import requests

url = "https://meta.feedonomics.com/api.php/login"

payload = {
    "method": "token",
    "password": "password123",
    "twofa_token": "abc123321cba",
    "username": "user123"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Step 2: generate an API token
const url = 'https://meta.feedonomics.com/api.php/login';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"method":"token","password":"password123","twofa_token":"abc123321cba","username":"user123"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Step 2: generate an API token
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://meta.feedonomics.com/api.php/login"

	payload := strings.NewReader("{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"twofa_token\": \"abc123321cba\",\n  \"username\": \"user123\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Step 2: generate an API token
require 'uri'
require 'net/http'

url = URI("https://meta.feedonomics.com/api.php/login")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"twofa_token\": \"abc123321cba\",\n  \"username\": \"user123\"\n}"

response = http.request(request)
puts response.read_body
```

```java Step 2: generate an API token
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://meta.feedonomics.com/api.php/login")
  .header("Content-Type", "application/json")
  .body("{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"twofa_token\": \"abc123321cba\",\n  \"username\": \"user123\"\n}")
  .asString();
```

```php Step 2: generate an API token
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://meta.feedonomics.com/api.php/login', [
  'body' => '{
  "method": "token",
  "password": "password123",
  "twofa_token": "abc123321cba",
  "username": "user123"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Step 2: generate an API token
using RestSharp;

var client = new RestClient("https://meta.feedonomics.com/api.php/login");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"method\": \"token\",\n  \"password\": \"password123\",\n  \"twofa_token\": \"abc123321cba\",\n  \"username\": \"user123\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Step 2: generate an API token
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "method": "token",
  "password": "password123",
  "twofa_token": "abc123321cba",
  "username": "user123"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://meta.feedonomics.com/api.php/login")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```