# Invalid\_fields - \[cart\_items\]

**URL:** <https://community.rapyd.net/t/invalid-fields-cart-items/12156>\
**Category:** 🙋🏽‍♀️🙋🏽‍♂️ Ask Questions\
**Created:** [June 28, 2022, 4:44pm UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156 "2022-06-28T16:44:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m2z](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@m2z](https://community.rapyd.net/u/m2z)\
**Post date:** [June 28, 2022, 4:44pm UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156/1 "2022-06-28T16:44:35Z")

</div>

When I include cart\_items I get INVALID\_FIELDS - [CART\_ITEMS]:

array(1) { [“status”]=\> array(5) { [“error\_code”]=\> string(29) “INVALID\_FIELDS - [CART\_ITEMS]” [“status”]=\> string(5) “ERROR” [“message”]=\> string(261) “The request attempted an operation, but one or more of the fields did not have a valid value. The request was rejected. Corrective action: Use valid values. The names of the affected fields appear at the end of the error code. See the API Reference for details.” [“response\_code”]=\> string(29) “INVALID\_FIELDS - [CART\_ITEMS]” [“operation\_id”]=\> string(36) “47bcd867-06de-4009-a467-eac8c8bb20b6” } }

This is my code:

```auto
<?php
include('utilities.php');
$cart_items = [
        "name" => "course",
        "amount" => 51,
        "quantity" => 2,
];
$body = [
    "amount" => 102,
    "complete_checkout_url" => "https://...co.uk/sandbox/complete.php",
    "cancel_checkout_url" => "https://...co.uk/sandbox/cancel.php",
    "cart_items" => $cart_items,
    "country" => "GB",
    "currency" => "GBP",
    "merchant_reference_id" => "950ae8c6-76",
];

try {
    $object = make_request('post', '/v1/checkout', $body);
// var_dump($object['data']['redirect_url']);
    var_dump($object);
// header("Location: ".$object['data']['redirect_url']);
    exit();
} catch (Exception $e) {
    echo "Error: $e";
}
?>

```

---

<div class="post-metadata">

**Author:** ![Community\_Team](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Community\_Team](https://community.rapyd.net/u/Community_Team)\
**Post date:** [June 28, 2022, 8:38pm UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156/2 "2022-06-28T20:38:51Z")

</div>

Thanks, @m2z, those fields are correct, and I made a generated a page in postman just to check.

The URLs you have are actual URLs rather than …co.uk… correct? It would create an error if you input those specific strings (`https://...co.uk/sandbox/cancel.php`).

My guess is the code is generating something, but cart\_items seems to have valid fields.

**Request**

```auto
{
    "complete_checkout_url": "http://test.co.uk/sandbox/complete.php",
    "country": "GB",
    "currency": "GBP",
    "cancel_checkout_url": "https://test.co.uk/sandbox/cancel.php",
    "merchant_reference_id": "950ae8c6-76",
    "amount": 102,
    "cart_items": [{
            "name": "course",
            "amount": 51,
            "quantity": 2
        }
    ]
}

```

**Response**

```auto
{
    "status": {
        "error_code": "",
        "status": "SUCCESS",
        "message": "",
        "response_code": "",
        "operation_id": "54cf6685-85b5-4eb7-a898-cff8dc9791bc"
    },
    "data": {
        "id": "checkout_d3af1bd3147dcc93ef7af11b408c9de6",
        "status": "NEW",
        "language": null,
        "merchant_color": "323fff",
        "merchant_logo": null,
        "merchant_website": "http://rapyd.net",
        "merchant_customer_support": {
            "url": "http://support.rapyd.net",
            "email": "support@rapyd.net",
            "phone_number": "555-555-5555"
        },
        "merchant_alias": "Test Business",
        "merchant_terms": null,
        "merchant_privacy_policy": null,
        "page_expiration": 1657657888,
        "redirect_url": "https://sandboxcheckout.rapyd.net?token=checkout_d3af1bd3147dcc93ef7af11b408c9de6",
        "merchant_main_button": "pay_now",
        "cancel_checkout_url": "https://test.co.uk/sandbox/cancel.php",
        "complete_checkout_url": "http://test.co.uk/sandbox/complete.php",
        "country": "GB",
        "currency": "GBP",
        "amount": 102,
        "payment": {
            "id": null,
            "amount": 102,
            "original_amount": 0,
            "is_partial": false,
            "currency_code": "GBP",
            "country_code": "GB",
            "status": null,
            "description": "Payment via Checkout",
            "merchant_reference_id": "950ae8c6-76",
            "customer_token": null,
            "payment_method": null,
            "payment_method_data": {},
            "expiration": 0,
            "captured": false,
            "refunded": false,
            "refunded_amount": 0,
            "receipt_email": null,
            "redirect_url": null,
            "complete_payment_url": null,
            "error_payment_url": null,
            "receipt_number": null,
            "flow_type": null,
            "address": null,
            "statement_descriptor": null,
            "transaction_id": null,
            "created_at": 0,
            "updated_at": 0,
            "metadata": null,
            "failure_code": null,
            "failure_message": null,
            "paid": false,
            "paid_at": 0,
            "dispute": null,
            "refunds": null,
            "order": null,
            "outcome": null,
            "visual_codes": {},
            "textual_codes": {},
            "instructions": {},
            "ewallet_id": null,
            "ewallets": [],
            "payment_method_options": {},
            "payment_method_type": null,
            "payment_method_type_category": null,
            "fx_rate": null,
            "merchant_requested_currency": null,
            "merchant_requested_amount": null,
            "fixed_side": null,
            "payment_fees": null,
            "invoice": null,
            "escrow": null,
            "group_payment": null,
            "cancel_reason": null,
            "initiation_type": "customer_present",
            "mid": null,
            "next_action": "not_applicable"
        },
        "payment_method_type": null,
        "payment_method_type_categories": null,
        "payment_method_types_include": null,
        "payment_method_types_exclude": null,
        "customer": null,
        "custom_elements": {
            "save_card_default": false,
            "display_description": false,
            "payment_fees_display": true,
            "merchant_currency_only": false,
            "billing_address_collect": false,
            "dynamic_currency_conversion": false
        },
        "timestamp": 1656448288,
        "payment_expiration": null,
        "cart_items": [
            {
                "name": "course",
                "amount": 51,
                "quantity": 2,
                "image": null
            }
        ],
        "escrow": null,
        "escrow_release_days": null
    }
}

```

---

<div class="post-metadata">

**Author:** ![Community\_Team](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Community\_Team](https://community.rapyd.net/u/Community_Team)\
**Post date:** [June 28, 2022, 10:04pm UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156/3 "2022-06-28T22:04:52Z")

</div>

@m2z, after speaking with a team member, it was pointing out that card\_items does need to be an array of objects vs an array of fields as referenced on [Checkout Page Object](https://docs.rapyd.net/build-with-rapyd/reference/checkout-page-object#custom-elements-object).

 ![Screen Shot 2022-06-28 at 2.10.13 PM](https://us1.discourse-cdn.com/flex016/uploads/rapyd/original/2X/9/957382414485e1df973dbbf35db2198bf0edba22.png)

I’m unfamiliar with [PHP syntax](https://www.php.net/manual/en/language.types.object.php), What would your $cart\_items look like as an array of objects?

---

<div class="post-metadata">

**Author:** ![CharlesDorsett](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rapyd.net/charlesdorsett/32/47_2.png) [@CharlesDorsett](https://community.rapyd.net/u/CharlesDorsett)\
**Post date:** [June 29, 2022, 5:49am UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156/4 "2022-06-29T05:49:14Z")

</div>

Your $cart\_items is an object, not an array of objects. It can be an array of one single object, but it must be the right datatype.

---

<div class="post-metadata">

**Author:** ![m2z](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@m2z](https://community.rapyd.net/u/m2z)\
**Post date:** [June 29, 2022, 8:55am UTC](https://community.rapyd.net/t/invalid-fields-cart-items/12156/5 "2022-06-29T08:55:28Z")

</div>

Thanks for your help.
