FedEx integration example
This tutorial shows how to integrate FedEx.
1. Preparation
1.1. Create a FedEx account
Create an account on the developer portal.
1.2. Create projects and get tokens
In My projects, create two projects and save the client ID and client secret.
The first project is for managing shipments:
The second project is for tracking shipments:
1.3. Create delivery statuses
On the statuses tab of the order storage, create statuses (opens in a new tab):
- order_delivery
- order_delivery_started
- ready_for_pickup
1.4. Create an event to track statuses
In the Events (opens in a new tab) module, create an event that tracks when an order changes to the order_delivery status.

1.5. Create a delivery collection
In the Integration Collections (opens in a new tab) module, create a delivery collection with these attributes:
- name (
string) - address (
string) - phone_number (
string) - city (
string) - state_code (
string) - postal_code (
string) - country_code (
string) - tracking_number (
string) - transaction_id (
string) - ship_datestamp (
string) - delivery_datestamp (
string)

1.6. Create a test order
Create an order and a collection record for it.


2. Creating a shipment
2.1. Track the delivery event
- Drag the events (opens in a new tab) node onto the workspace.
- Enter a name for the node.
- Change the value of the "Set" field to "orderEvent". The event is saved to the "msg.orderEvent" object, and other nodes can use it.
- Select the "order delivery" event you created and click "submit".

2.2. Get a token
- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.
- Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your own values.

