|
from flask import request, jsonify |
|
import os |
|
import requests |
|
import globs |
|
|
|
api_key = os.getenv('api_key') |
|
base_url = os.getenv('base_url') |
|
token = os.getenv('token') |
|
|
|
def add_user(): |
|
err = 0 |
|
|
|
if api_key == request.args.get('api'): |
|
|
|
names = globs.name |
|
emails = globs.email |
|
phones = globs.phone |
|
grups_id = globs.grup_id |
|
pr1s = globs.pr1 |
|
pr2s = globs.pr2 |
|
|
|
|
|
data = { |
|
'list_id': grups_id, |
|
'email': emails, |
|
'values': [ |
|
{'value': names, 'parameter_id': 'nam1'}, |
|
{'value': phones, 'parameter_id': 'pho2'}, |
|
{'value': pr1s, 'parameter_id': 'pr13'}, |
|
{'value': pr2s, 'parameter_id': 'pr24'} |
|
] |
|
} |
|
|
|
|
|
headers = { |
|
'Authorization': f'Bearer {token}', |
|
'Content-Type': 'application/json' |
|
} |
|
response = requests.post(f"{base_url}lists/{data['list_id']}/recipients", json=data, headers=headers) |
|
|
|
|
|
globs.server_response = response.text |
|
|
|
|
|
err = 1 if response.status_code == 200 else 0 |
|
|
|
response_data = { |
|
"status": "success" if err == 1 else "error", |
|
"err": err |
|
} |
|
|
|
return jsonify(response_data) |