# Chaining

This is the mechanism on how to chain scenarios for Autokin. Let us say that you want to Login the user then use the session token to retrieve user information.

```
    POST https://www.autokinjs.com/login
    Headers:
    Content-Type: application/json
    {
        "username": "juan",
        "password": "p3dr0"
    }

    Response:
    {
        "sessionId": "2AA21boNhOM5zR3Xgn96qw=="
    }

    GET https://www.autokinjs.com/user/1001
    Headers: 
    Content-Type: application/json
    SessionId: 2AA21boNhOM5zR3Xgn96qw==

    Response:
    {
        "id": 1001,
        "name": "Juan Pedro",
        "age": 30 
    }
```

So having that we can have this Feature definition:

```
@chaining
Feature: My Chaining Feature
	As Autokin tester
	I want to verify that all API are working as they should

    Scenario: Login to the system
        Given that a secure endpoint is up at www.autokinjs.com
        Given I set Content-Type header to application/json
        Given I set the JSON body to 
        """
        {
            "username": "juan",
            "password": "p3dr0"
        }
        """
        When I POST /login
        Then response status code should be 200
        Then I keep the value of body path "$.sessionId" as "userSessionToken"

    Scenario: Get user information
        Given that a secure endpoint is up at www.autokinjs.com
        Given I set Content-Type header to application/json
        Given I set SessionId header from "userSessionToken"
        When I GET /user/1001
        Then response status code should be 200
```

As you see in the above example, we login then we store the session token to a variable `userSessionToken`, the variable name can be anything as long as a one word. Following to our next scenario, as needed by our API, we set the header `SessionId` to the value of the previously stored data by specifying that we are getting the stored value from the variable `userSessionToken`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://autokin.gitbook.io/docs/features/chaining.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
