In the Communicating with the REST API-article I got order-info using cURL, HTTP GET - method. Now I'm going to create an order using cURL, JSON-datafile and HTTP PUT - method.

HTTP PUT is a custom request. We have to tell curl this. My curl-setup options are as follows:

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($data)
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_URL, $url);
//I forgot to set 'Content-Type'. Important to remember.
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
						'Content-Length: '.strlen($data),
              			$header_auth));
//$header_auth is an authorization-header containing login-information:
in my case it's defined as the following:
"$authorization_str".base64_encode($login); 
//where $authorization_str="Authorization: Basic ", and login is defined as follows
//$login = 'username'.':'.'password'

//The json-data is stored in a file called "createorder.json". We have to get the contents of this:

$data = file_get_contents("createorder.json");

This files' contents is as follows:

{
  "goodsOwnerId": 67,
  "orderNumber": "201905180831-test",
  "deliveryDate": "2019-05-21T00:00:00",
  "referenceNumber": "ref-test123",
  "orderRemark": "Creating order using REST API. action: PUT, with JSON-data----FM",
  "deliveryInstruction": "Call before delivering: 555-31313",
  "consignee": {
    "customerNumber": "31750",
    "name": "Test Testson",
    "address1": "Testsendeveien 10T",
    "postcode": "1810",
    "city": "Askim",
    "countryCode":  "NO"
  },
  "transporter": {
    "transporterServiceCode": "SBTLNOSG"
  },
  "orderLines": [
    {
      "rowNumber": 1,
      "articleNumber": "101213",
      "numberOfItems": "5.00"
    },
    {
      "rowNumber": 2,
      "articleNumber": "101363",
      "numberOfItems": "9.00"
    }
  ]
}

Thsi is actually a very easy/short way of creating an order. Sometimes this is all that is needed, and I guess that was the point of creating the REST API for ongoingsystems.se, because there are alot of information that you cannot insert(nor defined), for this API. If one wants to add more info or get into more details, I/one has to use SOAP, which is very detailed when it comes to information.

But in many cases this is all that is needed. And I guess that this is something that should be put into consideration before choosing an API.