Introduction

Welcome to the Cloud9 API documentation. This API allows you to integrate with our platform and access various functionalities programmatically.

Base URL

Use the following base URL for API requests:

Production: https://system_url/api 
All requests: Require Content-Type: application/json.

Authentication and Token Management

Use the endpoints below to authenticate users and manage tokens.

1. User Login

Generates an access token and refresh token for authentication.

Endpoint: /login
Method: POST
Headers: None

Example Body:

{
  "email": "user@example.com",
  "password": "password123"
}

• Response (Success):

{
  "token_type": "Bearer",
  "expires_in": 1800,
  "access_token": "your_access_token_here",
  "refresh_token": "your_refresh_token_here"
}

• Response (Failure):

{
  "error": "Invalid credentials"
}

2. Refresh Token

Generates a new access token using a valid refresh token.

Endpoint: /refresh-token
Method: POST
Headers: None

Example Body:

{
  "refresh_token": "your_refresh_token_here"
}

• Response (Success):

{
  "token_type": "Bearer",
  "expires_in": 1800,
  "access_token": "new_access_token_here",
  "refresh_token": "new_refresh_token_here"
}

• Response (Failure):

{
  "error": "Invalid refresh token"
}

Campaign Management

Use the following endpoints to manage campaigns.

1. List Campaigns

Fetches all campaigns along with their id and campaign_name.

Endpoint: /campaigns
Method: GET
Headers:

Makefile:


  Authorization: Bearer <access_token>

• Response (Success):

{
  "message": "Campaigns retrieved successfully",
  "campaigns": [
   {
    "id": 1,
    "campaign_name": "Campaign A"
   },
   {
    "id": 2,
    "campaign_name": "Campaign B"
   }
  ]
}

•Response (Failure - Unauthenticated):

{
  "error": "Unauthenticated."
}

Leads Management

Use the `/leads` endpoint to upload leads to specific campaigns.


api/leads/$campaign_id

Endpoint Overview

The api/leads/campaign_id endpoint is used to upload multiple leads to a specific campaign. Developers must pass the campaign_id as a URL parameter and a list of leads as part of the request body. Where $leads should be declared as an array to hold all the leads, see example code snippets below.


Endpoint Details

• URL: POST /api/leads/campaign_id
• Method: POST
• Authentication: Requires a valid Bearer token in the Authorization header.
• Headers:

plaintext:


  Authorization: Bearer <access_token>
  Content-Type: application/json

Request Parameters

URL Parameter

NameTypeDescription
campaign_idintID of the campaign to which the leads are being added.

Request Body

The request body should include a leads array, where each item represents a lead with the following fields:

FieldTypeRequiredDescription
fullnamestringYesFull name of the lead.
national_idstringYesNational ID or identification number of the lead.
primary_numberstringYesPrimary contact number of the lead. Must start with one of the allowed country codes.
secondary_numberstringNoSecondary contact number of the lead. Must start with one of the allowed country codes if provided.
physical_addressstringNoPhysical address of the lead.
emailstringYesEmail address of the lead.
supplierstringNoSupplier or source of the lead.

Example Request

URL

POST https://cloud9.sipline-cloud.com/api/leads/2

Headers

Authorization: Bearer your_access_token
Content-Type: application/json

Body

{
  "leads": [
    {
      "fullname": "John Doe",
      "national_id": "123456789",
      "primary_number": "27123456789",
      "secondary_number": "265987654321",
      "physical_address": "123 Main Street",
      "email": "johndoe@example.com",
      "supplier": "Supplier A"
    },
    {
      "fullname": "Jane Smith",
      "national_id": "987654321",
      "primary_number": "91234567890",
      "secondary_number": "27123456787",
      "physical_address": "456 Elm Street",
      "email": "janesmith@example.com",
      "supplier": "Supplier B"
    }
  ]
}

Response

Success

{
  "message": "Leads processed successfully",
  "total_processed": 2,
  "total_inserted": 1,
  "total_skipped": 1
}
  • total_processed: Total number of leads received.
  • total_inserted: Number of leads successfully added to the campaign.
  • total_skipped: Number of leads skipped due to duplicates or validation issues.

