Python SDK
from metrifox_sdk import MetrifoxClient
client = MetrifoxClient(api_key="your_api_key")
# Upload customers via CSV
result = client.customers.upload_csv("/path/to/customers.csv")
print(f"Total customers: {result['data']['total_customers']}")
print(f"Successful: {result['data']['successful_upload_count']}")
print(f"Failed: {result['data']['failed_upload_count']}")
# Handle failed uploads
if result['data']['failed_upload_count'] > 0:
for failure in result['data']['customers_failed']:
print(f"Row {failure['row']}: {failure['errors']}")
import { init } from "metrifox-js";
const metrifoxClient = init({
apiKey: process.env.METRIFOX_API_KEY
});
// Example: File input handler
const handleFileUpload = async (event) => {
const file = event.target.files[0];
if (file && file.type === 'text/csv') {
await metrifoxClient.customers.uploadCsv(file);
} else {
alert('Please select a valid CSV file');
}
};
require 'metrifox-sdk'
# Initialize with configuration
METRIFOX_SDK = MetrifoxSDK.init({ api_key: "your-api-key" })
# Upload customers via CSV
response = METRIFOX_SDK.customers.upload_csv("/path/to/customers.csv")
puts response["data"]["total_customers"]
puts response["data"]["successful_upload_count"]
curl --request POST \
--url https://{defaultHost}/api/v1/customers/csv-upload \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form file='@example-file'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{defaultHost}/api/v1/customers/csv-upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data; boundary=---011000010111000001101001",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{defaultHost}/api/v1/customers/csv-upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{defaultHost}/api/v1/customers/csv-upload")
.header("x-api-key", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--")
.asString();{
"total_customers": 3,
"successful_upload_count": 3,
"failed_upload_count": 0,
"customers_added": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"customer_key": "acme-corp-001",
"primary_email": "contact@acme.com",
"customer_type": "BUSINESS"
},
{
"id": "550e8400-e29b-41d4-a716-446655440001",
"customer_key": "tech-solutions-002",
"primary_email": "info@techsolutions.com",
"customer_type": "BUSINESS"
},
{
"id": "550e8400-e29b-41d4-a716-446655440002",
"customer_key": "jane-doe-003",
"primary_email": "jane.doe@example.com",
"customer_type": "INDIVIDUAL"
}
],
"customers_failed": []
}Customers
Upload Customers in Bulk via CSV
Update an existing customer
POST
/
api
/
v1
/
customers
/
csv-upload
Python SDK
from metrifox_sdk import MetrifoxClient
client = MetrifoxClient(api_key="your_api_key")
# Upload customers via CSV
result = client.customers.upload_csv("/path/to/customers.csv")
print(f"Total customers: {result['data']['total_customers']}")
print(f"Successful: {result['data']['successful_upload_count']}")
print(f"Failed: {result['data']['failed_upload_count']}")
# Handle failed uploads
if result['data']['failed_upload_count'] > 0:
for failure in result['data']['customers_failed']:
print(f"Row {failure['row']}: {failure['errors']}")
import { init } from "metrifox-js";
const metrifoxClient = init({
apiKey: process.env.METRIFOX_API_KEY
});
// Example: File input handler
const handleFileUpload = async (event) => {
const file = event.target.files[0];
if (file && file.type === 'text/csv') {
await metrifoxClient.customers.uploadCsv(file);
} else {
alert('Please select a valid CSV file');
}
};
require 'metrifox-sdk'
# Initialize with configuration
METRIFOX_SDK = MetrifoxSDK.init({ api_key: "your-api-key" })
# Upload customers via CSV
response = METRIFOX_SDK.customers.upload_csv("/path/to/customers.csv")
puts response["data"]["total_customers"]
puts response["data"]["successful_upload_count"]
curl --request POST \
--url https://{defaultHost}/api/v1/customers/csv-upload \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-key: <api-key>' \
--form file='@example-file'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{defaultHost}/api/v1/customers/csv-upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data; boundary=---011000010111000001101001",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{defaultHost}/api/v1/customers/csv-upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{defaultHost}/api/v1/customers/csv-upload")
.header("x-api-key", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\ncustomers.csv\r\n-----011000010111000001101001--")
.asString();{
"total_customers": 3,
"successful_upload_count": 3,
"failed_upload_count": 0,
"customers_added": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"customer_key": "acme-corp-001",
"primary_email": "contact@acme.com",
"customer_type": "BUSINESS"
},
{
"id": "550e8400-e29b-41d4-a716-446655440001",
"customer_key": "tech-solutions-002",
"primary_email": "info@techsolutions.com",
"customer_type": "BUSINESS"
},
{
"id": "550e8400-e29b-41d4-a716-446655440002",
"customer_key": "jane-doe-003",
"primary_email": "jane.doe@example.com",
"customer_type": "INDIVIDUAL"
}
],
"customers_failed": []
}Authorizations
Body
multipart/form-data
CSV file containing customer data
Response
CSV upload processed successfully
Total number of customers in the CSV file
Number of customers successfully created
Number of customers that failed to be created
Array of successfully created customers
Array of customers that failed to be created with error details
Show child attributes
Show child attributes
⌘I

