# restCall

## Description

Performs a rest API call using a Rest Connector.

## Input / Parameter

| Name       | Description                                           | Input Type    | Default      | Options                                                   | Required |
| ---------- | ----------------------------------------------------- | ------------- | ------------ | --------------------------------------------------------- | -------- |
| connector  | The Rest Connector to be used.                        | Text          | -            | -                                                         | Yes      |
| path       | The additional path to append to the connector's url. | Text          | -            | -                                                         | No       |
| method     | The http request method.                              | Text          | Get          | Get, Patch, Put, Post, Delete, Head, Options              | No       |
| query      | The query string for the endpoint.                    | Object        | -            | -                                                         | No       |
| callType   | The content type of the API.                          | Text          | Raw          | Form\_Data, X\_WWW\_Form\_URL\_Encoded, Raw, Binary, JSON | No       |
| headers    | The query string for the endpoint.                    | Object        | -            | -                                                         | No       |
| cookies    | The cookies of the API call.                          | Object / List | -            | -                                                         | No       |
| resultType | The preferred result to return.                       | Text          | String\_UTF8 | String\_UTF8, Byte\_Array                                 | No       |
| body       | The body to pass along in the call.                   | Object / Text | -            | -                                                         | No       |
| attachment | The path to the selected file.                        | Object / List | -            | -                                                         | No       |
| extra      | The stored value that is passed to all the callbacks. | Any           | -            | -                                                         | No       |

### cookies (Object | List)

Cookies of the API call. Will contain a single object, or a list of one (1) or more objects which consist of:

| Key   | Description                       | Input Type | Required |
| ----- | --------------------------------- | ---------- | -------- |
| name  | Name of the cookie.               | Text       | No       |
| value | Contains the value of the cookie. | Text       | Yes      |

### attachment (Object | List)

The path to the selected file. Will contain a single object, or a list of one (1) or more objects which consist of:

| Key   | Description                                              | Input Type | Required |
| ----- | -------------------------------------------------------- | ---------- | -------- |
| name  | Optional name. If not specified, file name will be used. | Text       | No       |
| value | Contains the direct file path of the attachments.        | Text       | Yes      |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The action performed if this function runs successfully.

| Description                                             | Output Type |
| ------------------------------------------------------- | ----------- |
| Returns an object with the information of the API call. | Object      |

#### Object

| Key        | Description                      | Output Type |
| ---------- | -------------------------------- | ----------- |
| statusCode | The status code of the API call. | Number      |
| result     | The result of the API call.      | Text        |
| cookies    | The cookies of the API call.     | Object      |

### errorCallback

The action performed if this function runs successfully.

| Description                                             | Output Type |
| ------------------------------------------------------- | ----------- |
| Returns an object with the information of the API call. | Object      |

#### Object

| Key          | Description                                  | Output Type |
| ------------ | -------------------------------------------- | ----------- |
| statusCode   | The status code of the API call.             | Number      |
| errorMessage | The error message for unsuccessful API call. | Text        |

## Example

In this example, we will create a connection using the restCall function.

### Steps

1. Drag a `REST Connector` component into the services panel in the Services page and fill the fields.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-d3314c883a0cb24928db265f5fc4bf5f5777d49a%2FrestCall-step-1.png?alt=media)
2. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-36378dd8298446b1a050281dc016db1ebc46b2fd%2FrestCall-step-2.png?alt=media)
3. Select the event `press` and drag the `Connector.restCall` function to the event flow and fill in the parameter.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-70167e786508511f78d3016daaea60fd725d0b8c%2FrestCall-step-3.png?alt=media)
4. Open the preview and try to press the Button, the rest api call should be visibile on the inspector network tab.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-b0f59c688216777b854dc1b3fdc76c1bf0e33c34%2FrestCall-step-4.png?alt=media)

### Result

The information of the API call should be returned.
