Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRatesWithShipmentDetails #63

Open
wentao709 opened this issue Jul 10, 2023 · 6 comments
Open

getRatesWithShipmentDetails #63

wentao709 opened this issue Jul 10, 2023 · 6 comments

Comments

@wentao709
Copy link

Hi Devs,

I'm having trouble with this API: getRatesWithShipmentDetails

I'm calling it like this:

const shipEngineResults = await shipengine.getRatesWithShipmentDetails(shippingInfo);

where shippingInfo = {
rateOptions: {
carrierIds: [ 'se-2884143', 'se-2884144', 'se-2884146' ],
serviceCodes: []
},
shipment: {
validateAddress: 'validate_only',
confirmation: 'none',
shipFrom: {
name: 'Tom Hanks',
phone: '7146129169',
postalCode: '93306',
companyName: 'Test Company',
countryCode: 'US',
addressLine1: '3218 Kaibab Avenue',
addressLine2: '',
cityLocality: 'Bakersfield',
stateProvince: 'CA',
addressResidentialIndicator: 'no'
},
shipTo: {
name: 'Nxtlives Dev',
phone: null,
addressLine1: '800 W 6th St',
addressLine2: null,
cityLocality: 'Los Angeles',
stateProvince: 'CA',
countryCode: 'US',
postalCode: '90017'
},
packages: [ [Object] ]
}
}

