Vehicle Rate REST API routes

Vehicle rate add on haw two available API routes, “Vehicles” which you can get all the rates for all vehicles and “Vehicle” which we can get rates for specific vehicle.

How to use “Vehicles” API route?

mysite.com/wp-json/wpcargo/v1/api/{api_key}/vehicles

This route accepts two parameters, “pickup” which is the address where the Package it to pickup and “destination” which the item address to deliver. the method we will use to send request is “POST” request.

Sample request response:

{
    "status": "OK",
    "results": {
        "Motorcycle": {
            "distance": "42.4 km",
            "duration": "1 Hour 18 Minutes",
            "rate": "474"
        },
        "SUV Express": {
            "distance": "42.4 km",
            "duration": "1 Hour 18 Minutes",
            "rate": "945.1999999999999"
        },
        "motorcycle": {
            "distance": "42.4 km",
            "duration": "1 Hour 18 Minutes",
            "rate": "661"
        }
    }
}

Sample PHP Code to get the all available Vehicles from pickup to destination



    $url = 'https://www.mydomain.com/wp-json/wpcargo/v1/api/{my_api_key_heare}/vehicles/';
    $response = wp_remote_post( $url, array(
        'method'      => 'POST',
        'body'        => array(
            'pickup' => 'san pedro laguna', // pickup Location
            'destination' => 'malate manila', // Destination Location
        ),
    ) );
     
    if ( is_wp_error( $response ) ) {
        $error_message = $response->get_error_message();
        echo "Something went wrong: $error_message";
    } else {
        echo 'Response:<pre>';
        print_r( $response['body'] );
        echo '</pre>';
    }


How to use “Vehicle” API route?

mysite.com/wp-json/wpcargo/v1/api/{api_key}/vehicle

This route accepts three parameters, “pickup” which is the address where the Package it to pickup and “destination” which the item address to deliver and “vehicle” which is the type of vehicle. the method we will use to send request is “POST” request.

Sample request response:

{
    "status": "OK",
    "results": {
        "Motorcycle": {
            "distance": "26.4 mi",
            "duration": "1 Hour 18 Minutes",
            "rate": "314"
        },
        "motorcycle": {
            "distance": "26.4 mi",
            "duration": "1 Hour 18 Minutes",
            "rate": "421"
        }
    }
}

Sample PHP Code to get the rate per Vehicle from pickup to destination



    $url = 'https://www.mydomain.com/wp-json/wpcargo/v1/api/{my_api_key_heare}/vehicle/';
    $response = wp_remote_post( $url, array(
        'method'      => 'POST',
        'body'        => array(
            'pickup' => 'san pedro laguna', // pickup Location
            'destination' => 'malate manila', // Destination Location
            'vehicle' => 'Motorcycle' // vehicle type
        ),
        )
    );
     
    if ( is_wp_error( $response ) ) {
        $error_message = $response->get_error_message();
        echo "Something went wrong: $error_message";
    } else {
        echo 'Response:<pre>';
        print_r( $response['body'] );
        echo '</pre>';
    }


Note: Google Map API Key needs to enable the following API’s to make it work.

  1. Places API
  2. Maps JavaScript API
  3. Geolocation API
  4. Geocoding API
0
    0
    Your Cart
    Your cart is emptyReturn to Shop