### Fetch Batch Details using Java Source: https://docs.shiphawk.com/ This Java code example shows how to make a GET request to retrieve batch information. It requires the javax.json-1.0.jar library and proper API key substitution. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { // 'bat_mMppjwpG' is an example batch id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/batches/bat_mMppjwpG?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed. Code was " + responseCode); } } } ``` -------------------------------- ### Retrieve Proposed Shipments with Java Source: https://docs.shiphawk.com/ This Java example demonstrates how to make a GET request to retrieve proposed shipments. It includes basic error handling for HTTP response codes. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { // 'ord_RfE8CtKE' is an example order id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/orders/ord_RfE8CtKE/proposed_shipments?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed. Code was " + responseCode); } } } ``` -------------------------------- ### Authentication Example Source: https://docs.shiphawk.com/ This example demonstrates how to authenticate with the ShipHawk API using an API Key in the X-Api-Key header. ```APIDOC ## GET /api/v4/user ### Description Retrieves user information. This endpoint is used to verify authentication and retrieve basic user details. ### Method GET ### Endpoint /api/v4/user ### Parameters #### Headers - **x-api-key** (string) - Required - Your ShipHawk API Key. - **Content-Type** (string) - Required - Set to 'application/json'. ### Request Example ```curl curl --request GET 'https://shiphawk.com/api/v4/user' \ --header 'Content-Type: application/json' \ --header 'x-api-key: YOUR_API_KEY' ``` ### Response #### Success Response (200) - **user_id** (number) - The unique identifier for the user. - **email** (string) - The email address associated with the user account. - **name** (string) - The name of the user. #### Response Example ```json { "user_id": 12345, "email": "user@example.com", "name": "John Doe" } ``` ``` -------------------------------- ### Retrieve an Address by ID using Java Source: https://docs.shiphawk.com/ This Java example shows how to make a GET request to retrieve address details. Replace 'YOUR_API_KEY' with your credentials and ensure you have the javax.json-1.0.jar library. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { // 'adr_W7NQxx48' is an example address id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/addresses/adr_W7NQxx48?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed. Code was " + responseCode); } } } ``` -------------------------------- ### Start Bulk SKU Import Source: https://docs.shiphawk.com/ Initiates a bulk import of multiple SKUs, accepting a list of SKU objects. ```APIDOC ## POST /api/v4/bulk_sku_imports ### Description Starts a bulk SKU import. ### Method POST ### Endpoint /api/v4/bulk_sku_imports ### Parameters #### Request Body - **skus** (Array[Sku]) - required - A list of SKU Object to import (up to 1000 objects) ### Request Example ```json { "skus": [ { "sku": "T001", "name": "T-Shirt 1", "description": "Regular fit t-shirt", "price": "20.0", "items": [ { "quantity": 1, "length": 2, "width": 1, "height": 1, "weight": 0.5, "item_type": "parcel" } ] }, { "sku": "T002", "name": "T-Shirt 2", "description": "Regular fit t-shirt", "price": "20.0", "items": [ { "quantity": 1, "length": 2, "width": 1, "height": 1, "weight": 0.5, "item_type": "parcel" } ] } ] } ``` ### Response #### Success Response (200) - **Import Status** (Object) - Status of the initiated import. ``` -------------------------------- ### Retrieve Pick Ticket for an Order using Java Source: https://docs.shiphawk.com/ This Java example shows how to get an order's pick ticket using standard Java networking. Include 'javax.json-1.0.jar' and replace 'YOUR_API_KEY' with your actual ShipHawk API key. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { // 'ord_mbX920Mg' is an example order id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/orders/ord_mbX920Mg/pick_ticket?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed."); } } } ``` -------------------------------- ### List All Shipments with Python Source: https://docs.shiphawk.com/ This Python script utilizes the requests library to fetch all shipments. Make sure the 'requests' library is installed (`pip install requests`). ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/shipments' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### HazmatData Object Examples Source: https://docs.shiphawk.com/ Provides examples for the HazmatData object, including Hazmat, Limited Quantity, Excepted Quantity, and Lithium Batteries. ```APIDOC ## Rate HazmatData Object ### Example: Hazmat ```json { "container": "Fiberboard Box", "additional_description": "some additional description", "emergency_contact_phone_number": "800-424-9300", "battery_types": [], "packing_group": "II", "emergency_response_phone_number": null, "amount_unit": "l", "technical_name": "Propanone", "regulation_set": "CFR", "proper_shipping_name": "Acetone", "hazard_class_or_division": "3", "transportation_mode": "ground", "amount": "1", "emergency_contact_name": "CHEMTREC", "dangerous_goods_type": "hazmat", "packing_instructions": null, "un_or_na_number": "UN1090" // ..., "hazmat_data": { "dangerous_goods_type": "hazmat", "un_or_na_number": "UN1090", "proper_shipping_name": "Acetone", "technical_name": "Propanone", "hazard_class_or_division": "3", "packing_group": "II", "container": "Fiberboard Box", "amount": "10", "amount_unit": "L", "regulation_set": "CFR", "transportation_mode": "ground", "emergency_contact_name": "CHEMTREC (USA) CCN 1883", "emergency_contact_phone_number": "800-424-9300", "additional_description": "some additional description", "battery_types": [] }, // ..., } ``` ### Example: Limited Quantity ```json { // ..., "hazmat_data": { "dangerous_goods_type": "limited_quantity" }, // ..., } ``` ### Example: Excepted Quantity ```json { // ..., "hazmat_data": { "dangerous_goods_type": "excepted_quantity" }, // ..., } ``` ### Example: Lithium Batteries ```json { // ..., "hazmat_data": { "dangerous_goods_type": "lithium_batteries", "battery_types": ["lithium_ion_packed_with_equipment"] }, // ..., } ``` ``` -------------------------------- ### Order HazmatData Object - Lithium Batteries Example Source: https://docs.shiphawk.com/ This example defines the structure for 'lithium_batteries' dangerous goods. It requires specifying the dangerous goods type and the relevant battery types. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "lithium_batteries", "battery_types": ["lithium_ion_packed_with_equipment"] }, // ..., } ``` -------------------------------- ### Combine Orders Asynchronously (cURL) Source: https://docs.shiphawk.com/ Examples of using cURL to combine orders asynchronously. One example shows combining specific order IDs, and another implies combining all items. ```curl #`ord_2E1pWGRh` is an example order id # Split order to New order curl POST 'https://sandbox.shiphawk.com/api/v4/orders/ord_2E1pWGRh/split_async?api_key=YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ "new_order_number": "ORD10100112", "order_line_items": [ { "id": "ordi_NmDJkZWj", "quantity": 1 } ] }' # Split order to Existing order curl POST 'https://sandbox.shiphawk.com/api/v4/orders/ord_2E1pWGRh/split_async?api_key=YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ "move_to_order_id": "ord_F2gvqhR2", "order_line_items": [ { "id": "ordi_NmDJkZWj", "quantity": 1 } ] }' ``` -------------------------------- ### Lithium Batteries Hazmat Data Example Source: https://docs.shiphawk.com/ This example demonstrates the HazmatData object configuration for shipments containing lithium batteries, including the required 'battery_types' array. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "lithium_batteries", "battery_types": ["lithium_ion_packed_with_equipment"] }, // ..., } ``` -------------------------------- ### Rate Response Object Example Source: https://docs.shiphawk.com/ This is an example of a Rate Response object, which contains a list of available shipping rates. Each rate includes details like carrier, service name, price, and estimated delivery date. ```json { "rates": [ { "id": "rate_6ZPt6R1fSsSg8FXvq0zSGPwD", "carrier": "USPS", "carrier_code": "usps", "tariff_insurance_rule": "carrier", "service_name": "First-Class Mail", "service_level": "First-Class Mail", "standardized_service_name": "Ground", "rate_display_name": "USPS First-Class Mail", "price": "4.19", "currency_code": "USD", "est_delivery_date": "2019-01-23T00:00:00.000-06:00", "est_delivery_time": null, "service_days": 3, "origin_network_location_id": null, "destination_network_location_id": null, "carrier_quote_number": null }, { "id": "rate_fG2f45GaBQH0c4XS1vgNybsD", "carrier": "USPS", "carrier_code": "usps", "tariff_insurance_rule": "carrier", "service_name": "Priority Mail", "service_level": "Priority Mail", "standardized_service_name": "Ground", "rate_display_name": "USPS Priority Mail", "price": "7.99", "currency_code": "USD", "est_delivery_date": "2019-01-22T00:00:00.000-06:00", "est_delivery_time": null, "service_days": 2, "origin_network_location_id": null, "destination_network_location_id": null, "carrier_quote_number": "123456789" } ] } ``` -------------------------------- ### Get All Webhooks Source: https://docs.shiphawk.com/ Retrieves a list of all configured webhooks for your account. ```APIDOC ## GET /api/v4/webhooks ### Description Retrieves a list of all configured webhooks. ### Method GET ### Endpoint /api/v4/webhooks/ ### Request Example ```bash curl -X GET -H "X-Api-Key: YOUR_API_KEY" "https://sandbox.shiphawk.com/api/v4/webhooks/" ``` ### Response #### Success Response (200) - **id** (String) - Unique identifier for the webhook. - **events** (Array[String]) - List of events the webhook is subscribed to. - **callback_url** (String) - The URL to which webhook events will be sent. - **created_at** (String) - Timestamp when the webhook was created. #### Response Example ```json { "id": "wh_6vh3AegY", "events": [ "shipment.status_update", "shipment.tracking_update" ], "callback_url": "http://requestb.in/1khurll1", "created_at": "2016-12-28T11:59:15Z" } ``` ``` -------------------------------- ### Order HazmatData Object - Hazmat Example Source: https://docs.shiphawk.com/ This example demonstrates the structure for 'hazmat' dangerous goods. It includes detailed information required for hazardous material transportation, such as UN number, proper shipping name, and hazard class. ```json { "container": "Fiberboard Box", "additional_description": "some additional description", "emergency_contact_phone_number": "800-424-9300", "battery_types": [], "packing_group": "II", "emergency_response_phone_number": null, "amount_unit": "l", "technical_name": "Propanone", "regulation_set": "CFR", "proper_shipping_name": "Acetone", "hazard_class_or_division": "3", "transportation_mode": "ground", "amount": "1", "emergency_contact_name": "CHEMTREC", "dangerous_goods_type": "hazmat", "packing_instructions": null, "un_or_na_number": "UN1090" // ..., "hazmat_data": { "dangerous_goods_type": "hazmat", "un_or_na_number": "UN1090", "proper_shipping_name": "Acetone", "technical_name": "Propanone", "hazard_class_or_division": "3", "packing_group": "II", "container": "Fiberboard Box", "amount": "10", "amount_unit": "L", "regulation_set": "CFR", "transportation_mode": "ground", "emergency_contact_name": "CHEMTREC (USA) CCN 1883", "emergency_contact_phone_number": "800-424-9300", "additional_description": "some additional description", "battery_types": [], }, // ..., } ``` -------------------------------- ### Get List of Created Webhooks Source: https://docs.shiphawk.com/ Retrieves a list of all currently configured webhooks. ```APIDOC ## GET /api/v4/webhooks ### Description Retrieves a list of all webhooks that have been created and configured. ### Method GET ### Endpoint /api/v4/webhooks ``` -------------------------------- ### Create a Webhook Source: https://docs.shiphawk.com/ Set up a new webhook by providing a callback URL and a list of events to subscribe to. This POST request requires your API key and specifies the events and the URL where notifications should be sent. ```bash curl -X POST -H "X-Api-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{"callback_url": "http://requestb.in/1khurll1", "events":["shipment.status_update","shipment.tracking_update"]}' "https://sandbox.shiphawk.com/api/v4/webhooks" ``` -------------------------------- ### Retrieve Parcel Shipment Label URL with Python Source: https://docs.shiphawk.com/ This Python script uses the 'requests' library to get the parcel shipment label URL. Make sure to install the library (`pip install requests`). ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/shipments/shp_8Wskd61X/labels' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### Retrieve Address Label PDF URL with Python Source: https://docs.shiphawk.com/ This Python script uses the 'requests' library to get the address label PDF URL. Make sure to install the library (`pip install requests`). ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/shipments/shp_8Wskd61X/address_labels' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### Create SKU Source: https://docs.shiphawk.com/ Use this endpoint to create a new SKU. Ensure all required fields, including item details, are provided. ```bash curl -H "Content-Type: application/json" -X POST -d ' { "sku": "T001", "name": "T-Shirt 1", "description": "Regular fit t-shirt", "image_url": "https://example.com/t-shirt.jpg", "price": "20.0", "items": [ { "quantity": 1, "length": 2, "width": 1, "height": 1, "weight": 1, "description": "Some description", "value": 150, "item_type": "parcel", "commodity_description": "Some commodity description", "country_of_manufacture: "CN", "harmonized_codes": [ { "country_code": "UA", "harmonized_code: "123.123.123", }, { "country_code": "DE", "harmonized_code: "333.333.333", }, { "country_code": "", "harmonized_code: "111.111.111", } ] } ], }' 'https://sandbox.shiphawk.com/api/v4/skus?api_key=YOUR_API_KEY' ``` -------------------------------- ### Retrieve an Address using cURL Source: https://docs.shiphawk.com/ This example shows how to retrieve a specific address using a GET request with cURL. Replace 'adr_ddstab0m' with the actual address ID and 'YOUR_API_KEY' with your API key. ```bash # 'adr_ddstab0m' is an example address id. curl -H "Content-Type: application/json" -X GET 'https://sandbox.shiphawk.com/api/v4/addresses/adr_ddstab0m?api_key=YOUR_API_KEY' ``` -------------------------------- ### Create a Batch with Java Source: https://docs.shiphawk.com/ A Java example for creating a batch using HttpURLConnection. Replace 'YOUR_API_KEY' with your ShipHawk API key and ensure the Content-Type header is set. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class PostRequestsSimple { public static void main(String [] args) { try{ sendPost(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendPost() throws IOException { URL url = new URL("https://sandbox.shiphawk.com/api/v4/batches?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_CREATED){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("POST request failed. Code was " + responseCode); } } } ``` -------------------------------- ### Start Bulk SKU Import Source: https://docs.shiphawk.com/ Initiate a bulk import of SKUs. This endpoint accepts an array of SKU objects, with a limit of up to 1000 objects per request. ```bash curl -H "Content-Type: application/json" -X POST -d ' { "skus": [ { "sku": "T001", "name": "T-Shirt 1", "description": "Regular fit t-shirt", "price": "20.0", "items": [ { "quantity": 1, "length": 2, "width": 1, "height": 1, "weight": 0.5, "item_type": "parcel" } ] }, { "sku": "T002", "name": "T-Shirt 2", "description": "Regular fit t-shirt", "price": "20.0", "items": [ { "quantity": 1, "length": 2, "width": 1, "height": 1, "weight": 0.5, "item_type": "parcel" } ] } ] }' 'https://sandbox.shiphawk.com/api/v4/bulk_sku_imports?api_key=YOUR_API_KEY' ``` -------------------------------- ### Retrieve an Order using Python Source: https://docs.shiphawk.com/ This Python snippet uses the 'requests' library to get order information. Make sure to install the library and replace 'YOUR_API_KEY' with your actual ShipHawk API key. ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/orders/ord_mSCP9was' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### Retrieve BOL PDF URL using Python Source: https://docs.shiphawk.com/ This Python script uses the requests library to get the Bill of Lading PDF URL. Make sure to install the requests library if you haven't already. ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/shipments/shp_8Wskd61X/bol' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### Retrieve All Batches with Java Source: https://docs.shiphawk.com/ A Java example demonstrating how to retrieve all batches using HttpURLConnection. Make sure to replace 'YOUR_API_KEY' with your ShipHawk API key. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { URL url = new URL("https://sandbox.shiphawk.com/api/v4/batches?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed. Code was " + responseCode); } } } ``` -------------------------------- ### Place Orders on Hold (Java) Source: https://docs.shiphawk.com/ A Java example demonstrating how to place orders on hold using JSON processing and HTTP requests. Requires javax.json-1.0.jar. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; import javax.json.*; import javax.script.*; public class PostRequests { public static void main(String [] args) { try{ sendPost(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendPost() throws IOException { JsonObject personObject = Json.createObjectBuilder() .add("ids", Json.createArrayBuilder() .add("ord_2E1pWGRh") .add("ord_DqKvSb9M") ) .add("hold_until", "2019-01-30T23:16:34+00:00") .build(); try{ // For formatting json object to be readable ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("JavaScript"); scriptEngine.put("jsonString", personObject.toString()); scriptEngine.eval("result = JSON.Stringify(JSON.parse(jsonString), null, 2)"); String prettyPrintedJson = (String) scriptEngine.get("result"); URL url = new URL("https://sandbox.shiphawk.com/api/v4/orders/hold?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); OutputStream os = con.getOutputStream(); os.write(personObject.toString().getBytes()); os.flush(); os.close(); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("POST request failed. Code was " + responseCode); System.out.println("Body form:\n" + prettyPrintedJson); } } catch(NullPointerException ex){ ex.printStackTrace(System.out); } catch(ScriptException ex){ ex.printStackTrace(System.out); } } } ``` -------------------------------- ### Create a Webhook Source: https://docs.shiphawk.com/ Use this endpoint to create a new webhook subscription. Specify the events you want to receive and the callback URL. ```bash curl -X POST -H "X-Api-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{"callback_url": "http://requestb.in/197klsd1", "events":["shipment.timing_update", "shipment.tracking_update"]}' "https://sandbox.shiphawk.com/api/v4/webhooks/" ``` -------------------------------- ### Send POST Request with Java Source: https://docs.shiphawk.com/ This Java example demonstrates how to send a POST request to split an order asynchronously. It includes JSON formatting and handling HTTP responses. Note that `javax.json-1.0.jar` is required. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; import javax.json.*; import javax.script.*; public class PostRequests { public static void main(String [] args) { try{ sendPost(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendPost() throws IOException { JsonObject personObject = Json.createObjectBuilder() .add("order_number", "ORD101001111") .add("order_line_items", Json.createArrayBuilder()) .build(); try{ // For formatting json object to be readable ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("JavaScript"); scriptEngine.put("jsonString", personObject.toString()); scriptEngine.eval("result = JSON.Stringify(JSON.parse(jsonString), null, 2)"); String prettyPrintedJson = (String) scriptEngine.get("result"); // 'ord_JKAyGya4' is an example order id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/orders/ord_JKAyGya4/split_async?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); OutputStream os = con.getOutputStream(); os.write(personObject.toString().getBytes()); os.flush(); os.close(); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("POST request failed. Code was " + responseCode); System.out.println("Body form:\n" + prettyPrintedJson); } } catch(NullPointerException ex){ ex.printStackTrace(System.out); } catch(ScriptException ex){ ex.printStackTrace(System.out); } } } ``` -------------------------------- ### Excepted Quantity Hazmat Data Example Source: https://docs.shiphawk.com/ This example illustrates the basic structure for the HazmatData object when the dangerous goods type is 'excepted_quantity'. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "excepted_quantity" }, // ..., } ``` -------------------------------- ### Get List of Created Webhooks Source: https://docs.shiphawk.com/ Fetch a list of all webhooks that have been previously created. This GET request requires your API key for authentication. ```bash curl -X GET -H "X-API-KEY: YOUR_API_KEY" "https://sandbox.shiphawk.com/api/v4/webhooks" ``` -------------------------------- ### Create a Batch with cURL Source: https://docs.shiphawk.com/ This cURL command demonstrates how to create a new batch. It requires setting the Content-Type header and includes an example response. ```bash curl -H "Content-Type: application/json" -X POST 'https://sandbox.shiphawk.com/api/v4/batches?api_key=YOUR_API_KEY' ``` -------------------------------- ### Create User Source: https://docs.shiphawk.com/ Creates a new user. The request body must be in JSON format and include required fields like email and password. ```bash curl -H "Content-Type: application/json" -X POST -d ' { “email”: “mikel@shiphawk.com”, “password”: “MwLtNFV”, “first_name”: “Mikel”, “last_name”: “Richardson”, “warehouse_ids”: ["mc_n7nJ5XjQ"] } ' ‘https://sandbox.shiphawk.com/api/v4/users?api_key=YOUR_API_KEY' ``` -------------------------------- ### Limited Quantity Hazmat Data Example Source: https://docs.shiphawk.com/ This example shows the minimal structure for the HazmatData object when the dangerous goods type is set to 'limited_quantity'. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "limited_quantity" }, // ..., } ``` -------------------------------- ### Create Document using Python Source: https://docs.shiphawk.com/ This Python script shows how to create a document for a shipment using the `requests` library. Replace `shp_10RCpAYY` with your shipment ID and `YOUR_API_KEY` with your API key. The `files` parameter should be the path to the document. ```python import requests import json # 'shp_10RCpAYY' is an example shipment id. url = 'https://sandbox.shiphawk.com/api/v4/shipments/shp_10RCpAYY/documents' headers = {'X-Api-Key': 'YOUR_API_KEY'} payload = { "files": "path_to_file" } r = requests.post(url, headers=headers, json=payload) ``` -------------------------------- ### Get Available Webhook Events Source: https://docs.shiphawk.com/ Retrieve a list of all available events that can trigger a webhook. This GET request requires your API key for authentication. ```bash curl -X GET -H "X-Api-Key: YOUR_API_KEY" "https://sandbox.shiphawk.com/api/v4/webhooks/events" ``` -------------------------------- ### Get Orders by Source System (Python) Source: https://docs.shiphawk.com/ This Python snippet shows how to fetch orders using the requests library, specifying the 'NetSuite' source system and providing the API key in the headers. ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/orders/simple?source_system=NetSuite' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.get(url, headers=headers) ``` -------------------------------- ### Inventory Identifiers Array Example Source: https://docs.shiphawk.com/ An example of an array of inventory identifiers, used to specify serial numbers or lot numbers for order line items. ```json // Inventory Identfiers array example [ { "code": "ML31", "source_system_id": "544", "type": "SerialNumber" }, { "code": "ML32", "source_system_id": "545", "type": "SerialNumber" } ] ``` -------------------------------- ### Create User Source: https://docs.shiphawk.com/ Creates a new user account. ```APIDOC ## POST /api/v4/users ### Description Creates a new user account. ### Method POST ### Endpoint /api/v4/users ### Parameters #### Request Body - **email** (String) - The email address for the new user. - **password** (String) - The password for the new user. - **first_name** (String) - The first name of the new user. - **last_name** (String) - The last name of the new user. - **warehouse_ids** (Array[String]) - Assigns the user to specific Warehouse(s). ### Response #### Success Response (201) - **User** (Object) - Information about the newly created user. ``` -------------------------------- ### Create Document using Ruby Source: https://docs.shiphawk.com/ This Ruby script demonstrates how to create a document for a shipment. Ensure you have the `net/http`, `uri`, and `json` libraries. Replace `shp_10RCpAYY` with your shipment ID and `YOUR_API_KEY` with your API key. The `files` parameter specifies the path to the document. ```ruby require 'net/http' require 'uri' require 'json' # 'shp_10RCpAYY' is an example shipment id. uri = URI.parse('https://sandbox.shiphawk.com/api/v4/shipments/shp_10RCpAYY/documents?api_key=YOUR_API_KEY') document = '{ "files": "path_to_file" }' # Create the HTTP objects request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') request.body = document # Send the request response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Send POST Request to Create Document (Python) Source: https://docs.shiphawk.com/ This Python script demonstrates how to send a POST request to create a document. Replace 'YOUR_API_KEY' with your valid API key. ```Python import requests import json url = 'https://sandbox.shiphawk.com/api/v4/shipments/shp_10RCpAYY/documents/doc_aM5pCQ2A' headers = {'X-Api-Key': 'YOUR_API_KEY'} payload = { "type":"other" } r = requests.post(url, headers=headers, json=payload) ``` -------------------------------- ### Order HazmatData Object - Excepted Quantity Example Source: https://docs.shiphawk.com/ This example illustrates the structure for 'excepted_quantity' dangerous goods. Similar to limited quantity, only the dangerous goods type is essential. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "excepted_quantity" }, // ..., } ``` -------------------------------- ### Order HazmatData Object - Limited Quantity Example Source: https://docs.shiphawk.com/ This example shows the minimal structure required for 'limited_quantity' dangerous goods. Only the dangerous goods type needs to be specified. ```json { // ..., "hazmat_data": { "dangerous_goods_type": "limited_quantity" }, // ..., } ``` -------------------------------- ### List All Shipments with Java Source: https://docs.shiphawk.com/ This Java code demonstrates how to make a GET request to list all shipments. It requires the javax.json-1.0.jar library and handles potential IOExceptions. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; public class GetRequests { public static void main(String [] args) { try{ sendGet(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendGet() throws IOException { URL url = new URL("https://sandbox.shiphawk.com/api/v4/shipments?api_key=YOUR_API_KEY&source_system=NetSuite"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("GET request failed."); } } } ``` -------------------------------- ### Delete Document from Shipment (curl) Source: https://docs.shiphawk.com/ This command-line example shows how to delete a document from a shipment using a DELETE request. Replace the example IDs and API key with your actual values. ```curl #'shp_nhMNNzwQ' is an example shipment id and 'doc_q04Sx49Z' is an example document id. curl -X DELETE 'https://sandbox.shiphawk.com/api/v4/shipments/shp_nhMNNzwQ/documents/doc_q04Sx49Z?api_key=YOUR_API_KEY' ``` -------------------------------- ### Create Document using Java Source: https://docs.shiphawk.com/ This Java code snippet demonstrates creating a document for a shipment. It uses `javax.json` for JSON handling and `HttpURLConnection` for the POST request. Replace `shp_Zm7B5cVm` with your shipment ID and `YOUR_API_KEY` with your API key. The `files` parameter indicates the path to the document. ```java // Running with javax.json-1.0.jar import java.io.*; import java.net.*; import javax.json.*; import javax.script.*; public class PostRequests { public static void main(String [] args) { try{ sendPost(); } catch(IOException ex){ ex.printStackTrace(System.out); } } private static void sendPost() throws IOException { JsonObject personObject = Json.createObjectBuilder() .add("files", "path_to_file") .build(); try{ // For formatting json object to be readable ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine scriptEngine = manager.getEngineByName("JavaScript"); scriptEngine.put("jsonString", personObject.toString()); scriptEngine.eval("result = JSON.stringify(JSON.parse(jsonString), null, 2)"); String prettyPrintedJson = (String) scriptEngine.get("result"); // 'shp_Zm7B5cVm' is an example shipment id. URL url = new URL("https://sandbox.shiphawk.com/api/v4/shipments/shp_Zm7B5cVm/documents?api_key=YOUR_API_KEY"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); OutputStream os = con.getOutputStream(); os.write(personObject.toString().getBytes()); os.flush(); os.close(); int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK){ BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content.toString()); } else{ System.out.println("POST request failed. Code was " + responseCode); System.out.println("Body form:\n" + prettyPrintedJson); } } catch(NullPointerException ex){ ex.printStackTrace(System.out); } catch(ScriptException ex){ ex.printStackTrace(System.out); } } } ``` -------------------------------- ### Create a Batch with Python Source: https://docs.shiphawk.com/ This Python script uses the requests library to create a batch. Ensure you replace 'YOUR_API_KEY' with your valid API key. ```python import requests url = 'https://sandbox.shiphawk.com/api/v4/batches' headers = {'X-Api-Key': 'YOUR_API_KEY'} r = requests.post(url, headers=headers) ``` -------------------------------- ### Hazmat Data Object Example Source: https://docs.shiphawk.com/ This example demonstrates the structure of the HazmatData object when the dangerous goods type is 'hazmat'. It includes all required fields for a standard hazardous material shipment. ```json { "container": "Fiberboard Box", "additional_description": "some additional description", "emergency_contact_phone_number": "800-424-9300", "battery_types": [], "packing_group": "II", "emergency_response_phone_number": null, "amount_unit": "l", "technical_name": "Propanone", "regulation_set": "CFR", "proper_shipping_name": "Acetone", "hazard_class_or_division": "3", "transportation_mode": "ground", "amount": "1", "emergency_contact_name": "CHEMTREC", "dangerous_goods_type": "hazmat", "packing_instructions": null, "un_or_na_number": "UN1090" // ..., "hazmat_data": { "dangerous_goods_type": "hazmat", "un_or_na_number": "UN1090", "proper_shipping_name": "Acetone", "technical_name": "Propanone", "hazard_class_or_division": "3", "packing_group": "II", "container": "Fiberboard Box", "amount": "10", "amount_unit": "L", "regulation_set": "CFR", "transportation_mode": "ground", "emergency_contact_name": "CHEMTREC (USA) CCN 1883", "emergency_contact_phone_number": "800-424-9300", "additional_description": "some additional description", "battery_types": [], }, // ..., } ```