0

I can insert and get from Sales/Invoice/Professional but I can not update. It doesn't give me any error it just return null, doesn't give me any curl error, but also didn't update anything.

my working header for get and insert as follow :

$this->header_data = array(
        'Authorization: Bearer ' . $this->access_token,
        'x-myobapi-cftoken: ' . $this->CfToken,
        'x-myobapi-key: ' . $this->ClientId,
        'x-myobapi-version: v2'
    );

my curl is as follow :

$temp_file = tmpfile();
$json_data = json_encode($data);
fwrite($temp_file, $json_data);
fseek($temp_file, 0);

var_dump($json_data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_INFILE, $temp_file);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($json_data));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$result = curl_exec($ch);

$decoded_result = json_decode($result);

echo "curl errno: ";
var_dump(curl_error($ch));

echo "\n curl info: ";
var_dump(curl_getinfo($ch));

fclose($temp_file);
return $decoded_result;

my json data is as follow :

{
  "Date": "2016-09-15 00:13:32",
  "Customer": {
    "UID": "1e75e4d0-61af-4c40-bd01-16041719c773"
  },
  "Lines": [
    {
      "Total": "100",
      "Description": "wc id - 8443:Membership member",
      "TaxCode": {
        "UID": "54c69a03-032d-4d93-a8df-90a04b20548f"
      },
      "Account": {
        "UID": "4dc0e4dd-73a5-476e-838e-acafbba6e63f"
      },
      "Date": "2016-09-15 00:13:32",
      "Job": {
        "UID": "bf95e411-956a-4431-8cab-5a82d590bea4"
      },
      "RowID": 1143,
      "RowVersion": "-8806226121369583616"
    }
  ],
  "CustomerPurchaseOrderNumber": "WC-8443",
  "Status": "Open",
  "UID": "69e6354e-b9b7-4744-851d-a0fb75dc4bfa",
  "RowVersion": "-9094456497521295360"
}

Looking at the Lines RowID, it seems to be wrong because it requires 32 characters but it is only 4 characters, but i'm getting it from the existing records so should be alright. there is no curl_error showing with var_dump. so i'm using getinfo. result if var_dump as follow:

curl errno: string(0) ""

curl info: array(26) {
  ["url"]=>
  string(100) "https://ar1.api.myob.com/accountright/35b87d7b-d79a-4539-a060-6f20f56d8340/Sale/Invoice/Professional"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(404)
  ["header_size"]=>
  int(506)
  ["request_size"]=>
  int(1230)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.346163)
  ["namelookup_time"]=>
  float(0.012373)
  ["connect_time"]=>
  float(0.030841)
  ["pretransfer_time"]=>
  float(0.071112)
  ["size_upload"]=>
  float(830)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(2397)
  ["download_content_length"]=>
  float(0)
  ["upload_content_length"]=>
  float(830)
  ["starttransfer_time"]=>
  float(0.089799)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(14) "54.252.117.213"
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(443)
  ["local_ip"]=>
  string(13) "223.27.16.227"
  ["local_port"]=>
  int(60100)
}

I've posted the same thing on myob community but no one replies yet. anyone can help what is wrong with it?

jmjap
  • 166
  • 13

1 Answers1

0

If you are trying to update a record, your URL will need to end with the UID of the Invoice you would like to update. Try changing the URL to

https://ar1.api.myob.com/accountright/35b87d7b-d79a-4539-a060-6f20f56d8340/Sale/Invoice/Professional/69e6354e-b9b7-4744-851d-a0fb75dc4bfa

I noticed that the cURL "url" property did not have the UID included. Another thing to keep in mind is that a PUT will replace the contents of the item that you are sending, rather than a POST which will update the contents with the changed properties.

Stolen from https://stackoverflow.com/a/2590281/1881175:

POST to a URL creates a child resource at a server defined URL.

PUT to a URL creates/replaces the resource in its entirety at the client defined URL.

Community
  • 1
  • 1
prototype14
  • 305
  • 2
  • 11