Difference between revisions of "API Details"

From Charitylog Manual
Jump to: navigation, search
(Created blank page)
 
Line 1: Line 1:
 +
Authentication
 +
The API grants access based on three headers:
  
 +
 +
Org the Charitylog client
 +
 +
 +
Source The integration (e.g Dizions CRM, Steps etc) which also controls project visibility
 +
 +
 +
User User record, controls branch, project and field visibility
 +
 +
 +
Groups
 +
The API is based around a range of groups that map to various entities.
 +
 +
clients (organisations that are "people")
 +
referrals (diary)
 +
done_contacts (completed actions)
 +
due_contacts (outstanding actions)
 +
workers (support workers)
 +
schedules (job cards)
 +
 +
An example URL would look like (GET) https://api.dizions.co.uk/v2/clients
 +
Filters
 +
If you want to filter your results, you can keep adding up to 10 key/value pairs to the URL. The value can usually take multiple values separated by a ;.
 +
The example below would get all clients that have a religion (org_religion) ID of 1,3 or 10 and an ethnicity (org_ethnic_group) ID of 1.
 +
[GET] https://api.dizions.co.uk/v2/clients/religion/1;3;10/ethnicity/1
 +
Here's another example. You would see completed actions for project ID 5, where the client was unemployed and registered disabled.
 +
[GET] https://api.dizions.co.uk/v2/done_contacts/client_registered_disabled/Y/client_employment_status/N/project/5
 +
You can also filter by the record ID (getting a single record)
 +
[GET] https://api.dizions.co.uk/v2/referrals/id/510.
 +
For referrals and clients you can actually filter by single record extension database value(s).
 +
[GET] https://api.dizions.co.uk/v2/clients/website_photo_consent/109
 +
For referrals, contacts and schedules you can restrict the results to a date range.
 +
[GET] https://api.dizions.co.uk/v2/referrals/date_active/2018-10-01,2018-10-31
 +
Selecting Specific Fields
 +
When you hit an endpoint, a range of default fields are automatically returned. If you want something that isn't default, or you want to return less data to speed things up, you can pick the fields to be returned. In the case of referrals or clients you can also return any single record extension databases. Use /field/ with semicolon separated field names to choose the fields you want to return.
 +
[GET] https://api.dizions.co.uk/clients/field/id;surname;website_photo_consent
 +
The API can tell you which fields are available by appending /selectable_fields to the group.
 +
 +
[GET] https://api.dizions.co.uk/v2/clients/selectable_fields
 +
 +
[GET] https://api.dizions.co.uk/v2/workers/selectable_fields
 +
 +
[GET] https://api.dizions.co.uk/v2/referrals/selectable_fields
 +
 +
[GET] https://api.dizions.co.uk/v2/due_contacts/selectable_fields
 +
 +
[GET] https://api.dizions.co.uk/v2/done_contacts/selectable_fields
 +
 +
[GET] https://api.dizions.co.uk/v2/schedules/selectable_fields
 +
 +
 +
Creating Records
 +
To create a record you need to do a [PUT] request, with fields in the body. Many of these will have a selection of mandatory fields.
 +
Create a client:
 +
[PUT] https://api.dizions.co.uk/v2/clients
 +
Create a client by an external ID (e.g a reference to the client in another system):
 +
[PUT] https://api.dizions.co.uk/v2/clients/external_id/EXTERNAL_ID
 +
Create a referral (Record a Contact):
 +
[PUT] https://api.dizions.co.uk/v2/referrals
 +
Create a due contact (incomplete action) for a referral:
 +
[PUT] https://api.dizions.co.uk/v2/due_contacts/referral/REFERRAL_ID
 +
Updating Records
 +
To update records you need to use the [POST] method, with fields in the body. There will be some mandatory fields and some fields that need a value if present.
 +
Update a client:
 +
[POST] https://api.dizions.co.uk/v2/clients/id/CLIENT_ID
 +