Validation Error

{
  "errors": {
    "leads.1.primary_number": [
      "The primary_number must start with one of the following country codes: 27, 265, 91, 1."
    ]
  }
}

Invalid Campaign ID

{
  "error": "Invalid campaign_id"
}

Unauthorized

{
  "error": "Unauthenticated."
}

Integration Examples

1. PHP (Using cURL)

<?php
$campaignId = 2;
$url = "https://cloud9.sipline-cloud.com/api/leads/$campaignId";
$accessToken = 'your_access_token_here';
$leads = [
  [
    'fullname' => 'John Doe',
    'national_id' => '123456789',
    'primary_number' => '27123456789',
    'secondary_number' => '265987654321',
    'physical_address' => '123 Main Street',
    'email' => 'johndoe@example.com',
    'supplier' => 'Supplier A',
  ],
  [
    'fullname' => 'Jane Smith',
    'national_id' => '987654321',
    'primary_number' => '91234567890',
    'secondary_number' => '27123456787',
    'physical_address' => '456 Elm Street',
    'email' => 'janesmith@example.com',
    'supplier' => 'Supplier B',
  ],
];
$headers = [
  "Authorization: Bearer $accessToken",
  "Content-Type: application/json",
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['leads' => $leads]));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

2. Python (Using requests)

import requests

url = "https://cloud9.sipline-cloud.com/api/leads/2"
access_token = "your_access_token_here"
leads = [
  {
    "fullname": "John Doe",
    "national_id": "123456789",
    "primary_number": "27123456789",
    "secondary_number": "265987654321",
    "physical_address": "123 Main Street",
    "email": "johndoe@example.com",
    "supplier": "Supplier A",
  },
  {
    "fullname": "Jane Smith",
    "national_id": "987654321",
    "primary_number": "91234567890",
    "secondary_number": "27123456787",
    "physical_address": "456 Elm Street",
    "email": "janesmith@example.com",
    "supplier": "Supplier B",
  },
]

response = requests.post(
  url,
  json={"leads": leads},
  headers={
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
  }
)

print(response.status_code, response.json())

3. JavaScript (Using Axios)

const axios = require('axios');

const campaignId = 2;
const url = `https://cloud9.sipline-cloud.com/api/leads/${campaignId}`;
const accessToken = 'your_access_token_here';

const leads = [
  {
    fullname: 'John Doe',
    national_id: '123456789',
    primary_number: '27123456789',
    secondary_number: '265987654321',
    physical_address: '123 Main Street',
    email: 'johndoe@example.com',
    supplier: 'Supplier A',
  },
  {
    fullname: 'Jane Smith',
    national_id: '987654321',
    primary_number: '91234567890',
    secondary_number: '27123456787',
    physical_address: '456 Elm Street',
    email: 'janesmith@example.com',
    supplier: 'Supplier B',
  },
];

axios
  .post(url, { leads }, {
    headers: {
      Authorization: `Bearer ${accessToken}`,
      'Content-Type': 'application/json',
    },
  })
  .then((response) => {
    console.log('Response:', response.data);
  })
  .catch((error) => {
    console.error('Error:', error.response.status, error.response.data);
  });

Error Handling

Common Error Responses

• 401 Unauthorized:

{
  "error": "Unauthenticated."
}

Occurs when the token is missing or invalid.

• 422 Unprocessable Entity:

{
  "errors": {
   "field_name": ["Error message."]
  }
}

Occurs when required fields are missing or invalid.

• 400 Bad Request:

{
  "error": "Invalid request data."
}

Occurs when invalid or malformed data is sent to the server.

Integration Workflow

1. Authenticate and Obtain Token

• Call /login to authenticate the user and obtain an access_token and refresh_token. 
• Use the access_token to make subsequent API calls.

2. Fetch Campaigns

• Use /campaigns to list available campaigns and their IDs.

3. Upload Leads

• Use /leads to upload bulk leads, ensuring all leads are associated with a valid campaign_id.

4. Refresh Token

• Use /refresh-token to renew the access_token when it expires.