msg.payload = {
'grant_type': 'client_credentials',
'client_id': 'YOUR_CLIENT_ID',
'client_secret': 'YOUR_CLIENT_SECRET'
}
msg.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
return msg;
For details on the parameters, see the FedEx documentation.
- Drag the http request (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- In the Method field, select "POST".
- In the Data field, select "Send as request body".
- In the Link field, enter
https://apis-sandbox.fedex.com/oauth/token. - In the Return field, select "Object JSON".

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.

msg.access_token = msg.payload.access_token;
return msg;
2.3. Create the shipment
- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Receiving all records belonging to the collection" method and paste the code below into the "Data" field.
{
"entityType": "orders",
"entityId": "{{orderEvent.order.id}}",
"langCode": "en_US",
"offset": 0,
"limit": 1,
"marker": "delivery"
}

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.

// get the previously saved token
const token = msg.access_token;
// set the headers
msg.headers = {
'Content-Type': 'application/json',
'authorization': `Bearer ${token}`
};
// get the collection from the previous step
const collection = msg.payload.items[0];
// convert the array to an object
const formData = collection.formData.reduce((acc, item) => {
acc[item.marker] = item.value;
return acc;
}, {});
// set the recipient parameters from the form
const recipient = {
"address": {
"streetLines": [
formData.address
],
"city": formData.city,
"stateOrProvinceCode": formData.state_code,
"postalCode": formData.postal_code,
"countryCode": formData.country_code
},
"contact": {
"personName": formData.name,
"phoneNumber": formData.phone_number
}
}
// store the collection data in msg for later use
msg.collection = collection;
// set the request parameters for FedEx
msg.payload = {
"labelResponseOptions": "URL_ONLY",
"accountNumber": {
"value": "510087020"
},
"requestedShipment": {
"shipper": {
"contact": {
"personName": "SENDER NAME",
"phoneNumber": "9018328595"
},
"address": {
"streetLines": [
"SENDER ADDRESS 1"
],
"city": "MEMPHIS",
"stateOrProvinceCode": "TN",
"postalCode": "38116",
"countryCode": "US"
}
},
"recipients": [
recipient
],
"serviceType": "STANDARD_OVERNIGHT",
"packagingType": "YOUR_PACKAGING",
"pickupType": "DROPOFF_AT_FEDEX_LOCATION",
"shippingChargesPayment": {
"paymentType": "SENDER",
"payor": {
"responsibleParty": {
"accountNumber": {
"value": "510087020",
"key": ""
}
},
"address": {
"streetLines": [
"SENDER ADDRESS 1"
],
"city": "MEMPHIS",
"stateOrProvinceCode": "TN",
"postalCode": "38116",
"countryCode": "US"
}
}
},
"labelSpecification": {},
"requestedPackageLineItems": [
{
"customerReferences": [
{
"customerReferenceType": "CUSTOMER_REFERENCE",
"value": `Collection${collection.id}`
}
],
"weight": {
"units": "LB",
"value": "20"
}
}
]
}
};
return msg;
For details on the parameters, see the FedEx documentation.
- Drag the http request (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- In the Method field, select "POST".
- In the Data field, select "Send as request body".
- In the Link field, enter
https://apis-sandbox.fedex.com/ship/v1/shipments. - In the Return field, select "Object JSON".

- Drag the debug (opens in a new tab) node onto the workspace and connect it to the node from the previous step.

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.

// get the shipment data
const shipment = msg.payload.output.transactionShipments[0];
// get the previously saved collection data
const collection = msg.collection;
// write the shipment data to the form attributes
const newFormData = [
...collection.formData
.filter(item => !['transaction_id', 'ship_datestamp', 'delivery_datestamp', 'tracking_number'].includes(item.marker)),
{
marker: 'transaction_id',
value: msg.payload.transactionId,
type: 'string'
},
{
marker: 'ship_datestamp',
value: shipment.shipDatestamp,
type: 'string'
},
{
marker: 'delivery_datestamp',
value: shipment.pieceResponses[0].deliveryDatestamp,
type: 'string'
},
{
marker: 'tracking_number',
value: shipment.masterTrackingNumber,
type: 'string'
}
]
// set the parameters for updating the collection
msg.params = {
langCode: 'en_US',
id: collection.id,
marker: 'delivery'
}
msg.data = {
formIdentifier: 'delivery_form',
formData: {
en_US: newFormData
},
entityId: collection.entityId,
entityType: collection.entityType
}
// store the collection data for later use
msg.collection = collection;
return msg;
- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Changing a record in the collection" method.

2.4. Update the order status
- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Updating the status of an order belonging to the order storage object" method.
- Paste the code below into the "Query parameters" field.
{
"id": 1,
"orderId": "{{collection.entityId}}"
}
- Paste the code below into the "Request body" field.
{
"statusIdentifier": "order_delivery_started"
}

- Drag the debug (opens in a new tab) node onto the workspace and connect it to the node from the previous step.

3. Tracking the shipment status
3.1. Get the orders to track
- Drag the interval (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Enter the interval in minutes.

- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Receiving all orders belonging to the order storage object" method.
- Paste the code below into the "Query parameters" field.
{
"statusIdentifier": "order_delivery_started",
"langCode": "en_US",
"offset": 0,
"limit": 100,
"id": 1
}

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.

msg.payload = msg.payload.items;
return msg;
- Drag the split (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Enter the length.

- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Receiving all records belonging to the collection" method.
- Paste the code below into the "Query parameters" field.
{
"marker": "delivery",
"entityId": "{{payload.id}}",
"entityType": "orders",
"langCode": "en_US",
"limit": 1,
"offset": 0
}

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.

msg.payload = msg.payload.items[0]
return msg;
- Drag the switch (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Add a check rule and select the "not empty" condition.

- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.
![]()
msg.trackingNumber = msg.payload
.formData
.find(item => item.marker === 'tracking_number')
.value;
msg.collection = msg.payload;
return msg;
3.2. Get a token
- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.
- Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your own values.

msg.payload = {
'grant_type': 'client_credentials',
'client_id': 'YOUR_CLIENT_ID',
'client_secret': 'YOUR_CLIENT_SECRET'
}
msg.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
return msg;
For details on the parameters, see the FedEx documentation.
- Drag the http request (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- In the Method field, select "POST".
- In the Data field, select "Send as request body".
- In the Link field, enter
https://apis-sandbox.fedex.com/oauth/token. - In the Return field, select "Object JSON".

3.3. Get the shipment status
- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.
![]()
const token = msg.payload.access_token;
msg.headers = {
'content-type': 'application/json',
'authorization': `Bearer ${token}`
};
msg.payload = {
"trackingInfo": [
{
"trackingNumberInfo": {
"trackingNumber": msg.trackingNumber
}
}
],
"includeDetailedScans": true
}
return msg;
For details on the parameters, see the FedEx documentation.
- Drag the http request (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- In the Method field, select "POST".
- In the Data field, select "Send as request body".
- In the Link field, enter
https://apis-sandbox.fedex.com/track/v1/trackingnumbers. - In the Return field, select "Object JSON".
![]()
- Drag the function (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Paste the example code into the "Function" field.
![]()
msg.payload = msg.payload.output.completeTrackResults[0].trackResults[0].latestStatusDetail.statusByLocale;
return msg;
3.4. Update the order status
- Drag the switch (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Add a check rule, select the "==" condition, and enter "Ready for pickup" as the value.

- Drag the admin-api (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
- Select the "Updating the status of an order belonging to the order storage object" method.
- Paste the code below into the "Query parameters" field.
{
"id": 1,
"orderId": "{{collection.entityId}}"
}
- Paste the code below into the "Request body" field.
{
"statusIdentifier": "ready_for_pickup"
}

- Drag the debug (opens in a new tab) node onto the workspace and connect it to the node from the previous step.
