# POST / PUT / DELETE Requests

#### POST / PUT / DELETE Requests

When calling a POST / PUT / DELETE method, three pieces of information are required:

1. The URL (This could also contain the query parameters)
2. The authentication token
3. The payload

{% hint style="warning" %}
POST, PUT and DELETE requests modify the original seed data that might affect other tests. Use [annotations](/api/automated-testing/functional-tests/annotations.md) to restore the data to the original state before the test was executed.&#x20;
{% endhint %}

{% hint style="info" %}
These requirements also apply to PATCH requests.
{% endhint %}

**POST Example:**

```php
/**
 * Test that the route /user/role returns 201
 *
 * @transaction auth
 * @test
 * @return void
 */
public function user_post_method_user_role_returns_201(): void
{
  $this->actingAsAdmin()
       ->authenticate()
       ->post('/user/role', [
          'organisation_id' => '1',
          'access_id' => '1',
       ]);
}
```

1. The URL in this example is `/user/role`
2. `authenticate()` authenticates the token
3. The third piece of information is the payload.

**PUT Example:**

<pre class="language-php"><code class="lang-php"><strong>$this->actingAsAdmin()
</strong>     ->authenticate()
     ->put('/user/mobilenumber', [
          "number" => "1555".rand(100000,999999)
     ])
</code></pre>

1. The URL in this example is `/user/mobilenumber`
2. `authenticate()` authenticates the token
3. The third piece of information is the payload.

**DELETE Example:**

```php
$this->actingAsAdmin()
     ->authenticate()
     ->delete('/courses/1', []);
```

1. The URL in this example is `/courses/1`
2. `authenticate()` authenticates the token
3. The third piece of information is the payload.

{% hint style="warning" %}
Even if there is no data, pass an empty array otherwise the response will be `403 forbidden`.
{% endhint %}


---

# 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://docs.elentra.org/api/automated-testing/functional-tests/testing-http-verbs/post-put-delete-requests.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.
