Create group order code examples

Bash:

# You can also use wget
curl -X POST https://app.staging.shippit.com/api/3/group_orders \
  -H 'Accept: application/json' \
  -H 'Authorization: API_KEY' \
  --H 'Content-Type: application/json' \
  --data '{ "reference_number": "R12345" }'

HTTP:

POST https://app.staging.shippit.com/api/3/group_orders HTTP/1.1
Host: app.staging.shippit.com
Accept: application/json
Content-Type: application/json
Content-Length: 30

{ "reference_number": "R12345" }

Javascript:

const headers = {
  'Accept':'application/json',
  'Authorization':'API_KEY',
  'Content-Type': 'application/json'
};

const inputBody = '{ { "reference_number": "R12345" } }'

fetch('https://app.staging.shippit.com/api/3/group_orders',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

Ruby:

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'API_KEY',
  'Content-Type' => 'application/json'
}

result = RestClient.post 'https://app.staging.shippit.com/api/3/group_orders',
  params: {
    "reference_number": "R12345"
  }, headers: headers

p JSON.parse(result)

Python:

import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'API_KEY',
  'Content-Type': 'application/json'
}
payload = {
    "reference_number": "R12345"
}

r = requests.post('https://app.staging.shippit.com/api/3/group_orders', headers = headers, data=payload)

print(r.json())

PHP:

<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'API_KEY',
    'Content-Type' => 'application/json'
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = '{
  "reference_number": "R12345"
}';

try {
    $response = $client->request('POST','https://app.staging.shippit.com/api/3/group_orders', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

Java:

URL obj = new URL("https://app.staging.shippit.com/api/3/group_orders");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

Golang:

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Content-Type": []string{"application/json"},
        "Authorization": []string{"API_KEY"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "https://app.staging.shippit.com/api/3/group_orders", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}