CreateOrders not working, any suggestions?

Hi,


Trying to have a small integration with linnworks from our ecommerce platform which essentially updates stock on either side, this appears to work no proble but now im looking at creating orders so we can manage the order status (just so its in linnworks in any capacity). I can pull order info but unfortunately I cannot seem to create an order via /Orders/CreateOrders.


Should the call to CreateOrders generate an error response if something is missing or invalid? Its extremely difficult to debug as there seems to be no list as to what is required for an order to be generated via the API and there is no feedback (unless this is an issue on our end?) so we cant debug what is wrong. 


Here is an example json sent and I added &location=default to the request incase that was needed.


orders =[

  {
    "UseChannelTax": true,
    "AutomaticallyLinkBySKU": true,
    "Site": "Protein Water Co",
    "MatchPostalServiceTag": "",
    "MatchPaymentMethodTag": "",
    "MappingSource": "",
    "OrderState": "None",
    "PaymentStatus": "Unpaid",
    "OrderItems": [
      {
        "TaxCostInclusive": true,
        "UseChannelTax": true,
        "PricePerUnit": "14.00",
        "Qty": "1",
        "TaxRate": "",
        "LineDiscount": 0,
        "ItemNumber": "2",
        "ChannelSKU": "V7",
        "isService": false,
        "ItemTitle": "Protein Water Co - Coconut & Mango",
        "Options": {
          "Property": "",
          "Value": ""
        }
      }
    ],
    "ExtendedProperties": {
      "Name": "",
      "Value": "",
      "Type": ""
    },
    "Notes": {
      "Note": "",
      "NoteEntryDate": "",
      "NoteuserName": "",
      "Internal": ""
    },
    "Source": "Verticalplus",
    "SubSource": "Verticalplus Site",
    "ChannelBuyerName": "lee perring",
    "ReferenceNumber": "180131-28-1128",
    "ExternalReference": "180131-28-1128",
    "SecondaryReferenceNumber": "",
    "Currency": "GBP",
    "ReceivedDate": {
      "date": "2018-01-31 11:28:01.000000",
      "timezone_type": 3,
      "timezone": "Europe\/London"
    },
    "DispatchBy": "",
    "PaidOn": "",
    "PostalServiceCost": "",
    "PostalServiceTaxRate": "",
    "PostalServiceDiscount": "",
    "Discount": "",
    "DiscountType": "",
    "BillingAddress": {
      "MatchCountryCode": "",
      "MatchCountryName": "",
      "FullName": "lee perring",
      "Address1": "8 pomphlett road",
      "Address2": "",
      "Address3": "plymouth",
      "Town": "plymouth",
      "Region": "Devon",
      "PostCode": "PL97BL",
      "Country": "GBR",
      "PhoneNumber": "",
      "EmailAddress": "lee@ico3.com",
      "isEmpty": false
    },
    "ShippingAddress": {
      "MatchCountryCode": "",
      "MatchCountryName": "",
      "FullName": "lee perring",
      "Address1": "8 pomphlett road",
      "Address2": "",
      "Address3": "plymouth",
      "Town": "plymouth",
      "Region": "Devon",
      "PostCode": "PL97BL",
      "Country": "GBR",
      "PhoneNumber": "",
      "EmailAddress": "lee@ico3.com",
      "isEmpty": false
    }
  }
]

Any assistance is greatly appreciated on this matter.

Thanks,

Lee


Hello Lee,


While I will be debugging your request here is the link to Mandatory Fields for this call:


 https://help.linnworks.com/solution/articles/7000013635-mandatory-parameters-for-createorders-api-call


Kind regards,

Nikita Barford

Hi Nik,


Thanks for the link, tried with filling in the DispatchBy as this is the only field missing values from the list but still no joy. I have also tried with using the exact same format of the date for both dispatchby and receivedDate incase it was that but still isnt working for me.


If you need any further information from me please let me know, appreciate its difficult to debug if you dont have the full scope!


Cheers,

Lee

Hi Lee,


There quite a few things I can already see within your JSON.


EP and notes needs to be sent in squared brackets:


"ExtendedProperties": { "Name": "", "Value": "", "Type": "" }, "Notes": { "Note": "", "NoteEntryDate": "", "NoteuserName": "", "Internal": "" }


ShippingAddress parameter must be DeliveryAddress.


ReceivedDate parameter looks different from the docs:


  "ReceivedDate": {
      "date": "2018-01-31 11:28:01.000000",
      "timezone_type": 3,
      "timezone": "Europe\/London"
    }


Tomorrow I will try to build your request  from the one I provided in KB. 


Thanks for the quick feedback Nik.


I have corrected those however im not sure on the received date being in that format as the example shows it as just a single text entry

http://apps.linnworks.net/Api/Method/Orders-CreateOrders


I have tried both your suggestion and the one in the example with no success. I have included below the latest example request. I assume its something obvious to you guys such as a field missing I just cant see it. Thanks