Update a referral:
 +
[POST] https://api.dizions.co.uk/v2/referrals/id/REFERRAL_ID
 +
Update due contact
 +
[POST] https://api.dizions.co.uk/v2/due_contacts/id/CONTACT_ID
 +
Update done contact, or complete due contact (complete by completing the start_date and end_date in the body)
 +
[POST] https://api.dizions.co.uk/v2/done_contacts/id/CONTACT_ID
 +
File Uploads
 +
You can upload files against clients and referrals, these can only be uploaded to Amazon S3.
 +
[POST] https://api.dizions.co.uk/v2/clients/id/CLIENT_ID/uploads
 +
[POST] https://api.dizions.co.uk/v2/referrals/id/REFERRAL_ID/uploads
 +
In the body you'll need the files along with user_visibility and group_visibility settings which are IDs (comma separated if there's more than one)
 +
Single Record Extension Databases
 +
As mentioned previously, for referrals and clients you can select single record extension database data, or filter by these values. To expose these fields to the API you need to edit that field in the front end, setting Allow collaborator API access? to Yes and choosing a suitable Name to share with collaborators. You can then reference that extension database field by the collaborator name.
 +
Multiple Record Extension Databases [GET]
 +
Multiple record extension databases work as their own entity. They can be accessed in the API by a combination of their name and ID. Here's the SQL that generates the API name CONCAT(REPLACE(LOWER(ext_name)," ", "_"), "_", ext_id)
 +
Here's an example of an end point that gets all records for an extension database:
 +
[GET] https://api.dizions.co.uk/v2/extension_database/staff_disciplinary_13
 +
You can also specify which fields you want to select, to make things more efficient. Extension database records can be filtered in the same way as other requests, to get all results for a particular referral you can do this:
 +
[GET] https://api.dizions.co.uk/v2/extension_database/wellcheck_notes_9/referral/2289
 +
Multiple Record Extension Databases [PUT]
 +
To create a new record you need to do a [PUT] request.
 +
[PUT] https://api.dizions.co.uk/v2/extension_database/staff_disciplinary_13
 +
Then add the body:
 +
 +
referral 2289
 +
 +
date_43 2018-11-08
 +
 +
 +
The ID of the new record will be returned.
 +
Multiple Record Extension Databases [POST]
 +
To update a record you also need to supply the ID:
 +
[POST] https://api.dizions.co.uk/v2/extension_database/wellcheck_notes_9/id/17
 +
Then add the POST body in the same way as a PUT request.
 +
Reports
 +
These are intended for use with the Analytics Reporting Tool.  Reporting is based on dimensions and metrics, although metrics are optional. If you pass in a dimension against a group, you will get a breakdown of the number of occurrences.
 +
This will show you how many clients there are in each district:
 +
[GET] https://api.dizions.co.uk/v2/clients/dimension/district
 +
If you want this further broken down by gender:
 +
[GET] https://api.dizions.co.uk/v2/clients/dimension/district/metric/gender
 +
You can also filter the results in the same way as other [GET] requests:
 +
[GET] https://api.dizions.co.uk/v2/clients/dimension/district/metric/gender/main_disability/7;9/blue_badge_holder/Y
 +
To view a user's completed contacts by day for a range of time, you can do this:
 +
[GET] https://api.dizions.co.uk/v2/done_contacts/dimension/day/date_active/2018-10-01,2018-10-31/user/*USER_ID*
 +
Dictionaries
 +
Many of the values returned by the API are IDs, so there's a selection of dictionaries to get the friendly names. Some have been set up properly in datadict, others are set up manually.
 +
As a (slow and heavy) reference you can get all datadict dictionaries:
 +
[GET] https://api.dizions.co.uk/v2/dictionary (not suggested for general use)
 +
If the dictionary is set up in datadict you can access via api_group/table_reference. The end points below will return the full list of IDs and friendly names.
 +
 +
