CreateDepartment
Organisation service 1.9: Creates a department under a parent - the new department is INACTIVE until UpdateDepartment is called.
| Service | Organisation 1.9 |
| Endpoint | POST https://app{server-number}.timelog.com/{account}/WebServices/Organisation/V1_9/OrganisationServiceSecure.svc |
| SOAPAction | http://www.timelog.com/api/tlp/v1_9/OrganisationService/CreateDepartment |
| Content-Type | text/xml; charset=utf-8 |
| Authentication | A token from GetToken |
| Changes data | Yes |
| Safe to retry | Only when you send your own departmentGuid: a retry after an ambiguous failure either creates the department or fails with 'Unable to insert new department'. |
How it works
The department is stored with IsActive = 0: the domain object is created inactive and Create never activates it. It therefore does not appear in GetDepartments, and the contract has no IsActive member to show it - call UpdateDepartment with the same values to activate it.
Parameters
Each parameter has one label: Required, Conditional (required depending on other values) or Optional. Send them in the order shown.
Optional. GUID for the new department.
Optional. Default null -> stored as NULL, read back as empty string. Department number. Not checked for uniqueness - a duplicate breaks GetDepartmentByNo for that number.
Optional. GUID of the parent department.
Optional. Any existing employee.
The token from GetToken: Initials, Expires and Hash, sent back unchanged.
Request
POST /{account}/WebServices/Organisation/V1_9/OrganisationServiceSecure.svc HTTP/1.1
Host: app{server-number}.timelog.com
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://www.timelog.com/api/tlp/v1_9/OrganisationService/CreateDepartment"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:org="http://www.timelog.com/api/tlp/v1_9"
xmlns:tok="http://www.timelog.com/api/tlp/v1_3">
<soapenv:Body>
<org:CreateDepartment>
<org:departmentGuid>{departmentGuid}</org:departmentGuid>
<org:name>{name}</org:name>
<org:no>{no}</org:no>
<org:parentDepartmentGuid>{parentDepartmentGuid}</org:parentDepartmentGuid>
<org:departmentManagerGuid>{departmentManagerGuid}</org:departmentManagerGuid>
<org:token>
<tok:Initials>{Initials from GetToken}</tok:Initials>
<tok:Expires>{Expires from GetToken, unchanged}</tok:Expires>
<tok:Hash>{Hash from GetToken}</tok:Hash>
</org:token>
</org:CreateDepartment>
</soapenv:Body>
</soapenv:Envelope>
curl -X POST "https://app{server-number}.timelog.com/{account}/WebServices/Organisation/V1_9/OrganisationServiceSecure.svc" \
-H "Content-Type: text/xml; charset=utf-8" \
-H 'SOAPAction: "http://www.timelog.com/api/tlp/v1_9/OrganisationService/CreateDepartment"' \
--data-binary @request.xml
import requests
URL = "https://app{server-number}.timelog.com/{account}/WebServices/Organisation/V1_9/OrganisationServiceSecure.svc"
SOAP_ACTION = '"http://www.timelog.com/api/tlp/v1_9/OrganisationService/CreateDepartment"'
envelope = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:org="http://www.timelog.com/api/tlp/v1_9"
xmlns:tok="http://www.timelog.com/api/tlp/v1_3">
<soapenv:Body>
<org:CreateDepartment>
<org:departmentGuid>{departmentGuid}</org:departmentGuid>
<org:name>{name}</org:name>
<org:no>{no}</org:no>
<org:parentDepartmentGuid>{parentDepartmentGuid}</org:parentDepartmentGuid>
<org:departmentManagerGuid>{departmentManagerGuid}</org:departmentManagerGuid>
<org:token>
<tok:Initials>{Initials from GetToken}</tok:Initials>
<tok:Expires>{Expires from GetToken, unchanged}</tok:Expires>
<tok:Hash>{Hash from GetToken}</tok:Hash>
</org:token>
</org:CreateDepartment>
</soapenv:Body>
</soapenv:Envelope>"""
response = requests.post(
URL,
data=envelope.encode("utf-8"),
headers={"Content-Type": "text/xml; charset=utf-8", "SOAPAction": SOAP_ACTION},
timeout=60,
)
result = parse_result(response) # see "Responses and errors"
{…} placeholder with your own value.Response
The call returns the standard response envelope. Check ResponseState first: a failed call still returns HTTP 200.
Success, Invalid or Error.
0 on success, otherwise the error code. See Errors.
Response<Department>: Return holds the department as SENT - ID, Name, No, ParentDepartmentGuid, DepartmentManagerGuid - with DepartmentID = 0. Success message names return type 'Department'. Never - failure is an Error envelope with an empty Return.
Example response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreateDepartmentResponse xmlns="http://www.timelog.com/api/tlp/v1_9">
<CreateDepartmentResult xmlns:a="http://api.timelog.com"
xmlns:b="http://www.timelog.com/api/tlp/v1_9"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Return>
<b:Department>
<a:Action>Original</a:Action>
<a:IsCustomFieldsLoaded>false</a:IsCustomFieldsLoaded>
<a:CustomFields i:nil="true"/>
<a:IsExternalKeysLoaded>false</a:IsExternalKeysLoaded>
<a:ExternalKeys i:nil="true"/>
<b:ID>3f2504e0-4f89-41d3-9a0c-305000000001</b:ID>
<b:Name>Example </b:Name>
<b:No>1001</b:No>
<b:ParentDepartmentGuid>3f2504e0-4f89-41d3-9a0c-305000000002</b:ParentDepartmentGuid>
<b:DepartmentManagerGuid>3f2504e0-4f89-41d3-9a0c-305000000003</b:DepartmentManagerGuid>
<b:DepartmentID>1001</b:DepartmentID>
</b:Department>
</a:Return>
<a:ReturnTypeDescription>Department</a:ReturnTypeDescription>
<a:Request>…</a:Request>
<a:ResponseState>Success</a:ResponseState>
<a:Messages>
<a:APIMessage>
<a:Message>Duration of call was 0,0421337 sec.</a:Message>
<a:Severity>Message</a:Severity>
<a:ErrorCode>0</a:ErrorCode>
</a:APIMessage>
</a:Messages>
<a:ErrorCode>0</a:ErrorCode>
<a:IsReturnPaged>false</a:IsReturnPaged>
<a:TotalPageCount>0</a:TotalPageCount>
</CreateDepartmentResult>
</CreateDepartmentResponse>
</s:Body>
</s:Envelope>
Request block is shortened.Errors
All errors come back with HTTP 200: check ResponseState, ErrorCode and Messages. The errors every operation can return (expired or invalid token, API not enabled, HTTPS required, general errors) are listed once in Responses and errors.
Errors specific to this operation:
| ResponseState | ErrorCode | Message | What it means | What to do |
|---|---|---|---|---|
| Error | 40001 | Error during call on TimeLog.API, Message 'Your site doesn't have departments enabled' | The department reads are not gated. | Enable departments on the account, or do not maintain departments through the API. |
| Error | 40001 | Error during call on TimeLog.API, Message 'Department name is not allowed to be empty' | name null, empty or whitespace. | Send a non-empty name. |
| Error | 40001 | Error during call on TimeLog.API, Message 'Unable to retrieve department from … with DepartmentGUID {guid}' | parentDepartmentGuid does not exist. | Take the GUID from GetDepartments or GetDepartmentByNo. |
| Error | 40001 | Error during call on TimeLog.API, Message 'No employee with ID "{guid}" found.' | departmentManagerGuid is not an employee GUID. | — |
| Error | 40001 | Error during call on TimeLog.API, Message 'The Department violates the Business Rules for Departments' | Parent already on level 4. | Choose a parent higher in the tree. |