Example use of the Cost Codes API¶
The following section aims to give a brief example use case for loading cost codes. The section does not go into an elaborate scenario, as loading cost codes is very straightforward.
Scenario: loading cost codes from a Finance file¶
Currently, the integration supports pushing cost codes into Sapio LIMS. Therefore, this scenario is for the Integration Hub to load a batch of cost codes, received from ERP/Finance as a file, into Sapio.
Info
As mentioned before, this is the Phase 1 shape of the integration. Until the ERP is set up, the cost codes arrive as a file from Finance, and the Integration Hub is the only caller of the POST /cost_codes/v1 endpoint. When the full integration is in place (Phase 2), Sapio will instead pull cost codes directly from the ERP through a separate Experience API with a GET resource.
Assume that Finance has issued a file containing a new cost code S-12345 for a science project studying leukaemia in children with Down syndrome. The cost code needs to exist in Sapio before any spend can be assigned to it. The details from the file are as follows:
1 2 3 4 5 6 7 8 | |
Warning
The integration does not enrich or transform the cost code data. Only the fields with a matching Sapio project field are created — the project code (ProjectId), the description (ProjectDesc), the lifecycle status (C_Status), and the effective start and end dates (StartDate, EndDate). Anything else in the payload, such as Type or Roles, is accepted but not stored in Sapio.
However, the integration does validate the essential fields — the project code and the project description — which are crucial for creating the record. In a case where these are missing or invalid, the integration would return a "Bad Request" response with proper error messages, before anything reaches Sapio.
To achieve this, the Integration Hub would need to:
- Authenticate with the Cost Codes API.
- Prepare and send the payload to the
POST /cost_codes/v1endpoint of the integration.
Authenticating with the API¶
In order to authenticate, the caller would have to follow the standard OAuth 2.0 protocol, as explained in the "Authentication & Authorisation Strategy" section. Basically, the calling application would need to invoke a /token endpoint and receive a token, and use the token in the headers to authorise with the POST /cost_codes/v1 endpoint. To receive the token, the client would have to use the client credentials established as part of the onboarding process discussed in the "How to use" section.
Preparing the payload¶
In order to prepare the payload, the Integration Hub would need to determine:
- Which cost codes from the file are to be loaded
- Whether any of them already exist in Sapio
These two points are dependent on each other. Sapio enforces uniqueness on the project code, and the load is atomic — so if even one code in the batch already exists, the whole batch is rejected and nothing is created.
Also, every entry must carry a valid project code and description; if either is missing or malformed, the integration would respond with a "Bad Request" 400.
After the Integration Hub has the aforementioned two points figured out, they can prepare the payload as follows — a JSON array, with one entry per cost code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Warning
In order for the client to be authorised to the POST /cost_codes/v1 endpoint, the client needs to submit the above payload with the Bearer token received via the /token endpoint. This is again the standard OAuth 2.0 procedure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
After the request has been submitted, the integration would return a 201 Created, with one entry per submitted cost code containing the project ID and the record ID that Sapio generated:
1 2 3 4 5 6 7 8 9 10 | |
Info
Receiving a 201 Created means the cost codes now exist in Sapio as project records and are ready to have spend assigned against them. If anything went wrong instead — a duplicate code, a validation failure, or Sapio being unavailable — the response would carry the appropriate error status and a message explaining the cause, as described in the "Troubleshooting" section. Every response also includes a correlation ID (the X-Amzn-Trace-Id header), which is worth keeping hold of when reporting a problem.