This feature (API Access) is only available to CommCare users with a Pro Plan or higher. For more details, see the CommCare Software Plan page.
Setting up a remote API connection
CommCare HQ manages remote API services and credentials under Project Settings > Connection Settings.
Give your connection a name.
Provide one or more addresses to send notifications to if something unexpected happens when forwarding data
Specify the URL that CommCare will be sending data to
And then select how CommCare must authenticate with the remote API, and provide credentials as required.
Setting up Data Forwarding
You can configure your project to forward any incoming forms and/or cases to a specified URL. To do so, in CommCare HQ navigate to ProjectSettings and then to Data Forwarding. It will look something like this:
There are no current limitations on the number of repeaters you can add to your project, but if you set up a repeater and notice a delay in record forwarding times, please contact our support team.
What to have your server expect
Data will be forwarded, and the contents of what is forwarded will be in the body of the HTTP POST. This does not use HTML form-style parameters.
In the examples below, we'll show you what HTTP Headers and POST body to expect. All newlines and indentation is for clarity only below; in the actual post any newline + indentation will be a single space.
You get the complete form (one POST per form)
In addition to the form there will be an extra header 'received-on' that is the time the form was received by CommCare HQ.
You get a case block representing the latest state of any cases affected by the form (one POST per case).
When you turn on case forwarding, every time a case changes on HQ, it will forward the case in its entirety to your URL (not just the last change). We expect that you will receive the case, look to see if there's a case with the same id already in your system, and then either create or update the case with all the information given. If the case has been closed, we will send the case with just a close block.
The URL you set up to deal with the in-coming information can expect to receive one case block at a time, in the format specified below (XML or JSON).
In addition to the case there will be an extra header 'server-modified-on' that is the last time the case was modified in CommCare HQ.
You get a timestamp (GMT), the form's id, and the ids of any affected cases
This works especially well in conjunction with our Data APIs; you can get notified of a change using Form Stub Forwarding and then use the Data APIs to look up the form and cases affected, either right away or at a later date.
CommCare will send error notifications to the email addresses specified for the remote API connection under Connection Settings. This will happen for errors raised by the remote API, like server errors, authentication errors, response timeouts, or network connection failures.
The notification will show the error message as given by the remote API, and will include the name of the project space, the URL that the request was sent to, and, if applicable, the ID of the form or case that was sent, so that the recipient has the information they need to follow up.
The email will also include instructions on how to stop getting notification in the future. All remote API connections should have at least one email address for notifications so that if data forwarding stops working for any reason, someone is aware of that.