[GET] https://api.dizions.co.uk/v2/dictionary/organisations/district
 +
 +
[GET] https://api.dizions.co.uk/v2/dictionary/referrals/project
 +
 +
[GET] https://api.dizions.co.uk/v2/dictionary/contacts/contact_type
 +
 +
 +
You can also search for items in the dictionary:
 +
 +
[GET] https://api.dizions.co.uk/v2/dictionary/search/referrals/project/SEARCH_TERM
 +
 +
[GET] https://api.dizions.co.uk/v2/dictionary/search/referrals/referrer/SEARCH_TERM
 +
 +
 +
External Referrals (Web Forms)

Revision as of 14:59, 20 November 2018

Authentication The API grants access based on three headers:


Org the Charitylog client


Source The integration (e.g Dizions CRM, Steps etc) which also controls project visibility


User User record, controls branch, project and field visibility


Groups The API is based around a range of groups that map to various entities.

clients (organisations that are "people") referrals (diary) done_contacts (completed actions) due_contacts (outstanding actions) workers (support workers) schedules (job cards)

An example URL would look like (GET) https://api.dizions.co.uk/v2/clients Filters If you want to filter your results, you can keep adding up to 10 key/value pairs to the URL. The value can usually take multiple values separated by a ;. The example below would get all clients that have a religion (org_religion) ID of 1,3 or 10 and an ethnicity (org_ethnic_group) ID of 1. [GET] https://api.dizions.co.uk/v2/clients/religion/1;3;10/ethnicity/1 Here's another example. You would see completed actions for project ID 5, where the client was unemployed and registered disabled. [GET] https://api.dizions.co.uk/v2/done_contacts/client_registered_disabled/Y/client_employment_status/N/project/5 You can also filter by the record ID (getting a single record) [GET] https://api.dizions.co.uk/v2/referrals/id/510. For referrals and clients you can actually filter by single record extension database value(s). [GET] https://api.dizions.co.uk/v2/clients/website_photo_consent/109 For referrals, contacts and schedules you can restrict the results to a date range. [GET] https://api.dizions.co.uk/v2/referrals/date_active/2018-10-01,2018-10-31 Selecting Specific Fields When you hit an endpoint, a range of default fields are automatically returned. If you want something that isn't default, or you want to return less data to speed things up, you can pick the fields to be returned. In the case of referrals or clients you can also return any single record extension databases. Use /field/ with semicolon separated field names to choose the fields you want to return. [GET] https://api.dizions.co.uk/clients/field/id;surname;website_photo_consent The API can tell you which fields are available by appending /selectable_fields to the group.

[GET] https://api.dizions.co.uk/v2/clients/selectable_fields

[GET] https://api.dizions.co.uk/v2/workers/selectable_fields

[GET] https://api.dizions.co.uk/v2/referrals/selectable_fields

[GET] https://api.dizions.co.uk/v2/due_contacts/selectable_fields

[GET] https://api.dizions.co.uk/v2/done_contacts/selectable_fields

[GET] https://api.dizions.co.uk/v2/schedules/selectable_fields


