Trying the BioID Web Service REST API with Windows PowerShell
In a recent blog post we described how to interact with the BioID Web Service (BWS) RESTful API as an Client App with the cURL command line tool. While this tool is common on UNIX and akin systems the PowerShell is the default scripting environment on Microsoft Windows systems.
Thus we repeat the walk through from the blog post Trying the BioID Web Service REST API with cURL with the equivalent Windows PowerShell commands here. The cmdlets we use for this example require at least Windows PowerShell 3.0.
If you not done already you first need to register for a free BioID account. After registration you can already play around with biometrics using your web cam or microphone but in this post we want to cover the usage of the API.
First you need to apply for an BWS trial instance and register a sample client app. Trying REST API with cURL is an explanation how. Then you can upload image files and perform biometric operations on those files.
Give me a token
Before we get our token we should prepare the PowerShell environment to save some typing. Open a PowerShell window and use the following commands to set your credentials.
You can use the Get-Credential cmdlet to open a authentication dialog box to enter your Client App Identifier and the secret.
Or you can use following commands to set the credentials in the shell.
Next we request the enrollment token and convert it into a header for the Invoke-RestMethod cmdlet.
Now we can check if user 42 is already enrolled with images of the face. Therefore we use the isenrolled API call with the BCID of the user.
If the user hasn't been enrolled yet the API call returns the error 404 Not Found obviously.
If the person is already enrolled the cmdlet will just return silently. With the PowerShell cmdlet Invoke-WebRequest we get a little more verbose output if there are already images (or voice samples) uploaded and a biometric template is present:
StatusCode OK tells us there are already some images enrolled.
May I introduce
Now we upload the encoded images a.png.txt and b.png.txt with the following two commands to the BWS:
If everything works well following return message is shown in the PowerShell window.
The images are uploaded and can be enrolled with the next command. Since the token has only a limited lifetime you should perform the upload commands and enrollment command without a larger break. Otherwise simply request a new token and start over.
This return message shows the success of the command.
Now the isenrolled API call should return a 200 OK.
The Invoke-REST method just returns silently if the call succeeded so again you can use the Invoke-WebRequest cmdlet for a more verbose result message.
Now we'll try to perform a verification (API) with a third image we haven't enrolled. First we acquire the token for verification, then we upload the image and last we perform the verification API call.
With the token we can now upload the image and perform the verification.
The BWS Result API call returns some more information. It shows if the operation succeeded or not, the action perfomed and the BCID of the individual we performed the operation on.
You can learn more about the RESTful API calls, e.g. result codes or parameters, of the BioID Web Service in our Web API documentation.