Air Apple Cart External API's

To save Signup Lead data from your application use the following code swagger. Following variables must be present.

  1. x-api-key (Header)
  2. email
  3. firstName (Optional)
  4. lastName (Optional)
  5. address (Optional)
  6. dateOfBirth (Optional)
  7. phoneNumber (Optional)
  8. whatsAppNumber (Optional)
  9. jobTitle (Optional)
  10. dateOfJoining (Optional)


    API_URL=https://gateway-stg.airapplecart.co.uk/contact/public
    API_KEY=YOUR_API_KEY

    
import { Injectable, HttpService } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';



@Injectable()
export class LeadGenerationService {
  constructor(
    private readonly httpService: HttpService,
    private readonly configService: ConfigService,
  ) {}



  async createLead(): Promise {
    const url = this.configService.get('API_URL');
    const apiKey = this.configService.get('API_KEY');
    const headers = {
      'accept': 'application/json',
      'x-api-key': apiKey,
      'Content-Type': 'application/json',
    };
    const data = {
      email: 'IG@ceative.co.uk',
      firstName: 'Orcalo',
      lastName: 'Holdings',
      address: 'Johar town',
      dateOfBirth: '2024-05-21T09:47:05.388Z',
      phoneNumber: '00923165372970',
      whatsAppNumber: '00923165372970',
      jobTitle: 'developer',
      dateOfJoining: '2024-05-21T09:47:05.388Z',
    };



    try {
      const response = await this.httpService.post(url, data, { headers }).toPromise();
      return response.data;
    } catch (error) {
      // Handle error
      console.error(error);
      throw error;
    }
  }
}

Java Implementation

    
    

Java Dependency

org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-json org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-env package com.example.demo.service; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.util.UriComponentsBuilder; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; @Service public class LeadGenerationService { @Value("${api.url}") private String apiUrl; @Value("${api.key}") private String apiKey; private final HttpClient httpClient; private final ObjectMapper objectMapper; public LeadGenerationService() { this.httpClient = HttpClient.newHttpClient(); this.objectMapper = new ObjectMapper(); } public String createLead() throws IOException, InterruptedException { URI uri = UriComponentsBuilder.fromHttpUrl(apiUrl).build().toUri(); Map leadDetails = new HashMap<>(); leadDetails.put("email", "IG@ceative.co.uk"); leadDetails.put("firstName", "Orcalo"); leadDetails.put("lastName", "Holdings"); leadDetails.put("address", "Johar town"); leadDetails.put("dateOfBirth", "2024-05-21T09:47:05.388Z"); leadDetails.put("phoneNumber", "00923165372970"); leadDetails.put("whatsAppNumber", "00923165372970"); leadDetails.put("jobTitle", "developer"); leadDetails.put("dateOfJoining", "2024-05-21T09:47:05.388Z"); String requestBody = objectMapper.writeValueAsString(leadDetails); HttpRequest request = HttpRequest.newBuilder() .uri(uri) .header("accept", "application/json") .header("x-api-key", apiKey) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(requestBody)) .build(); HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() == 200) { return response.body(); } else { throw new IOException("Error creating lead: " + response.body()); } } }

To save Enquiry data from your application use the following code swagger. Following variables must be present.

  1. x-api-key (Header)
  2. email
  3. query
  4. name
  5. phoneNumber


    
import { useState } from 'react';

const EnquiryForm = () => {
  const [formData, setFormData] = useState({
    query: '',
    name: '',
    email: '',
    phoneNumber: '',
  });

  const handleChange = (e) => {
    setFormData({
      ...formData,
      [e.target.name]: e.target.value,
    });
  };

  const handleSubmit = async (e) => {
    e.preventDefault();

    const response = await fetch(process.env.NEXT_PUBLIC_API_URL, {
      method: 'POST',
      headers: {
        'accept': 'application/json',
        'x-api-key': process.env.NEXT_PUBLIC_API_KEY,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(formData),
    });

    if (response.ok) {
      const data = await response.json();
      console.log('Success:', data);
      alert('Enquiry submitted successfully');
    } else {
      console.error('Error:', response.statusText);
      alert('Failed to submit enquiry');
    }
  };

Java Implementation


    
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class EnquiryClient {

    private static final String API_URL = System.getenv("API_URL");
    private static final String API_KEY = System.getenv("API_KEY");

    public static void main(String[] args) {
        String jsonInputString = "{\"query\": \"Looking for your sales products\", \"name\": \"maarij\", \"email\": \"maarij.bhatti@oxfordfintech.com\", \"phoneNumber\": \"+1234567890\"}";
        sendPostRequest(jsonInputString);
    }

    public static void sendPostRequest(String jsonInputString) {
        try {
            URL url = new URL(API_URL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json; utf-8");
            conn.setRequestProperty("Accept", "application/json");
            conn.setRequestProperty("x-api-key", API_KEY);
            conn.setDoOutput(true);

            try(OutputStream os = conn.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            int responseCode = conn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Enquiry submitted successfully");
            } else {
                System.out.println("Failed to submit enquiry: " + conn.getResponseMessage());
            }

            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}