/lovable-integrations

Lovable and AfterShip integration: Step-by-Step Guide 2025

Learn how to seamlessly connect Lovable with AfterShip using our step-by-step guide. Streamline shipment tracking and boost order management efficiency.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Lovable with AfterShip?

 

Step 1: Create the AfterShip Integration File

 

Create a new TypeScript file in your Lovable project. For example, create a file named afterShipIntegration.ts inside a folder called src/integrations (create the folder if it does not exist). This file will house all the code needed to connect with AfterShip’s API.

Add the following code inside afterShipIntegration.ts:


const AFTERSHIPAPIKEY = 'YOURAFTERSHIPAPI_KEY'; // Replace with your actual API key
const AFTERSHIPBASEURL = 'https://api.aftership.com/v4';

export interface TrackingInfo {
  tracking_number: string;
  slug: string;
}

export class AfterShipService {
  // A method to track a shipment using its tracking number and slug
  public async trackShipment(tracking: TrackingInfo): Promise {
    const url = ${AFTERSHIP_BASE_URL}/trackings/${tracking.slug}/${tracking.tracking_number};
    
    const response = await fetch(url, {
      method: 'GET',
      headers: {
        'aftership-api-key': AFTERSHIPAPIKEY,
        'Content-Type': 'application/json'
      }
    });
    
    if (!response.ok) {
      throw new Error('Failed to retrieve tracking information.');
    }
    
    const data = await response.json();
    return data;
  }

  // A method to create a new tracking entry
  public async createTracking(tracking: TrackingInfo): Promise {
    const url = ${AFTERSHIP_BASE_URL}/trackings;
    const body = {
      tracking: tracking
    };

    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'aftership-api-key': AFTERSHIPAPIKEY,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(body)
    });

    if (!response.ok) {
      throw new Error('Failed to create tracking entry.');
    }

    const data = await response.json();
    return data;
  }
}

This file defines an API key and base URL for AfterShip as well as two methods: one to get tracking details and another to create a tracking entry.

 

Step 2: Ensure Dependency Compatibility

 

Since Lovable does not provide a terminal to install Node.js dependencies, ensure your project supports the fetch API. Most modern browsers and environments have a built‐in fetch function. If your project runs in an environment that does not support fetch, you might need to include a polyfill. To do that, add the following script tag to your main HTML file:


<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/3.0.0/fetch.min.js"></script>

If Lovable already supports fetch natively, you can skip this step.

 

Step 3: Integrate the AfterShip Service into Your Lovable Code

 

Open the file in your Lovable project where you want to use the AfterShip functionality. For example, if you have a main file like app.ts or main.ts, import the AfterShip service and call its methods when needed.

Add the following snippet to your main file where you want to trigger tracking calls:


import { AfterShipService, TrackingInfo } from './integrations/afterShipIntegration';

const afterShip = new AfterShipService();

// Example function to get tracking info
async function getTrackingDetails() {
  const trackingData: TrackingInfo = {
    trackingnumber: 'TRACKINGNUMBER_HERE', // Replace with actual tracking number
    slug: 'COURIERSLUGHERE'                // Replace with the courier's slug, e.g., 'ups', 'fedex'
  };

  try {
    const result = await afterShip.trackShipment(trackingData);
    console.log('Tracking Details:', result);
    // Process the returned tracking details as needed
  } catch (error) {
    console.error('Error fetching tracking details:', error);
  }
}

// Example function to create a tracking entry
async function createNewTracking() {
  const trackingData: TrackingInfo = {
    trackingnumber: 'TRACKINGNUMBER_HERE',
    slug: 'COURIERSLUGHERE'
  };

  try {
    const result = await afterShip.createTracking(trackingData);
    console.log('Created Tracking:', result);
    // Process the API response as needed
  } catch (error) {
    console.error('Error creating tracking entry:', error);
  }
}

// Call the functions as per your application logic
getTrackingDetails();
// createNewTracking(); // Uncomment to use the create tracking functionality

This code imports your AfterShip integration, creates an instance, and shows how to use its methods to get tracking details and create tracking entries. Replace the placeholder strings with your actual data.

 

Step 4: Handling API Key and Sensitive Data

 

Since Lovable might not have a dedicated terminal or environment variable configuration setup, securely embed your AfterShip API key directly in afterShipIntegration.ts if needed. However, be cautious with sensitive information. If your project supports runtime environment variables or a configuration file, consider moving the API key into a separate configuration file and importing it.

For example, create a file config.ts inside src with the following content:


export const config = {
  AFTERSHIPAPIKEY: 'YOURAFTERSHIPAPI_KEY' // Replace with your actual API key
};

Then modify afterShipIntegration.ts to import and use the API key from config.ts:


import { config } from '../config';

const AFTERSHIPAPIKEY = config.AFTERSHIPAPIKEY;
const AFTERSHIPBASEURL = 'https://api.aftership.com/v4';

// ... rest of the code remains the same

This way you separate configuration from code even if you cannot use a terminal to set environment variables.

 

Step 5: Testing the Integration

 

To verify the integration, trigger the functions from your Lovable project’s UI or call them in your main execution flow. Open your browser’s console or your application's log output to see the results of the API calls. Adjust the tracking data and error handling as needed based on the testing results.

By following these structured steps, you integrate AfterShip with your Lovable project using TypeScript. Each step includes where to place the code, what each file represents, and how to make calls to AfterShip’s API.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022