# Book Shipment

The `book shipment` endpoint is used to submit your shipping details to the SHiiP operations team for processing. Once your shipment is booked, it is typically attended to within 30 minutes to 3 hours. Please note that this time frame may vary depending on the volume of shipments and operational surges on that particular day.

## Payload&#x20;

Here's the documentation for the payload in a tabular form:&#x20;

<table data-header-hidden><thead><tr><th width="181"></th><th width="99"></th><th width="109"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Type</strong></td><td><strong>Required</strong></td><td><strong>Validation Rules</strong></td><td><strong>Description</strong></td></tr><tr><td><code>redis_key</code></td><td>string</td><td>Yes</td><td>Must be a valid string, gotten from the <a href="get-single-rate">rates</a> response (data->redis_key)</td><td>A unique key for identifying Redis records.</td></tr><tr><td><code>user_id</code></td><td>Integer</td><td>Yes</td><td>Must be a positive integer, gotten from the <a href="get-user-profile">Get User Profile endpoint (id)</a></td><td>The ID of the user initiating the request.</td></tr><tr><td><code>rate_id</code></td><td>string</td><td>Yes</td><td>Must be a valid string, gotten from the <a href="get-single-rate">rates</a> response (data->rates->courier->id)</td><td>A unique identifier for the rate being used.</td></tr><tr><td><code>platform</code></td><td>String</td><td>Yes</td><td>Must be set to<code>web2</code></td><td>Specifies the platform the request originates from.</td></tr><tr><td><code>delivery_note</code></td><td>string</td><td>No</td><td>Must be a string</td><td>Custom order request and instructions</td></tr></tbody></table>

#### Notes:

* **`redis_key`** and **`rate_id`** must be valid UUIDs, ensuring unique, standardized formats.
* **`user_id`** must be a positive integer, representing a valid user in the system.
* **`platform`** must be set to web2, ensure the request comes from an allowed source.

{% hint style="warning" %}
Ensure your wallet is adequately funded before booking a shipment, as we'd be debiting you from there.
{% endhint %}

## Request Sample

{% tabs %}
{% tab title="Curl" %}

```javascript
curl --location 'https://delivery-staging.apiideraos.com/api/v2/token/bookshipment' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer Secrek Key' \
--data '{
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://delivery-staging.apiideraos.com/api/v2/token/bookshipment"

payload = json.dumps({
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer Secrek Key'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "uri"
require "json"
require "net/http"

url = URI("https://delivery-staging.apiideraos.com/api/v2/token/bookshipment")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer Secret Key"
request.body = JSON.dump({
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
})

response = https.request(request)
puts response.read_body

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://delivery-staging.apiideraos.com/api/v2/token/bookshipment',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer Secret Key'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer Secret Key");

const raw = JSON.stringify({
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
});

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: raw,
  redirect: "follow"
};

fetch("https://delivery-staging.apiideraos.com/api/v2/token/bookshipment", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://delivery-staging.apiideraos.com/api/v2/token/bookshipment"
  method := "POST"

  payload := strings.NewReader(`{
  "redis_key": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "user_id": 96,
  "rate_id": "2c89e045-3a84-4316-923a-7729edbe4e21",
  "platform": "web2",
  "delivery_note": "Leave at the reception in my condo"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", "Bearer Secret Key")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}
{% endtabs %}

## Response Sample

{% tabs %}
{% tab title="422" %}

```json
{
    "status": false,
    "message": "The redis key field is required."
}

```

{% endtab %}

{% tab title="200" %}

```json
{
    "data": {
        "reference": "72d4iejm4lg0",
        "shipmentId": 21749,
        "code": 200,
        "status": true
    },
    "status": true,
    "message": "OK",
    "status_code": 200
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "data": [],
    "status": false,
    "message": "Invalid User ID supplied - 10",
    "status_code": 400
}
```

{% endtab %}
{% endtabs %}
