Skip to content

Create multiple customers

Post
bash
https://api.bunce.so/v1/customers/bulk

Create Multiple Customers.

If successful, your response includes a copy of the new customer entity in an array.

Request

Body Parameters array required

customer_id string requiredCustomer's ID in your database
email string<email> requiredCustomer's email address
first_name string requiredCustomer's first name
last_name string requiredCustomer's last name
phone_no string requiredCustomer's phone number
devices array<{ device_type: string; device_token: string; }> nullableCustomer's devices

Devices Field

The devices field is an optional array of device objects. Each device object should contain the following fields:

  • device_type (string): The type of device (e.g., ios, android).
  • device_token (string): The token associated with the device.

Example:

json
{
  "devices": [
    {
      "device_type": "ios",
      "device_token": "123456"
    },
    {
      "device_type": "android",
      "device_token": "654321"
    }
  ]
}
bash
curl --request POST \
  --url https://api.bunce.so/v1/customers/bulk \
  --header 'Content-Type: application/json' \
  --header 'X-Authorization: sk_live_************************' \
  --data ' {
   "customers": [
    {
      "customer_id" : "0000",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe21@example.com",
      "phone_no": "+23481999999999",
      "devices": [
        {
          "device_type": "ios",
          "device_token": "123456"
        },
        {
          "device_type": "android",
          "device_token": "654321"
        }
      ]
    },
    {
      "customer_id" : "1111",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe22@example.com",
      "phone_no": "+23481999999999"
    }
  ]
 }'
go
import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

url := "https://api.bunce.so/v1/customers/bulk"

payload := strings.NewReader(" {\n \"customers\": [\n {\n \"customer_id\": \"t6yygythh\",\n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"email\": \"johndoe21@example.com\",\n \"phone_no\": \"+23481999999999\"\n},\n {\n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"email\": \"johndoe22@example.com\",\n \"phone_no\": \"+23481999999999\"\n}\n ]\n }")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("X-Authorization", "sk_live_************************")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))
js
import  from 'node-fetch'

let  = 'https://api.bunce.so/v1/customers/bulk'

let  = {
  : 'POST',
  : {
    'X-Authorization': 'sk_live_************************',
    'Content-Type': 'application/json',
  },
  : '{"customers":[{"customer_id":"0000","first_name":"John","last_name":"Doe","email":"johndoe21@example.com","phone_no":"+23481999999999"},{"first_name":"John","last_name":"Doe","email":"johndoe22@example.com","phone_no":"+23481999999999"}]}',
}

(, )
  .then(() => .json())
  .then(() => .())
  .catch(() => .('error:' + ))
php
<?php

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append('{
   "customers": [
    {
      "customer_id":"0000",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe21@example.com",
      "phone_no": "+23481999999999"
    },
    {
      "customer_id":"1111",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe22@example.com",
      "phone_no": "+23481999999999"
    }
  ]
 }');

$request->setRequestUrl('https://api.bunce.so/v1/customers/bulk');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders([
  'X-Authorization' => 'sk_live_************************',
  'Content-Type' => 'application/json'
]);

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
java
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.bunce.so/v1/customers/bulk"))
    .header("X-Authorization", "sk_live_************************")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString(" {\n \"customers\": [\n {\n \"customer_id\": \"0000\", \n \"first_name\": \"John\",\n      \"last_name\": \"Doe\",\n \"email\": \"johndoe21@example.com\",\n \"phone_no\": \"+23481999999999\"\n },\n {\n \"customer_id\": \"John\", \n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"email\": \"johndoe22@example.com\",\n \"phone_no\": \"+23481999999999\"\n }\n ]\n }"))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Response

json
{
  "data": [
    {
      "customer_id": "0000",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe@example.com",
      "phone_no": "+23481999999999",
      "customer_created_at": "2023-12-17T10:59:04.685126+01:00"
    },
    {
      "customer_id": "1111",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe2@example.com",
      "phone_no": "+23481999999999",
      "customer_created_at": "2023-12-17T10:59:04.912064+01:00"
    },
    {
      "customer_id": "2222",
      "first_name": "John",
      "last_name": "Doe",
      "email": "johndoe3@example.com",
      "phone_no": "+23481999999999",
      "customer_created_at": "2023-12-17T10:59:05.138562+01:00",
      "devices": [
        {
          "device_id": "018c7737-0ab2-78f7-ba75-1710dd8fe631",
          "device_type": "ios",
          "device_token": "123456"
        },
        {
          "device_id": "1710dd8fe631-018c7737-0ab2-78f7",
          "device_type": "android",
          "device_token": "654321"
        }
      ]
    }
  ],
  "message": "Customers created successfully",
  "success": true
}
json
{
  "errors": ["johndoe@example.com is already taken"],
  "message": "Errors encountered while creating. 1 out of 3 customers failed",
  "status": false
}