PHP - Myob Api更新到销售/发票/专业人员无法正常工作

时间:2016-09-15 23:25:56

标签: php myob

我可以从Sales / Invoice / Professional插入和获取,但我无法更新。它没有给我任何错误它只返回null,不给我任何卷曲错误,但也没有更新任何东西。

我的get和insert工作标题如下:

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

我的卷曲如下:

$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;

我的json数据如下:

{
  "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"
}

查看Lines RowID,它似乎是错误的,因为它需要32个字符,但它只有4个字符,但我从现有记录中获取它所以应该没问题。 var_dump没有显示curl_error。所以我正在使用getinfo。结果如果var_dump如下:

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)
}

我在myob社区发布了相同的内容,但还没有人回复。任何人都可以帮助它有什么问题吗?

1 个答案:

答案 0 :(得分:0)

如果您尝试更新记录,则您的网址需要以您要更新的发票的UID结尾。尝试将网址更改为

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

我注意到cURL“url”属性没有包含UID。另外要记住的是,PUT将替换您正在发送的项目的内容,而不是POST 更新具有更改的属性的内容。

https://stackoverflow.com/a/2590281/1881175被盗:

  对URL的

POST 会在服务器定义的URL处创建子资源。

     对URL的

PUT 会在客户端定义的网址上创建/替换资源