Sometimes I get the error saying {
err: ShipEngineError: The ShipEngine /v1/rates API timed out.
at sendRequestWithRetry (/Users/wentaozhou/Documents/GitHub/nextsite_server/node_modules/shipengine/cjs/client/index.js:44:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.post (/Users/wentaozhou/Documents/GitHub/nextsite_server/node_modules/shipengine/cjs/client/index.js:14:12)
at async Object.getRatesWithShipmentDetails (/Users/wentaozhou/Documents/GitHub/nextsite_server/node_modules/shipengine/cjs/get-rates-with-shipment-details/index.js:17:22)
at async itemShipping (file:///Users/wentaozhou/Documents/GitHub/nextsite_server/utils/order.js:1109:31)
at async file:///Users/wentaozhou/Documents/GitHub/nextsite_server/controllers/orderController.js:1579:26
at async Promise.all (index 0)
at async get_cart_shipping (file:///Users/wentaozhou/Documents/GitHub/nextsite_server/controllers/orderController.js:1569:23) {
source: 'shipengine',
type: 'system',
code: 'timeout',
requestID: undefined,
url: URL {
href: 'https://www.shipengine.com/docs/errors/codes/',
origin: 'https://www.shipengine.com/',
protocol: 'https:',
username: '',
password: '',
host: 'www.shipengine.com',
hostname: 'www.shipengine.com',
port: '',
pathname: '/docs/errors/codes/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
}
}

Please note that this error does not happen every time I call it using the same json input. I would say there's a 50% chance that the error occurs, and other times the call is successful. do you know why this occurs?

Thanks,
Wentao Zhou

@AnneOReilly
Copy link
Member

Hey @wentao709 ! It looks like you're running the default timeout frame of 5 seconds. In Sandbox, it's common for carriers not to meet this timeframe. You can modify the timeout for the SDK as a configuration variable. 60 seconds will be the maximum.

/// <param name="timeout">The timespan to wait before the request times out. Defaults to 5 seconds</param>

@wentao709
Copy link
Author

hi, what is the right way to change the timeout?

@AnneOReilly
Copy link
Member

AnneOReilly commented Jul 18, 2023

@wentao709 You can set timeout as a parameter at the same place in your code where you are setting the API key.

For example, if you are instantiating your config object like this:
var config = new Config(apiKey: apiKeyString);
Then you can make this adjustment:
var config = new Config(apiKey: apiKeyString, timeout: 60);

@wentao709
Copy link
Author

sorry I guess my question is how do I import ShipEngineConfig from the node module?
I can import shipengine as
import Shipengine from 'shipengine';

not sure how to import ShipEngineConfig to my node.js server

@brandonraphael
Copy link

brandonraphael commented Jul 20, 2023

Hey @AnneOReilly, I'm also working with @wentao709 on this, thanks for the assistance. We have configured shipEngine to have a 60 second timeout now in js:

const shipEngineConfig = {
  apiKey: config.shipengineKey,
  timeout: 60,
};
const shipengine = new ShipEngine(shipEngineConfig);

Below is the ship engine config (JSON stringified) at the time of call to /v1/rates using the the function:
const shipEngineResults = await shipengine.getRatesWithShipmentDetails(shipment);

Ship Engine config:

 ShipEngine {
   config: NormalizedConfig {
     apiKey: 'XXXXXXXXXXXXXXX',
     baseURL: URL {
       href: 'https://api.shipengine.com/',
       origin: 'https://api.shipengine.com',
       protocol: 'https:',
       username: '',
       password: '',
       host: 'api.shipengine.com',
       hostname: 'api.shipengine.com',
       port: '',
       pathname: '/',
       search: '',
       searchParams: URLSearchParams {},
       hash: ''
     },
     pageSize: 50,
     retries: 1,
     timeout: 60
   }
 }

We are still seeing the same timeout error with that config:

 itemShipping Error  ShipEngineError: The ShipEngine /v1/rates API timed out.
     at sendRequestWithRetry (/home/ec2-user/NxtLives/nextsite_server/node_modules/shipengine/cjs/client/index.js:44:23)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)
     at async Object.post (/home/ec2-user/NxtLives/nextsite_server/node_modules/shipengine/cjs/client/index.js:14:12)
     at async Object.getRatesWithShipmentDetails (/home/ec2-user/NxtLives/nextsite_server/node_modules/shipengine/cjs/get-rates-with-shipment-details/index.js:17:22)
     at async itemShipping (file:///home/ec2-user/NxtLives/nextsite_server/utils/order.js:1129:31)
     at async file:///home/ec2-user/NxtLives/nextsite_server/controllers/orderController.js:1646:26
     at async Promise.all (index 0)
     at async get_cart_shipping (file:///home/ec2-user/NxtLives/nextsite_server/controllers/orderController.js:1636:23) {
   source: 'shipengine',
   type: 'system',
   code: 'timeout',
   requestID: undefined,
   url: URL {
     href: 'https://www.shipengine.com/docs/errors/codes/',
     origin: 'https://www.shipengine.com',
     protocol: 'https:',
     username: '',
     password: '',
     host: 'www.shipengine.com',
     hostname: 'www.shipengine.com',
     port: '',
     pathname: '/docs/errors/codes/',
     search: '',
     searchParams: URLSearchParams {},
     hash: ''
   }
 }

I also confirmed it was not the shipping info used that is causing the problem, as I created and tested the cUrl manually using the same shipping parameters and was able to get a successful response:

curl --location 'https://api.shipengine.com/v1/rates' \
--header 'Api-Key: XXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data '{
    "rate_options": {
        "carrier_ids": [
            "se-4994286",
            "se-4994020"
        ],
        "service_codes": []
    },
    "shipment": {
        "validate_address": "validate_only",
        "confirmation": "none",
        "ship_from": {
            "name": "Jane Smith",
            "phone": "2135370158",
            "postal_code": "90017",
            "company_name": "Test Company",
            "country_code": "US",
            "address_line1": "1111 Wilshire Blvd",
            "address_line2": "",
            "city_locality": "Los Angeles",
            "state_province": "CA",
            "address_residential_indicator": "no"
        },
        "ship_to": {
            "name": "John Doe",
            "phone": null,
            "address_line1": "1833 Via Quinto",
            "address_line2": null,
            "city_locality": "Oceanside",
            "state_province": "CA",
            "country_code": "US",
            "postal_code": "92056"
        },
        "packages": [
            {
                "weight": {
                    "unit": "pound",
                    "value": 5
                },
                "dimensions": {
                    "unit": "inch",
                    "width": 15,
                    "height": 15,
                    "length": 23
                }
            }
        ]
    }
}'

Results in 200 OK with rate response.

Do you have any other ideas what could be causing this issue?

@wentao709
Copy link
Author

Hey @brandonraphael I stopped seeing the error without any custom config. can you try that please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants