使用Linnworks API和Inventory / CreateInventoryItemTitles

时间:2017-02-01 11:21:13

标签: php rest api post

我正在尝试使用Linnworks API发布帖子请求。

更具体地说推新标题,但我无法让它发挥作用。我正在查询他们的系统,所以我的格式有明显的错误;

$CreateTitle = json_decode(Factory::GetResponse("Inventory/CreateInventoryItemTitles","inventoryItemTitles=[{StockItemId=00000000-4683-0000-88dc-00880000fc09&Source=Test&SubSource=Test&Title=Test}]",$authorization->Token, "https://api.linnworks.net/"));

Linnworks支持团队已回复;

对于rowId生成随机guid。这是我的请求正文:#/ p>

inventoryItemTitles=[{"StockItemId":"797b268d-4fa5-4714-a96d-00d45608f2d6","Title":"New Title","Source":"EBAY","SubSource":"EBAY4","pkRowId":"ccbd77f6-f04a-404b-af36-f859747d5c20"}]

但这不是在PHP中,他们不会提供任何有关php开发的帮助。

所以根据Brians的建议,我已经更新了这个,但是我是;仍然遇到HTTP / 1.1 400错误请求。显然仍然做错了;

$object = [
 "StockItemId" => "00000000-4683-0000-88dc-00880000fc09",
 "Title" => "value2",
 "Source" => "value2",
 "SubSource" => "value2" 
 ];

$encoded = json_encode($object);
$CreateTitle = json_decode(Factory::GetResponse("Inventory/CreateInventoryItemTitles",$encoded,$authorization->Token, "https://api.linnworks.net/"));

// print_r($encoded);

2 个答案:

答案 0 :(得分:0)

你需要像这样形成你的对象:

<?php

 $object = [
    [
    "pkRowId" => "5c6dc399-f476-49a5-8c64-771310a25691",
    "Source" => "sample string 2",
    "SubSource" => "sample string 3",
    "Title" => "sample string 4",
    "StockItemId" => "5695ab85-829d-4f5c-bd88-f0b6943fd577"
  ],
  [
    "pkRowId" => "5c6dc399-f476-49a5-8c64-771310a25691",
    "Source" => "sample string 2",
    "SubSource" => "sample string 3",
    "Title" => "sample string 4",
    "StockItemId" => "5695ab85-829d-4f5c-bd88-f0b6943fd577"
  ]

];

 $encoded = json_encode($object);

 print_r($encoded);

结果:

[{"pkRowId":"5c6dc399-f476-49a5-8c64-771310a25691","Source":"sample string 2","SubSource":"sample string 3","Title":"sample string 4","StockItemId":"5695ab85-829d-4f5c-bd88-f0b6943fd577"},
{"pkRowId":"5c6dc399-f476-49a5-8c64-771310a25691","Source":"sample string 2","SubSource":"sample string 3","Title":"sample string 4","StockItemId":"5695ab85-829d-4f5c-bd88-f0b6943fd577"}]

这是您在REST调用中作为有效负载inventoryItemTitles=发送的内容,它们需要一个对象数组。

答案 1 :(得分:0)

在我的示例中将标题列为“示例字符串4”时,失败是由&符号引起的! '进行urlencode'