Articles on: Automation Rules

Set Up AfterShip Shipping Rule-Based Label API

Overview



AfterShip's Shipping Rule-based Label API can help you fulfill your orders by auto-selecting the carrier and service type. The API creates shipping labels automatically based on specific rules or conditions. This can automate the label generation process, saving time and reducing manual errors.

Prerequisites



The Rule-based Label API is in Beta testing and only applicable to Enterprise plan users.
Consult with your account executive if you want to test the feature.

How to enable the feature?



Case 1: Set up automation rules based on cheapest or fastest carrier service and specify automatic field in Labels API



Step 1: Set up carrier account



Set up your carrier account in AfterShip Shipping as usual and only enable the preferred services types.

You can add your own accounts to ship using your negotiated rates.
You can start shipping immediately with AfterShip Shipping's discounted rates at up to 89% off.

Step 2: Set up automation rules



Follow this guide to setup your automation rules particularly configure to help to auto-select carriers and service types for your orders if they meet the required conditions.

For example: You can set up rules to automatically select the cheapest or fastest carrier service for orders originating from the US. To set up rules around this scenario.

Select Apply actions to orders that meet certain conditions.
Under conditions, Select Meet all conditions. Proceed to select the Ship from location condition from the dropdown. Select the logic— Is and input the value— US.
Set up the Action > Use carrier/service > Cheapest or Fastest, and specify the delivery speed.

If there are multiple carriers with the same speed, our system will choose the cheapest service to generate shipping labels.
If there are multiple carriers with the same prices, our system will choose the one with the fastest to generate shipping labels.



Step 3: Modify the AfterShip Shipping Label API request



Update the request payload for AfterShip Shipping Label API as suggested below.

a. Remove the fields: shipper_account, service_type
b. Add a field: automatic. Sine it's a boolean field, you are required to use the value true in request payload.

Once the request payload is updated and passed, AfterShip Shipping will check all your preferred services and choose the cheapest service for label generation.

A sample of the request will be as below:

{
    "automatic": true,
    "order_number":"test-order1",
    "shipment": {
        "ship_from": {
            "contact_name": "Test Test",
            "phone": "(111) 111-1234",
            "email": "test@test.com",
            "street1": "2432 Quaking Cove",
            "street2": "Content, Mississippi",
            "city": "New York",
            "postal_code": "10001",
            "state": "NY",
            "country": "USA",
            "type": "residential"
        },
        "ship_to": {
            "contact_name": "xxx Test",
            "phone": "(222) 222-5678",
            "email": "test@test.com",
            "street1": "2432 Quaking Cove",
            "street2": "Content, Mississippi",
            "city": "New York",
            "postal_code": "10001",
            "state": "NY",
            "country": "USA",
            "type": "residential"
        },
        "parcels": [
            {
                "description": "Food XS",
                "box_type": "custom",
                "weight": {
                    "value": 1,
                    "unit": "kg"
                },
                "dimension": {
                    "width": 1,
                    "height": 1,
                    "depth": 1,
                    "unit": "cm"
                },
                "items": [
                    {
                        "description": "Food Bar",
                        "origin_country": "USA",
                        "quantity": 1,
                        "price": {
                            "amount": 500,
                            "currency": "USD"
                        },
                        "weight": {
                            "value": 0.6,
                            "unit": "kg"
                        },
                        "sku": "imac2014"
                    }
                ]
            }
        ]
    }
}


Case 2: Set up automation rules based on the preferred carrier and service and specify the carrier account in Labels API.



Step 1: Set up carrier account



Set up your carrier account in AfterShip Shipping as usual and only enable the preferred services types.

Step 2: Set up automation rules



For example: You can set up rules to automatically select the specified carrier and service type for orders originating from the US. To set up rules around this scenario.

Select Apply actions to orders that meet certain conditions.
Under conditions, Select Meet all conditions. Proceed to select the Ship from location condition from the dropdown. Select the logic— Is and input the value— US.
Set up the Action > Set carrier/service > Set service only > Select the service of your choice



Step 3: Modify the AfterShip Shipping Label API request



Specify the carrier account Id to use in the Labels API request . It refers to the input ID and predefined service to create shipping labels.

A sample of the request will be as below:

{
    "automatic": true,
    "order_number":"test-order1",
    "shipper_account": {
    "id": "11111111-1111-1111-1111-111111111111"
  },
    "shipment": {
        "ship_from": {
            "contact_name": "Test Test",
            "phone": "(111) 111-1234",
            "email": "test@test.com",
            "street1": "2432 Quaking Cove",
            "street2": "Content, Mississippi",
            "city": "New York",
            "postal_code": "10001",
            "state": "NY",
            "country": "USA",
            "type": "residential"
        },
        "ship_to": {
            "contact_name": "xxx Test",
            "phone": "(222) 222-5678",
            "email": "test@test.com",
            "street1": "2432 Quaking Cove",
            "street2": "Content, Mississippi",
            "city": "New York",
            "postal_code": "10001",
            "state": "NY",
            "country": "USA",
            "type": "residential"
        },
        "parcels": [
            {
                "description": "Food XS",
                "box_type": "custom",
                "weight": {
                    "value": 1,
                    "unit": "kg"
                },
                "dimension": {
                    "width": 1,
                    "height": 1,
                    "depth": 1,
                    "unit": "cm"
                },
                "items": [
                    {
                        "description": "Food Bar",
                        "origin_country": "USA",
                        "quantity": 1,
                        "price": {
                            "amount": 500,
                            "currency": "USD"
                        },
                        "weight": {
                            "value": 0.6,
                            "unit": "kg"
                        },
                        "sku": "imac2014"
                    }
                ]
            }
        ]
    }
}



The country field must use a 3-letter ISO country code, following the basic label API format.

In case you have any more questions, our chat support team is just a message away.

Updated on: 12/09/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!