[
  {
    "UseChannelTax": true,
    "AutomaticallyLinkBySKU": true,
    "Site": "Protein Water Co",
    "MatchPostalServiceTag": "",
    "MatchPaymentMethodTag": "",
    "MappingSource": "",
    "OrderState": "None",
    "PaymentStatus": "Unpaid",
    "OrderItems": [
      {
        "TaxCostInclusive": true,
        "UseChannelTax": true,
        "PricePerUnit": "14.00",
        "Qty": "1",
        "TaxRate": "",
        "LineDiscount": 0,
        "ItemNumber": "2",
        "ChannelSKU": "V7",
        "isService": false,
        "ItemTitle": "Protein Water Co - Coconut & Mango",
        "Options": [
          {
            "Property": "",
            "Value": ""
          }
        ]
      }
    ],
    "ExtendedProperties": [
      {
        "Name": "",
        "Value": "",
        "Type": ""
      }
    ],
    "Notes": [
      {
        "Note": "",
        "NoteEntryDate": "",
        "NoteuserName": "",
        "Internal": ""
      }
    ],
    "Source": "Verticalplus",
    "SubSource": "Verticalplus Site",
    "ChannelBuyerName": "lee perring",
    "ReferenceNumber": "180131-28-1128",
    "ExternalReference": "180131-28-1128",
    "SecondaryReferenceNumber": "",
    "Currency": "GBP",
    "ReceivedDate": {
      "date": {
        "date": "2018-01-31 11:28:01.000000",
        "timezone_type": 3,
        "timezone": "Europe\/London"
      },
      "timezone_type": 3,
      "timezone": "Europe\\\/London"
    },
    "DispatchBy": {
      "date": {
        "date": "2018-01-31 11:28:01.000000",
        "timezone_type": 3,
        "timezone": "Europe\/London"
      },
      "timezone_type": 3,
      "timezone": "Europe\\\/London"
    },
    "PaidOn": "",
    "PostalServiceCost": "",
    "PostalServiceTaxRate": "",
    "PostalServiceDiscount": "",
    "Discount": "",
    "DiscountType": "",
    "BillingAddress": {
      "MatchCountryCode": "",
      "MatchCountryName": "",
      "FullName": "lee perring",
      "Address1": "8 pomphlett road",
      "Address2": "",
      "Address3": "plymouth",
      "Town": "plymouth",
      "Region": "Devon",
      "PostCode": "PL97BL",
      "Country": "GBR",
      "PhoneNumber": "",
      "EmailAddress": "lee@ico3.com",
      "isEmpty": false
    },
    "DeliveryAddress": {
      "MatchCountryCode": "",
      "MatchCountryName": "",
      "FullName": "lee perring",
      "Address1": "8 pomphlett road",
      "Address2": "",
      "Address3": "plymouth",
      "Town": "plymouth",
      "Region": "Devon",
      "PostCode": "PL97BL",
      "Country": "GBR",
      "PhoneNumber": "",
      "EmailAddress": "lee@ico3.com",
      "isEmpty": false
    }
  }
]



Hello Lee,


