Apply to a Vacancy
Python example of how to create a new candidate user and apply to an existing vacancy using the REST API.
Use Case
An unregistered user creating a new application for an existing vacancy.
Prerequisites
- The first name, last name & email address of the user
- The vacancy ID of the vacancy that the user will apply to
This example will involve using the REST API
Creating A Candidate
Before an application can be made to a vacancy, we must create a candidate record for the user in question. See the Candidates & Applications concept for more information on the differences between an application and a candidate.
We only need to provide the candidate’s name and email address to successfully create a candidate record.
import requests
import json
# Authentication details for target system
username = "user"
password = "password"
url = "https://your-system.tal.net/vx/api/v1/candidates"
headers = {"accept": "application/json"}
data = {
"GivenName": "Test",
"FamilyName": "Candidate",
"Email": [
{
"Address": "testcandidate@example.com",
"Label": "personal",
"Preferred": "primary"
}
],
"UserArea": {
"UsernameEmail": "testcandidate@example.com"
}
}
# Create a new candidate with the details specified above
response = requests.post(url, auth=(username, password),
headers=headers, json=data)
candidate_ID = None
if(response.ok):
# Store the new candidate's ID
jData = json.loads(response.content.decode('utf-8'))
candidate_ID = jData["CandidateID"]
else:
# Display the http error code along with the description
response.raise_for_status()
Creating an Application
Now we have created our candidate, we’ll need to create an application to the target vacancy.
All we need at this stage is our newly created candidate ID and the ID of the vacancy you’d like to create an application for.
vacancy_id = 91
url = "https://your-system.tal.net/vx/api/v1/vacancies/{}/applications".format(
vacancy_id)
data = {"candidate_id": candidate_ID}
# Create a new application for the vacancy
response = requests.post(url, auth=(username, password),
headers=headers, json=data)
if(response.ok):
# Print response containing our new application
jData = json.loads(response.content.decode('utf-8'))
print(json.dumps(jData, indent=4,))
else:
response.raise_for_status()