Created
August 13, 2013 23:21
-
-
Save tstachl/6226672 to your computer and use it in GitHub Desktop.
This is a PowerShell v2 script that performs a simple customer creation action on the desk.com 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createCustomer($first_name, $last_name, $title, $background, $email) { | |
$subdomain = "your-site-subdomain" | |
$username = "[email protected]" | |
$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 | |
$http_request.open("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") | |
$http_request.send($body) | |
Write-Host $http_request.statusText | |
} | |
createCustomer "John" "Doe" "PhD" "Background info" "[email protected]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment