【问题标题】:fetch data through rest API in PHP在 PHP 中通过 rest API 获取数据
【发布时间】:2021-05-02 06:33:14
【问题描述】:

我正在尝试通过来自 unicommerce.com 的 PHP 中的 rest API 获取销售订单。问题是我无法理解通过 API 从服务器获取数据的参数。 据我了解,我使用我的凭据从该页面成功地从服务器access-token 获取数据。 但由于参数很少,我试图获得sales-order,我无法理解我通过什么来获取数据。 仅显示要传递的数据的页面 -

基本信息

NAME DETAILS
Endpoint: /services/rest/v1/oms/saleorder/get
Request Type: POST
Level: Tenant
Scheme: HTTPS
Header (Content-Type): application/json
Header (Authorization): bearer {access-token}, Eg.: bearer b30f3aea-7978-49bb-9ea7-33eddfc80afa

我是这样使用的,但它不起作用 并显示错误 - {"error":"unauthorized","error_description":"An Authentication object was not found in the SecurityContext"}

https://subdomain.unicommerce.com/services/rest/v1/oms/saleorder/get?bearer=b30f3aea-7978-49bb-9ea7-33eddfc80afa

【问题讨论】:

标签: php api curl fetch rest


【解决方案1】:

将 curl 与授权标头一起使用

$requestPayload = [
    'code' => 'string',
    'facilityCodes' => ['string']
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://subdomain.unicommerce.com/services/rest/v1/oms/saleorder/get");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestPayload));  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer b30f3aea-7978-49bb-9ea7-33eddfc80afa',
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec ($ch);

curl_close ($ch);

var_dump($response);

【讨论】:

  • 谢谢,但它是销售订单方面的工作。这不可能获取所有销售订单吗?当我使用print_r($response) 时,它也不显示漂亮
  • 请阅读 API 文档中的Request Payload Detailscode 用于单个订单或facilityCodes 用于列表订单
  • 先生,它给1619944810000 UTC 格式日期,请您在这个 IST 格式中更改
猜你喜欢
  • 1970-01-01
  • 2015-11-17
  • 2015-05-16
  • 1970-01-01
  • 2017-07-09
  • 2019-10-25
  • 1970-01-01
  • 1970-01-01
  • 2019-02-12
相关资源
最近更新 更多