Python script

import requests
import json

calculate_schema = open("calculate.json")
order_schema = open("order.json")

vitau_test_host = "https://api-v2.vitau.mx"
vitau_test_api_key = ""
email = ""
pswd = ""

def authenticate():
    """Fetch user access_token."""
    r = requests.post(
        url=f"{vitau_test_host}/api/token/",
        json={"email": email, "password": pswd},
        headers={"x-api-key": vitau_test_api_key},
    )
    return r.json()["access"]

def calculate():
    """Find the order total and estimated delivery date."""
    payload = json.load(calculate_schema)
    r = requests.post(
        url=f"{vitau_test_host}/api/orders/calculate/",
        json=payload,
        headers={"x-api-key": vitau_test_api_key},
    )
    # Correct status should be 200
    return r.status_code, r.json()

def create_order():
    """Create an 'approved' order."""
    # Requires authentication
    access_token = authenticate()
    payload = json.load(order_schema)
    r = requests.post(
        url=f"{vitau_test_host}/api/orders/resources/",
        json=payload,
        headers={
            "x-api-key": vitau_test_api_key,
            "Authorization": f"Bearer {access_token}",
        },
    )
    # Correct status should be 201
    return r.status_code, r.json()

Calculate JSON

{
    "zipcode": "64030",
    "details": [
        {
            "product": 19466,
            "quantity": 2
        },
        {
            "product": 72,
            "quantity": 5
        }
    ]
}

Orders JSON

{
    "user": {
        "email": "valid-email",
        "phone": null,
        "first_name": "Nombre",
        "last_name": "Apellido",
        "second_last_name": "Otro"
    },
    "order": {
        "shipping": {
            "street": "Gral. Pablo González Garza",
            "exterior_number": "620",
            "neighborhood": "Chepevera",
            "city": "Monterrey",
            "state": "Nuevo León",
            "country": "México",
            "zipcode": "64030",
            "phone": "+52 81 2190 4018",
            "additional_info": "Puerta color azul"
        },
        "payment_method": 42,
        "payment_status": "credit",
        "details": [
            {
                "product": 19466,
                "quantity": 2
            },
            {
                "product": 72,
                "quantity": 5
            }
        ]
    }
}