Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a PowerShell v2 script that performs a simple customer creation action on the API and outputs the status text. Either "created" if the customer has been created or "Unprocessable Entity" if a customer with the same email already exists.
function createCustomer($first_name, $last_name, $title, $background, $email) {
$subdomain = "your-site-subdomain"
$username = ""
$password = "YoUrPaSsWoRd"
$body = @"
"first_name": "$first_name",
"last_name": "$last_name",
"title": "$title",
"background": "$background",
"emails": [{
"type": "home",
"value": "$email"
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$"POST", "https://" + $subdomain + "/api/v2/customers", $false)
$http_request.setRequestHeader("Content-type", "application/json")
$http_request.setRequestHeader("Content-length", $body.length)
$http_request.setRequestHeader("Authorization", "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password)))
$http_request.setRequestHeader("Connection", "close")
Write-Host $http_request.statusText
createCustomer "John" "Doe" "PhD" "Background info" ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.