---
title: "Set up organisations for referral letters SMS workflow"
canonical: "https://wiki.patientsknowbest.com/space/api/4583784481/Set%20up%20organisations%20for%20referral%20letters%20SMS%20workflow"
format: markdown
---
It is possible for organisations to enable a workflow to send SMS to unregistered patients upon receiving a referral letter in their record.

To do so, we need:

- an employee to enable the workflow on the UI for the org (cf [this guide](https://wiki.patientsknowbest.com/space/MAN/4581294112/Gov.notify+for+sending+text+messages+(SMS)+-+IN+DRAFT))
- PKB / the org themselves to set up a new service on [GOV.UK](http://GOV.UK) Notify API webpage (cf [this guide](https://wiki.patientsknowbest.com/space/MAN/4581294112/Gov.notify+for+sending+text+messages+(SMS)+-+IN+DRAFT))
- a dev to add the credentials and sms setup into the database

This page covers the last bullet point. To create new credential and sms properties, the notification service exposes some controllers. (see `NotifyCredentialsController`and `NotifySmsPropertiesController`) Hence, we only need to send requests with the right parameters to the notification service using curl.

## Step 1: connecting to the right cluster

To be able to send requests using curl to the notification service, we need to connect to the right cluster and then forward the notificationservice pod port to our localhost.

#### Connecting to RC

```shell
gcloud container clusters get-credentials sandbox-2 --zone europe-west2-b --project develop-238811
kubectl port-forward deployment/notificationservice -n rc 40000:8080
```

#### Connecting to UK Prod

```shell
gcloud container clusters get-credentials uk-prod-1 --zone europe-west2-c --project prod-239510
kubectl port-forward deployment/notificationservice -n uk 40000:8080
```

## Step 2: sending a request

#### Create or update credentials for an organisation

This is what we use to authenticate to the [gov.uk](http://gov.uk) notify API. What you need:

- the organisation resourceId (`Organization/<some-uuid>`)
- the serviceId
- the apiKey

Both the serviceId and apiKey are created during the set up of the [GOV.UK](http://GOV.UK) Notify service. (covered in [this guide](https://wiki.patientsknowbest.com/space/MAN/4581294112/Gov.notify+for+sending+text+messages+(SMS)+-+IN+DRAFT)).

```shell
curl -X POST "localhost:40000/notify-credentials?orgResourceId=<some-org-resource-id>&serviceId=<some-uuid>&apiKey=<some-api-key>" -H "Content-Type: application/fhir+json" -v
```

#### Revoke credentials

```shell
curl -X PUT "localhost:40000/notify-credentials/revoke?orgResourceId=<some-org-resource id>" -H "Content-Type: application/fhir+json" -v
```

#### Create or update sms properties

What you need:

- the organisation resourceId (`Organization/<some-uuid>`)
- the templateId
- an optional senderId : this allows the org to send SMS from a specific sender display. It is optional. If it is null, the [GOV.UK](http://GOV.UK) Notify API will use the default sender set up in the service.

```shell
curl -X POST "localhost:40000/notify-sms-properties?orgResourceId=<some-org-resource-id>&templateId=<some-uuid>&senderId=<some-uuid>" -H "Content-Type: application/fhir+json" -v
```

Example without senderId:

```
curl -X POST "localhost:40000/notify-sms-properties?orgResourceId=<some-org-resource-id>&templateId=<some-uuid>" -H "Content-Type: application/fhir+json" -v
```

## Step 3: check your call was successful

You only need to read the response from the curl call you just made, however, you can also check the new rows were inserted into the db like so:

1. From intelliJ, start the appropriate SQL Proxy ('Prod UK - Notification Service' or ‘RC - Notification Service’)
2. Open a console ('UK - notificationservice' or ‘RC - notificationservice’)
3. Run one of these queries to check your calls were successfull

```sql
select * from notif.notify_credentials where org_downstream_resource_id = '<some-org-resourceId>';

select * from notif.notify_sms_properties where org_downstream_resource_id = '<some-org-resourceId>';
```

Note: if you need to see the history of credentials used you can look into the respective tables in the ‘history’ schema.