Creating Records To create a record you need to do a [PUT] request, with fields in the body. Many of these will have a selection of mandatory fields. Create a client: [PUT] https://api.dizions.co.uk/v2/clients Create a client by an external ID (e.g a reference to the client in another system): [PUT] https://api.dizions.co.uk/v2/clients/external_id/EXTERNAL_ID Create a referral (Record a Contact): [PUT] https://api.dizions.co.uk/v2/referrals Create a due contact (incomplete action) for a referral: [PUT] https://api.dizions.co.uk/v2/due_contacts/referral/REFERRAL_ID Updating Records To update records you need to use the [POST] method, with fields in the body. There will be some mandatory fields and some fields that need a value if present. Update a client: [POST] https://api.dizions.co.uk/v2/clients/id/CLIENT_ID Update a referral: [POST] https://api.dizions.co.uk/v2/referrals/id/REFERRAL_ID Update due contact [POST] https://api.dizions.co.uk/v2/due_contacts/id/CONTACT_ID Update done contact, or complete due contact (complete by completing the start_date and end_date in the body) [POST] https://api.dizions.co.uk/v2/done_contacts/id/CONTACT_ID File Uploads You can upload files against clients and referrals, these can only be uploaded to Amazon S3. [POST] https://api.dizions.co.uk/v2/clients/id/CLIENT_ID/uploads [POST] https://api.dizions.co.uk/v2/referrals/id/REFERRAL_ID/uploads In the body you'll need the files along with user_visibility and group_visibility settings which are IDs (comma separated if there's more than one) Single Record Extension Databases As mentioned previously, for referrals and clients you can select single record extension database data, or filter by these values. To expose these fields to the API you need to edit that field in the front end, setting Allow collaborator API access? to Yes and choosing a suitable Name to share with collaborators. You can then reference that extension database field by the collaborator name. Multiple Record Extension Databases [GET] Multiple record extension databases work as their own entity. They can be accessed in the API by a combination of their name and ID. Here's the SQL that generates the API name CONCAT(REPLACE(LOWER(ext_name)," ", "_"), "_", ext_id) Here's an example of an end point that gets all records for an extension database: [GET] https://api.dizions.co.uk/v2/extension_database/staff_disciplinary_13 You can also specify which fields you want to select, to make things more efficient. Extension database records can be filtered in the same way as other requests, to get all results for a particular referral you can do this: [GET] https://api.dizions.co.uk/v2/extension_database/wellcheck_notes_9/referral/2289 Multiple Record Extension Databases [PUT] To create a new record you need to do a [PUT] request. [PUT] https://api.dizions.co.uk/v2/extension_database/staff_disciplinary_13 Then add the body:

referral 2289

date_43 2018-11-08


The ID of the new record will be returned. Multiple Record Extension Databases [POST] To update a record you also need to supply the ID: [POST] https://api.dizions.co.uk/v2/extension_database/wellcheck_notes_9/id/17 Then add the POST body in the same way as a PUT request. Reports These are intended for use with the Analytics Reporting Tool. Reporting is based on dimensions and metrics, although metrics are optional. If you pass in a dimension against a group, you will get a breakdown of the number of occurrences. This will show you how many clients there are in each district: [GET] https://api.dizions.co.uk/v2/clients/dimension/district If you want this further broken down by gender: [GET] https://api.dizions.co.uk/v2/clients/dimension/district/metric/gender You can also filter the results in the same way as other [GET] requests: [GET] https://api.dizions.co.uk/v2/clients/dimension/district/metric/gender/main_disability/7;9/blue_badge_holder/Y To view a user's completed contacts by day for a range of time, you can do this: [GET] https://api.dizions.co.uk/v2/done_contacts/dimension/day/date_active/2018-10-01,2018-10-31/user/*USER_ID* Dictionaries Many of the values returned by the API are IDs, so there's a selection of dictionaries to get the friendly names. Some have been set up properly in datadict, others are set up manually. As a (slow and heavy) reference you can get all datadict dictionaries: [GET] https://api.dizions.co.uk/v2/dictionary (not suggested for general use) If the dictionary is set up in datadict you can access via api_group/table_reference. The end points below will return the full list of IDs and friendly names.

[GET] https://api.dizions.co.uk/v2/dictionary/organisations/district

[GET] https://api.dizions.co.uk/v2/dictionary/referrals/project

[GET] https://api.dizions.co.uk/v2/dictionary/contacts/contact_type


You can also search for items in the dictionary:

[GET] https://api.dizions.co.uk/v2/dictionary/search/referrals/project/SEARCH_TERM

[GET] https://api.dizions.co.uk/v2/dictionary/search/referrals/referrer/SEARCH_TERM


External Referrals (Web Forms)