I have found an issue. Basically remove space between orders and = sign, orders=[{ and you will receive errors about what is wrong with your object.


Hi Nik,


I think thats just the formatter I used to make it look readable on here, code wise there is no space.

orders=[{"UseChannelTax":true,"AutomaticallyLinkBySKU":true,"Site":"Protein Water Co","MatchPostalServiceTag":"","MatchPaymentMethodTag":"","MappingSource":"","OrderState":"None","PaymentStatus":"Unpaid","OrderItems":[{"TaxCostInclusive":true,"UseChannelTax":true,"PricePerUnit":"14.00","Qty":"1","TaxRate":"","LineDiscount":0,"ItemNumber":"2","ChannelSKU":"V7","isService":false,"ItemTitle":"Protein Water Co - Coconut & Mango","Options":[{"Property":"","Value":""}]}],"ExtendedProperties":[{"Name":"","Value":"","Type":""}],"Notes":[{"Note":"","NoteEntryDate":"","NoteuserName":"","Internal":""}],"Source":"Verticalplus","SubSource":"Verticalplus Site","ChannelBuyerName":"lee perring","ReferenceNumber":"180131-28-1128","ExternalReference":"180131-28-1128","SecondaryReferenceNumber":"","Currency":"GBP","ReceivedDate":{"date":{"date":"2018-01-31 11:28:01.000000","timezone_type":3,"timezone":"Europe\/London"},"timezone_type":3,"timezone":"Europe\\\/London"},"DispatchBy":{"date":{"date":"2018-01-31 11:28:01.000000","timezone_type":3,"timezone":"Europe\/London"},"timezone_type":3,"timezone":"Europe\\\/London"},"PaidOn":"","PostalServiceCost":"","PostalServiceTaxRate":"","PostalServiceDiscount":"","Discount":"","DiscountType":"","BillingAddress":{"MatchCountryCode":"","MatchCountryName":"","FullName":"lee perring","Address1":"8 pomphlett road","Address2":"","Address3":"plymouth","Town":"plymouth","Region":"Devon","PostCode":"PL97BL","Country":"GBR","PhoneNumber":"","EmailAddress":"lee@ico3.com","isEmpty":false},"DeliveryAddress":{"MatchCountryCode":"","MatchCountryName":"","FullName":"lee perring","Address1":"8 pomphlett road","Address2":"","Address3":"plymouth","Town":"plymouth","Region":"Devon","PostCode":"PL97BL","Country":"GBR","PhoneNumber":"","EmailAddress":"lee@ico3.com","isEmpty":false}}]


I encode the array data to json then add orders= 


Request being built is using the same examples from your PHP Factory::getResponse function. Still no joy with error responses, the system works fine for setting stock its just this createorders functionality. 

Any other suggestions?


Thanks,

Lee

Hello Lee,


raw request and response I sent:


https://SERVER/api/Orders/CreateOrders


Request body:


orders=[{"UseChannelTax":true,"AutomaticallyLinkBySKU":true,"Site":"Protein Water Co","MatchPostalServiceTag":"","MatchPaymentMethodTag":"","MappingSource":"","OrderState":"None","PaymentStatus":"Unpaid","OrderItems":[{"TaxCostInclusive":true,"UseChannelTax":true,"PricePerUnit":"14.00","Qty":"1","TaxRate":"","LineDiscount":0,"ItemNumber":"2","ChannelSKU":"V7","isService":false,"ItemTitle":"Protein Water Co - Coconut & Mango","Options":[{"Property":"","Value":""}]}],"ExtendedProperties":[{"Name":"","Value":"","Type":""}],"Notes":[{"Note":"","NoteEntryDate":"","NoteuserName":"","Internal":""}],"Source":"Verticalplus","SubSource":"Verticalplus Site","ChannelBuyerName":"lee perring","ReferenceNumber":"180131-28-1128","ExternalReference":"180131-28-1128","SecondaryReferenceNumber":"","Currency":"GBP","ReceivedDate":{"date":{"date":"2018-01-31 11:28:01.000000","timezone_type":3,"timezone":"Europe\/London"},"timezone_type":3,"timezone":"Europe\\\/London"},"DispatchBy":{"date":{"date":"2018-01-31 11:28:01.000000","timezone_type":3,"timezone":"Europe\/London"},"timezone_type":3,"timezone":"Europe\\\/London"},"PaidOn":"","PostalServiceCost":"","PostalServiceTaxRate":"","PostalServiceDiscount":"","Discount":"","DiscountType":"","BillingAddress":{"MatchCountryCode":"","MatchCountryName":"","FullName":"lee perring","Address1":"8 pomphlett road","Address2":"","Address3":"plymouth","Town":"plymouth","Region":"Devon","PostCode":"PL97BL","Country":"GBR","PhoneNumber":"","EmailAddress":"lee@ico3.com","isEmpty":false},"DeliveryAddress":{"MatchCountryCode":"","MatchCountryName":"","FullName":"lee perring","Address1":"8 pomphlett road","Address2":"","Address3":"plymouth","Town":"plymouth","Region":"Devon","PostCode":"PL97BL","Country":"GBR","PhoneNumber":"","EmailAddress":"lee@ico3.com","isEmpty":false}}]&location=default



response:

{"Code":"-","Message":"Can't deserialize \"orders\" parameter. Error: \"Error converting value \"\" to type 'System.Double'. Path '[0].OrderItems[0].TaxRate', line 1, position 302.\""}


So, currently the problem within order Items Tax rate.


Hi Nik,


Thanks I have realised the missing part in all of this. stream_context_create function needs to have the parameter 'ignore_errors' set to true in the $request as any error returns a 400 error which means the responses from $response = @file_get_contents($url, FALSE, $context); results in false or empty  data which made debugging next to impossible.


This is going from your php sdk as I have always used CURL which appears to not suffer from this, I really recommend you guys amend your PHP sdk to have this turned on as you dont seem to mention anything with regards to what error messages you could or will receive so I didnt know I should expect error messages, I wrongly assumed you just didnt return anything (as some people do unfortunately!). I would also suggest rather than filling in all your fields with 'sample string X' that you produce a 'worked' example so its easier to see and may help someone else in the future.

Do you guys have a list of error codes or something somewhere? It seems the errors you return Code and Message but Code always seems to be '-' which is hard to target as it seems like its the equivalent to not set, I have only looked at some of the errors though so it maybe a case that these few are unset but you have a long list of codes being used to handle any error scenarios.


I have managed to create an order now so I am onto the next part of this so thanks for your help.


For clarity you should change Factory.php GetResponse

 $opts = array(

  'http'=>array(

'method'=>"POST",

'header'=>"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" .

  "User-Agent: Linnworks PHP API SDK \r\n" . 

  "Referer: https://www.linnworks.net/ \r\n" .

  "Content-Length: " . strlen($data) . "\r\n" .

  "Authorization: " . $token . "\r\n"

  ,

'content' => $data

  )

);


to:

 $opts = array(

  'http'=>array(

'method'=>"POST",

'header'=>"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" .

  "User-Agent: Linnworks PHP API SDK \r\n" . 

  "Referer: https://www.linnworks.net/ \r\n" .

  "Content-Length: " . strlen($data) . "\r\n" .

  "Authorization: " . $token . "\r\n"

  ,

'content' => $data,

                        'ignore_errors' => true

  )

);



Cheers,

Lee


Login to post a comment