0

I'm sending a HTTP Post request through API to another service to create an order. Problem is, it requires some HTTP parameters that are array within array.

These are the params I'm using now:

"Content-Type: application/json",
"Accept: application/json",
"Stream-Nonce:".$randomstring2,
"Stream-Party:***************",
"Authorization: bearer ".$result_array["access_token"],

and I need to add this:

"header": {
"orderNo": "ABCD123456",
"orderDate": "2018-07-23",
"requiredDate": "2018-07-31",
"partner": {},
"orderType": "DELIVERY",
"serviceLevel": "STANDARD",
"services": [],
"customer": {},
"customerOrderNo": "ABC1234567890",
"orderNotes": "These notes relate to the order",
"driverNotes": "These notes are for the driver",
"routeInfo": "CC05"
},

This is directly from the service I'm using documentation. Problem is with "header": {...}.

I tried doing a different array format, like this:

'Content-Type' => ' application/json',
'Accept' => ' application/json',
'Stream-Nonce' => ''.$randomstring2,
'Stream-Party' => '***************',
'Authorization' => ' bearer '.$result_array['access_token'],

in which case I believe it would be easy to just enter ... => array('yada yada' => 'yada'); however after doing this, the headers don't work at all, I get forbidden message when sending a request.

What can I do here? Thanks.

  • 2
    maybe the second setion is sent by body,not http header.and suggest you use guzzlehttp instead of curl – nay Jun 17 '21 at 08:00
  • Documentation here: https://www.go2stream.net/API/redoc/index.html#tag/Orders/paths/~1orders~1orders/post , it says it's "Request sample" and "Payload" whatever that is, and response table is below it – Rytis Tamošiūnas Jun 17 '21 at 08:03
  • As @nay said, it looks like these aren’t actually HTTP headers. The documentation you linked to there, mentions both `header` and `collection` below `REQUEST BODY SCHEMA`. You simply need to send a JSON structure like it shows in the example there, as the request _body_ content. (`Stream-Nonce` and `Stream-Party` are explicitly listed below `HEADER PARAMETERS` – _those_ are supposed to be HTTP headers.) – CBroe Jun 17 '21 at 09:19

1 Answers1

0

I read the go2stream doc.this is easy while using guzzle.below is example.
if you meet some problem,most maybe wrong post data.
if you have any further question,please comment to me.

// composer require guzzlehttp/guzzle
$client = new \GuzzleHttp\Client();
$headers = [
    // "Content-Type" => "application/json",
    "Stream-Nonce" => $randomstring2,
    "Stream-Party" => $streamParty,
    "Authorization" => "bearer ".$result_array["access_token"],
];
$body = [
    "header" =>  [
        "orderNo" =>  "ABCD123456",
        "orderDate" =>  "2018-07-23",
        "requiredDate" =>  "2018-07-31",
        "partner" =>  [],
        "orderType" =>  "DELIVERY",
        "serviceLevel" =>  "STANDARD",
        "services" =>  [],
        "customer" =>  [],
        "customerOrderNo" =>  "ABC1234567890",
        "orderNotes" =>  "These notes relate to the order",
        "driverNotes" =>  "These notes are for the driver",
        "routeInfo" =>  "CC05"
    ],
    "collection" =>  [
        "address" =>  [
          "name" =>  "Proximity Resourcing Ltd",
          "address1" =>  "6 Kerry Hill",
          "address2" =>  "Off Town Street",
          "address3" =>  "Horsforth",
          "address4" =>  "Leeds",
          "address5" =>  "West Yorkshire",
          "country" =>  "GB",
          "postcode" =>  "LS18 4AY",
          "lat" =>  53.837496,
          "long" =>  -1.640644,
          "nuts" =>  "UKE42",
          "locationNotes" =>  "These notes relate to the location"
        ],
        "contact" =>  [
          "name" =>  "Jane Contact",
          "tel1" =>  "0113 000 0000",
          "tel2" =>  "0113 000 0000",
          "mobile" =>  "07801 000000",
          "fax" =>  "0113 000 0000",
          "email" =>  "sales@go2stream.com"
        ],
        "required" =>  [
          "fromDateTime" =>  "2018-07-31T12 => 00 => 00Z",
          "toDateTime" =>  "2018-08-01T17 => 00 => 00Z"
        ],
        "collectionMethod" =>  "NORTH",
        "timeOnSite" =>  [
          "unload" =>  60,
          "assembly" =>  30
        ],
        "bookingRequired" =>  true,
        "items" =>  [
            [
                "sequence" =>  1,
                "parentSequence" =>  2,
                "code" =>  "ABC123",
                "description" =>  "Widget",
                "quantity" =>  10,
                "weight" =>  150,
                "cube" =>  3.5,
                "assemblyTime" =>  30,
                "stockLocation" =>  "LEEDS",
                "onHandDate" =>  "2017-07-30",
                "packageId" =>  "ABCD1234567890",
                "notes" =>  "Include product manual within packaging.",
                "packageType" =>  "PALLET"
            ]
        ]
    ]
];

$response = $client->request('POST',"https => //www.demo.go2stream.net/api/orders/orders",[
    'headers' => $headers,
    'json' => $body,
]);
nay
  • 1,725
  • 1
  • 11
  • 11