2

I am trying to get the sales order through rest API in PHP from unicommerce.com. The issue is I could not able to understand the parameter to fetch the data from the server via API. as I understand I successfully get the data from the server access-token from this page using my credentials, but I am trying to get sales-order due to very few parameters I could not understand what I pass to get the data. The page only showing this data to pass -

Basic Information

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

I am using like this but it not working and showing the error -

{"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
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • The basic info table you include shows that `bearer` is meant to be passed as a Header, not as part of the query string. I skimmed through the docs you linked but it doesn't look like they give any examples, but there are plenty here on SO, eg https://stackoverflow.com/questions/30426047/correct-way-to-set-bearer-token-with-curl – Don't Panic May 02 '21 at 08:00
  • Does this answer your question? [Correct way to set Bearer token with CURL](https://stackoverflow.com/questions/30426047/correct-way-to-set-bearer-token-with-curl) – Don't Panic May 02 '21 at 08:01

1 Answers1

1

use curl with authorization header

$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);
nVuln
  • 11
  • 1
  • thank you but it is work on sales order wise. is this not possible to fetch all sales order? also when I use `print_r($response)` it is not show pretty –  May 02 '21 at 07:58
  • read `Request Payload Details` in API document please, `code` for single order or `facilityCodes` for list order – nVuln May 02 '21 at 08:06
  • sir it giving `1619944810000` UTC formate date, can you please chnage in this IST formate –  May 02 '21 at 08:55