<p>Here's an example <code>elementapi.php</code> that should get you going...this is returning shipping details but you can modify the transformer for whatever data you need of course...</p>

<pre><code>return [
'endpoints' =&gt; [
    'api/json/orders/whatever.json' =&gt;  [
        'paginate' =&gt; false,
        'elementType' =&gt; 'Commerce_Order',
        'criteria' =&gt;   ['dateOrdered' =&gt; '&gt;'. date('Y-m-d', strtotime("-2 weeks")),
                         'isPaid' =&gt; true,
                        ],

        'transformer' =&gt; function(Commerce_OrderModel $order) {
            return [
            "id" =&gt; $order-&gt;ISOrderNumber,   
            "fullname" =&gt; $order-&gt;shippingAddress-&gt;firstName ?? '' . " " . $order-&gt;shippingAddress-&gt;lastName ?? '',
            "firstname" =&gt; $order-&gt;shippingAddress-&gt;firstName ?? '',
            "lastname" =&gt; $order-&gt;shippingAddress-&gt;lastName ?? '',    
            "company" =&gt; $order-&gt;shippingAddress-&gt;businessName ?? '',
            "street1" =&gt; $order-&gt;shippingAddress-&gt;address1 ?? '',
            "street2" =&gt; $order-&gt;shippingAddress-&gt;address2 ?? '',
            "suburb" =&gt; $order-&gt;shippingAddress-&gt;city ?? '',
            "state" =&gt; $order-&gt;shippingAddress-&gt;stateName ?? '',
            "postcode" =&gt; $order-&gt;shippingAddress-&gt;zipCode ?? '',
            "phone" =&gt; $order-&gt;shippingAddress-&gt;phone ?? '',
            "mobile" =&gt; $order-&gt;shippingAddress-&gt;phone ?? '',
            "email" =&gt; $order-&gt;email ?? '', 
            ];
        },
    ], 

    // Next api thing to go here...

],
</code></pre>

<p>];</p>

CC BY-SA 3.0
2017-04-18T04:26:24.003Z
2017-04-18T04:26:24.003Z
Jeremy Daalder
<p>I want to list the orders with <code>datePaid</code> is within last 14 days. But I cannot workout the correct criteria, and I don't know if <code>isPaid</code> works correctly as well:</p>

<pre><code>'criteria' =&gt; [
    'dateUpdated' =&gt; '&gt;=' . date('Y-m-d'.' 00:00:00', strtotime("-14 days")),
    'isPaid' =&gt; '1',
],
</code></pre>

CC BY-SA 3.0
2017-04-18T03:47:02.543Z
You said you're looking for `datePaid`, but your code example is using `dateUpdated`.  Not sure if it's affecting your results, but ` 00:00:00` is probably unnecessary. `isPaid` should probably be a boolean. i.e. `'isPaid' => true`.
Brad Bell
CC BY-SA 3.0
2017-04-18T03:47:38.007Z
If none of that helps, try posting the rest of your element API config... could be something else in there.
Brad Bell
CC BY-SA 3.0
2017-04-18T07:09:11.590Z
don't know why i type `dateUpdated` when i was thinking `datePaid`. Thanks, and now things fixed!
idolab
<plugin-craftcommerce><plugin-elementapi>
List Orders with datePaid is within last 14 days using the Element API plugin
# List Orders with datePaid is within last 14 days using the Element API plugin

(Asked by: username_0 on 2017-04-18)

I want to list the orders with datePaid is within last 14 days. But I cannot workout the correct criteria, and I don't know if isPaid works correctly as well:
'criteria' => [
    'dateUpdated' => '>=' . date('Y-m-d'.' 00:00:00', strtotime("-14 days")),
    'isPaid' => '1',
],

**Tags:** plugin-craftcommerce, plugin-elementapi

> **Comments:**
> **username_1**: You said you're looking for `datePaid`, but your code example is using `dateUpdated`.  Not sure if it's affecting your results, but ` 00:00:00` is probably unnecessary. `isPaid` should probably be a boolean. i.e. `'isPaid' => true`.  
> **username_1**: If none of that helps, try posting the rest of your element API config... could be something else in there.  
> **username_0**: don't know why i type `dateUpdated` when i was thinking `datePaid`. Thanks, and now things fixed!  

---

## 1 answers

### Answer by username_2 on 2017-04-18. Score: 4 | Accepted answer

Here's an example elementapi.php that should get you going...this is returning shipping details but you can modify the transformer for whatever data you need of course...
return [
'endpoints' => [
    'api/json/orders/whatever.json' =>  [
        'paginate' => false,
        'elementType' => 'Commerce_Order',
        'criteria' =>   ['dateOrdered' => '>'. date('Y-m-d', strtotime("-2 weeks")),
                         'isPaid' => true,
                        ],

        'transformer' => function(Commerce_OrderModel $order) {
            return [
            "id" => $order->ISOrderNumber,   
            "fullname" => $order->shippingAddress->firstName ?? '' . " " . $order->shippingAddress->lastName ?? '',
            "firstname" => $order->shippingAddress->firstName ?? '',
            "lastname" => $order->shippingAddress->lastName ?? '',    
            "company" => $order->shippingAddress->businessName ?? '',
            "street1" => $order->shippingAddress->address1 ?? '',
            "street2" => $order->shippingAddress->address2 ?? '',
            "suburb" => $order->shippingAddress->city ?? '',
            "state" => $order->shippingAddress->stateName ?? '',
            "postcode" => $order->shippingAddress->zipCode ?? '',
            "phone" => $order->shippingAddress->phone ?? '',
            "mobile" => $order->shippingAddress->phone ?? '',
            "email" => $order->email ?? '', 
            ];
        },
    ], 

    // Next api thing to go here...

],

];


---

