Skip to content
Developerhome

apiGet

  Less than to read

Summary

The apiGet method is used to retrieve data for a single item from an API and store it in the Redux store for use in a screen. This guide provides an overview of how to use apiGet effectively and explores its different purposes.

Purposes of apiGet

  • Reading Data to Edit/Write Back: By default, apiGet is designed to fetch data into a screen with the intention of editing it and writing it back to the API. It assumes that the screen has separate controls for each field and unpacks the data from a single object into individual key/value pairs. This format is ideal for binding the data to different field controls in the screen. Additionally, apiGet updates the screen’s initial values, which is important for validation and tracking changes made to the screen.

  • Reading Data for Reference: If you only need to read data for reference purposes, such as retrieving a settings file, you can specify a key to store the data. The apiGet method will fetch the object from the API and store it as an object under the specified key. In this case, the data is stored without any unpacking.

  • Providing Data for Select Control: In certain cases, you may need to fetch data to populate a select control that requires both a foreign key and a foreign object. To achieve this, you can specify a key that ends with “_id” to store the data’s ID and a matching key to store the data object. For example, using the key “tax_code_id” would store the data’s ID at that key and the data object at the corresponding key “tax_code”. Additionally, the screen’s initial values will be updated to reflect the fetched data for validation and tracking purposes.

apiGET Parameters

Parameters Description
endpoint The URL for Sage 200 API endpoint that you require (e.g. v1/departments or v1/customers)
id (Optional) The ID of the item to be fetched.
queryParms (Optional) Additional query parameters to be included in the request (e.g., $filter, $select).
prefix (Optional) A prefix to separate the data in the Redux store.
isInDialog (Optional) Determines how initialValues are stored. When set to true (default), initialValues are stored separately for child dialogs, maintaining their own version independently. When set to false, initialValues are merged with the main parent screen. If data is to be displayed on the main form (eg in tab), then isInDialog should be set false, so that data is merged into the parent form’s initialValues; for consistent field validation, form dirtiness.

apiGet Example

"apiGet": {
	"endpoint": "v1/departments",
	"prefix": "",
	"id": {
		"get": {
		  "state": "dept_id"
	  }
	},
	"queryParams": {
	  "$expandall": "true"
	}
}