# Magical Autocomplete

**Magical Autocomplete** is a feature in Cosmocloud which is introduced to access dynamic values within the API Flow.

User can access these values using **`$.`** abbreviation. This is super helpful when you want to access data from one node into another, for example reusing some value returned by parent in child.

When user type **$.** in any input field in the node's properties window, it gives the user a list of autocomplete values which user can assess in that node level.

## Accessing values using \`$.\`&#x20;

These are 4 ways to access data using Magical Autocomplete -

* **Node data:** `$.<node_name>.<key>`
* **Variables:** `$.variable.`<mark style="color:red;">`<variable_name>`</mark>
* **Token data:** `$.tokenData.`<mark style="color:red;">`<key>`</mark>
* **Custom secrets data:** `$.secrets.`<mark style="color:red;">`<secret_name>`</mark>`.`<mark style="color:red;">`<key_name>`</mark>

## Accessing node data using \`$.\`

Nodes in cosmocloud are  basic building blocks for your API's. Each node can be considered as a single operation ( e.g. create , update , delete etc. ) that user needs to perform in flow.

Some of these nodes return values which can later be used in the flow.&#x20;

For e.g. `API call`  node is used to call an external API which in turn returns us `statusCode` and `body`

Now to access the values returned by this node we can use following syntax&#x20;

`$.<node name>.<return value>`

### Example

Let us assume you make an external API call using `API call` node and want to access the response in the flow.

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FYeHZ6Mepfdr1yQS3J5nh%2Fimage.png?alt=media&#x26;token=3441ca21-91b9-4545-9255-3f60f958e2b0" alt=""><figcaption></figcaption></figure>

Now we can access the value of this node as :&#x20;

* `$.node_7.body`
* `$.node_7.statusCode`

## Accessing variables using \`$.\`

Some of the nodes in cosmocloud is used to initialise variables is runtime. These nodes create a new variables which can later be accessed in the flow. eg.  `Set Variable` , `Build JSON`  etc.

You can access these variables using `$.variables.<variables name>`

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2FhVbQH4ScgUfPhczW86nr%2Fimage.png?alt=media&#x26;token=a1bef74c-7ac8-4510-b525-24c90bc7e7c9" alt=""><figcaption></figcaption></figure>

For the variable declared above using `Set Variable` node you can access it as `$.variables.newVariable`

## Accessing token data using \`$.\`

Accessing token data using $ abbreviations is very easy. you can either access raw token to be used in external API calls or you can access decoded token for values.&#x20;

**$.tokenData** helps you access `decoded bearer token` values or `raw token` to be used in external API's&#x20;

<figure><img src="https://392607133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZCdm9aJ8vkvDIIbg04AL%2Fuploads%2F0sAWjjxPCGfuMJaHXmfd%2Fimage.png?alt=media&#x26;token=9c3674b7-d6ab-4776-8259-b9295c2cc2ef" alt="" width="375"><figcaption><p>accessible values using $.tokenData</p></figcaption></figure>

* **Raw token** : $.tokenData.rawToken
* **Decoded token** : $.tokenData.\<variable\_name>

### Example&#x20;

Let us assume you are using a authentication service on cosmocloud and schema of your decoded token is in given format&#x20;

```javascript
{
  id : "012345678abcde"   // user id
  email : "example@gmail.com" //user email
  exp : 1234567643 // token expire at time
}
```

Now assume you want to access `user email` from `bearer token` . You can access is by \
`$.tokenData.email`  and use it anywhere in your flow.

Now, what if you want to access bearer token as it is,  so that you can use it for any external service ?&#x20;

well you can access `raw token` as `$.tokenData.rawToken`

## Accessing secrets using \`$.\`

Let us assume you have created a new `custom secret`  named as  `AWS_SECRETS`  which store values for AWS credentials such as :

* DEFAULT\_REGION
* QUEUE\_NAME

Now what if you want to access these values in flow? well you can access them using following syntax  `$.secrets.<SECRET_NAME>.<KEY_TO_ACCESS>`&#x20;

for above case you can access these values as :&#x20;

* $.secrets.AWS\_SECRETS.DEFAULT\_REGION
* $.secrets.AWS\_SECRETS.QUEUE\_NAME
