# 1a. Explanation of Python Code Step

{% embed url="<https://www.loom.com/share/60283bc5fc984444840ba7dbf00b64d2?sid=eb35b905-0e0b-4567-b7b4-ffaaab27dbe0>" %}

{% code title="Sample Python Code" %}

```python

import requests

api_key = # 'input your API key here'

url = 'https://app.maax.ai/api/v2/outgoing-messages/'
headers = {
    '2hd-api-key': api_key
}

service_type = # 'customer_support_automation' or 'sales_automation' 
platform = # 'email, 'website, or 'sms'
ai_id = # 'input your ai id here'
followup_url = # 'input your followup webhook url here'
send_response_url = # 'input your followup webhook url here'

message_content = input_data['message']
phone_number = input_data.get('phone', '') 
first_name = input_data.get('first_name', 'unknown')

data = {
    'service_type': service_type,
    'platform': platform,
    'ai_id': ai_id,
    'followup_url': followup_url,
    'send_response_url': send_response_url,
    'message_content': message_content,
    'prospect_info': {
        'phone': phone_number,
        'first_name': first_name
    }
}

# POST request
try:
    response = requests.post(url, json=data, headers=headers)
    response.raise_for_status()  
    output = [response.json()]

except requests.exceptions.RequestException as e:
    error_message = str(e)
    output = {"error": error_message}
```

{% endcode %}

## Summary

1. **`Simplifying the Code Step`** Despite its technical appearance, the code step in Zapier has been simplified to mainly involve copy-pasting and filling in different values.
2. **`Utilizing 'Code by Zapier' Step`** This step is used after everything in the 'ingest' part of the process. It involves running Python code.
3. **`Guidance on Usage`** The speaker encourages pausing and revisiting sections of the tutorial as needed, emphasizing the ease of the process.
4. **`Mapping Input Data`** The tutorial focuses on mapping specific fields like message, phone, and first name in the input data to the code.
5. **`Extracting User Query Information`** The 'message' field involves dropping in the user's question, which will be sent to Maax AI for processing.
6. **`Additional Data Fields`** Other data fields like phone and first name are also sent over. The user has the option to add more information like email and Instagram based on their needs.
7. **`API Key Handling`** The API key is discussed, with a recommendation to use 'storage by Zap' in Zapier for better security, instead of directly showing API keys.
8. **`Setting up Sales Automation and AI ID`** The user selects their sales automation platform and inputs the AI ID from their dashboard, which links the specific version of AI to the Zapier step.
9. **`Establishing Personalized Responses`** Different AI IDs may represent different use cases, each driving a unique goal, thus establishing different 'personalities' for the responses.
10. **`Setting Up Follow-Up URLs`** The tutorial includes mapping webhooks from Zapier in the body response, which is crucial for sending responses to Zapier triggers.
11. **`Finalizing the Step and Testing`** After setting up, a test is run to ensure that the output is successful and that the data is correctly sent to Maax AI.

<br>


---

# 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://documentation.maax.ai/main/setup-your-integration/v2-sales-ai-zapier/1a.-explanation-of-python-code-step.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.
