> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parcha.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Merchant code categorization

Merchant Category Code (MCC) verification is another important aspect of KYB processes. This example demonstrates how to use the Parcha API to verify a business's MCC code based on its basic information.

```mermaid theme={null}
graph TD
    A[Start] --> B[Prepare Business Data]
    B --> C[Run MCC Code Verification]
    C --> D[Poll for Job Status]
    D --> E{Check Result}
    E -->|Complete| F[Process Results]
    E -->|In Progress| D
    F --> G[End]

    style A fill:#f9d71c,stroke:#333,stroke-width:2px
    style B fill:#91c2e8,stroke:#333,stroke-width:2px
    style C fill:#91c2e8,stroke:#333,stroke-width:2px
    style D fill:#91c2e8,stroke:#333,stroke-width:2px
    style E fill:#f9d71c,stroke:#333,stroke-width:2px
    style F fill:#91c2e8,stroke:#333,stroke-width:2px
    style G fill:#f9d71c,stroke:#333,stroke-width:2px
```

### Step 1: Prepare Business Data and Run MCC Code Verification

Use the `runCheck` endpoint to initiate the MCC code verification process.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://demo.parcha.ai/api/v1/runCheck' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "agent_key": "your-agent-key",
    "kyb_schema": {
      "id": "unique-case-id",
      "self_attested_data": {
        "business_name": "TechInnovate Solutions",
        "description": "Providing cutting-edge software solutions for businesses",
        "website": "https://techinnovatesolutions.com",
        "country_code": "US"
      }
    },
    "check_id": "kyb.mcc_code_check_v3",
    "webhook_url": "https://your-webhook-url.com/callback"
  }'
  ```

  ```python Python theme={null}
  import requests

  api_key = 'YOUR_API_KEY'
  url = 'https://demo.parcha.ai/api/v1/runCheck'

  data = {
      "agent_key": "your-agent-key",
      "kyb_schema": {
          "id": "unique-case-id",
          "self_attested_data": {
              "business_name": "TechInnovate Solutions",
              "description": "Providing cutting-edge software solutions for businesses",
              "website": "https://techinnovatesolutions.com",
              "country_code": "US"
          }
      },
      "check_id": "kyb.mcc_code_check_v3",
      "webhook_url": "https://your-webhook-url.com/callback"
  }

  headers = {
      'Authorization': f'Bearer {api_key}',
      'Content-Type': 'application/json'
  }

  response = requests.post(url, json=data, headers=headers)
  print(response.json())
  ```

  ```typescript TypeScript theme={null}
  import axios from 'axios';

  const apiKey = 'YOUR_API_KEY';
  const url = 'https://demo.parcha.ai/api/v1/runCheck';

  const data = {
    agent_key: "your-agent-key",
    kyb_schema: {
      id: "unique-case-id",
      self_attested_data: {
        business_name: "TechInnovate Solutions",
        description: "Providing cutting-edge software solutions for businesses",
        website: "https://techinnovatesolutions.com",
        country_code: "US"
      }
    },
    check_id: "kyb.mcc_code_check",
    webhook_url: "https://your-webhook-url.com/callback"
  };

  axios.post(url, data, {
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    }
  })
  .then(response => console.log(response.data))
  .catch(error => console.error('Error:', error));
  ```
</CodeGroup>

### Step 2: Poll for Job Status (Optional if using webhook)

If you're not using a webhook, you can poll for the job status using the `getJobById` endpoint.

<CodeGroup>
  ```bash cURL theme={null}
  curl 'https://demo.parcha.ai/api/v1/getJobById?job_id=YOUR_JOB_ID&include_check_results=true' \
  -H 'Authorization: Bearer YOUR_API_KEY'
  ```

  ```python Python theme={null}
  import requests
  import time

  api_key = 'YOUR_API_KEY'
  job_id = 'YOUR_JOB_ID'
  url = f'https://demo.parcha.ai/api/v1/getJobById?job_id={job_id}&include_check_results=true'

  headers = {
      'Authorization': f'Bearer {api_key}'
  }

  while True:
      response = requests.get(url, headers=headers)
      job_data = response.json()
      
      if job_data['status'] == 'complete':
          print("Job completed!")
          print(job_data)
          break
      else:
          print("Job still in progress. Waiting...")
          time.sleep(5)  # Wait for 5 seconds before checking again
  ```

  ```typescript TypeScript theme={null}
  import axios from 'axios';

  const apiKey = 'YOUR_API_KEY';
  const jobId = 'YOUR_JOB_ID';
  const url = `https://demo.parcha.ai/api/v1/getJobById?job_id=${jobId}&include_check_results=true`;

  function pollJobStatus() {
    axios.get(url, {
      headers: {
        'Authorization': `Bearer ${apiKey}`
      }
    })
    .then(response => {
      const jobData = response.data;
      if (jobData.status === 'complete') {
        console.log("Job completed!");
        console.log(jobData);
      } else {
        console.log("Job still in progress. Waiting...");
        setTimeout(pollJobStatus, 5000);  // Check again after 5 seconds
      }
    })
    .catch(error => console.error('Error:', error));
  }

  pollJobStatus();
  ```
</CodeGroup>

### Step 3: Process the Results

Once the job is completed, examine the results to retrieve the MCC code and its description.

```python Python theme={null}
if job_data['status'] == 'complete':
    mcc_check_result = next(
        (result for result in job_data['check_results']
         if result['command_id'] == 'kyb.mcc_code_check_v3'),
        None
    )
    if mcc_check_result:
        payload = mcc_check_result['payload']
        mcc_code = payload.get('mcc_code')
        mcc_title = payload.get('mcc_title')
        mcc_description = payload.get('mcc_code_description')
        print(f"MCC Code: {mcc_code}")
        print(f"Title: {mcc_title}")
        print(f"Description: {mcc_description}")
    else:
        print("MCC code check result not found.")
```

Or use JSONPath for cleaner extraction:

```python Python theme={null}
from urllib.parse import quote

jsonpath_query = '$.check_results[?(@.command_id=="kyb.mcc_code_check_v3")].payload'
url = f'https://demo.parcha.ai/api/v1/getJobById?job_id={job_id}&include_check_results=true&jsonpath_query={quote(jsonpath_query)}'

response = requests.get(url, headers=headers)
mcc_payload = response.json()[0]

print(f"MCC Code: {mcc_payload['mcc_code']}")
print(f"Title: {mcc_payload['mcc_title']}")
print(f"Description: {mcc_payload['mcc_code_description']}")
```

### Conclusion

This MCC code verification process demonstrates a straightforward use of the Parcha API:

1. It requires minimal input (basic business information).
2. It can be executed with a single API call to `runCheck`.
3. Results can be retrieved either through a webhook or by polling the job status.

This approach is efficient for quick verifications that don't require document uploads or complex multi-step processes. Always ensure that the business information provided is accurate to get the most reliable MCC code verification results.
