jasontwong / fetchapp

5 stars 1 forks source link

Unable to Create Order #2

Closed graygilmore closed 11 years ago

graygilmore commented 11 years ago

All other classes work perfect (listing products, company info, etc), but when I try to create an order I get a "FetchApp Not Found" error.

Everything is being included properly (since listing products and other calls work), it's just creating orders, so I must be doing something wrong.

I've tried all sorts of combinations in the XML that I'm sending, the example provided below is simply my latest effort.

Here's my code:

require 'fetchapp/FetchApp.php';
$fetch_app = new FetchApp( 'https://myname.fetchapp.com', 'myname', 'mytoken' );

$new_order = '<?xml version="1.0" encoding="UTF-8"?>
                      <order>
                          <email>email@email.com</email>
                          <order_items type="array">
                              <order_item>
                                  <sku>mysku</sku>
                              </order_item>
                          </order_items>
                      </order>';
$create_order = $fetch_app->orders( 'create', $new_order );
jasontwong commented 11 years ago

Gary,

The issue is that you're passing a string as a parameter. Because of the magic method builder, if the parameter is a string, it thinks it's an additional API endpoint. If you want to pass post data it should be a SimpleXMLElement and if you want to pass query parameters it should be an array. I suggest changing your code as follows:

$create_order = $fetch_app->orders( 'create', simplexml_load_string( $new_order ) );
graygilmore commented 11 years ago

Thanks, Jason, that worked perfectly.