通过PHP中的REST API获取数据

nafvub8i  于 2023-08-02  发布在  PHP
关注(0)|答案(1)|浏览(112)

我试图通过PHP中的REST API从unicommerce.com获取销售订单。问题是我无法理解通过API从服务器获取数据的参数。据我所知,我成功地从服务器access-token从这个页面使用我的凭据获得数据,但我试图获得sales-order由于很少的参数,我无法理解我传递什么来获取数据。只显示此数据的页面将通过-

  • 基本信息 *

| 详细信息| DETAILS |
| --| ------------ |
| /services/rest/v1/oms/saleorder/get| /services/rest/v1/oms/saleorder/get |
| POST| POST |
| 租户| Tenant |
| HTTPS| HTTPS |
| 应用程序/json| application/json |
| 承载{访问令牌},例如:|承载b30 f3 aea-7978- 49 bb-9 ea 7 - 33 eddfc 80 afa bearer b30f3aea-7978-49bb-9ea7-33eddfc80afa |
我使用这样的,但它不工作,并显示错误-
{“error”:“unauthorized”,“error_description”:“在SecurityContext中未找到身份验证对象”}

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

字符串

ego6inou

ego6inou1#

使用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);

字符串

相关问题