# Creating Tasks and Accepting Reservations: Create a Task using the REST API

Recall the TaskRouter Task lifecycle:

***Task Created** → eligible Worker becomes available → Worker reserved → Reservation accepted → Task assigned to Worker.*

Before we create our first Task, make sure that our Worker Alice is in a non-available Activity state. Bob's Activity state won't matter right now, as we will create a Spanish language Task that he is not eligible to handle.

With your Workspace open in the [TaskRouter console](https://www.twilio.com/console/taskrouter/workspaces), click 'Workers' then click to edit Alice and set her Activity to 'Offline'. Your Workers should look like this:

![Worker status: Alice is offline for 7 seconds, Bob is idle for 28 seconds.](https://docs-resources.prod.twilio.com/1b2d27d5082176ded64ae09ed6e01a9b98cfb573ebceb031ef79aa10219722d7.png)

To simulate reality, we'll create a Task using the REST API rather than the web portal. We'll add on to our `server.rb` to create a task with our web server. Replace the \{} with your Twilio AccountSid, Twilio AuthToken, WorkspaceSid, and WorkflowSid.

Download and extract [Twilio's Ruby SDK](https://github.com/twilio/twilio-ruby) into the same directory that you are working in. This is required as we're utilizing the SDK to create a task and will continue to use the library in subsequent steps.

server.rb

```ruby
require 'rubygems'
require 'twilio-ruby'
require 'sinatra'
require 'json'
set :port, 8080

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = '{{ account_sid }}'
auth_token = '{{ auth_token }}'
workspace_sid = '{{ workspace_sid }}'
workflow_sid = '{{ workflow_sid }}'

client = Twilio::REST::Client.new(account_sid, auth_token)

post '/assignment_callback' do
# Respond to assignment callbacks with empty 200 response
content_type :json
{}.to_json
end

get '/create-task' do
# Create a task
task = client.taskrouter.workspaces(workspace_sid)
.tasks
.create(
attributes: {
'selected_language' => 'es'
}.to_json,
workflow_sid: workflow_sid
)
task.attributes
end
```

Alternatively, we can also create a Task using the command line utility `curl`, which should exist on any Mac or Linux workstation. Again, remember to replace the \{} with your matching credentials and Sids, then execute the following command at your terminal:

```bash
curl https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSid}/Tasks \
--data-urlencode Attributes='{"selected_language": "es"}' \
-d WorkflowSid={WorkflowSid} \
-u {AccountSid}:{AuthToken}
```

You can find your Twilio AccountSid and AuthToken on the [TaskRouter Getting Started page](https://www.twilio.com/console/taskrouter/getting-started) by clicking 'show API credentials'.

*If you don't have curl, you can run this request using an HTTP test tool like [Postman](https://www.getpostman.com/) or using the Task creation dialog in the TaskRouter web portal: with your Workspace open, click 'Tasks' then 'Create Task'.*

To see our newly created Task in the TaskRouter web portal, with your Workspace open, click 'Tasks' in the main navigation. Notice that the Task has been added to the "Customer Care Requests - Spanish" Task Queue based on the Attributes we provided in the curl request. The Assignment Status is 'pending' because there is no available Worker that matches the Task Queue:

![Task list showing a pending customer care request in Spanish with priority 0 and age 51 seconds.](https://docs-resources.prod.twilio.com/4ee935ab26f4a4a45a0e2017cd670f5d860e1537e107432f261323bc379d0079.png)

## Make an Eligible Worker Available

Look again at the TaskRouter Task lifecycle:

*Task Created → **eligible Worker becomes available** → Worker reserved → Reservation accepted → Task assigned to Worker.*

The first stage - 'Task Created' - is complete. To trigger an automatic Task Reservation, the next step is to bring en eligible Worker (in this case Alice) online.

With your Workspace open in the TaskRouter web portal, click 'Workers', then click to edit Alice and set her Activity to 'Idle':

![Alice's activity status set to Idle in Customer Care Center workspace.](https://docs-resources.prod.twilio.com/9db336f78810480f4e9a1e2efe0b331889b0f29decc5bfe75394e9df3dfc695e.png)

When you hit save, Twilio will create a Reservation between Alice and our Task and you will receive a Webhook request at the Assignment Callback URL that we set up in the previous step. If you're using ngrok, open `http://localhost:4040` in your web browser to see a detailed log of the request that Twilio made to your server, including all the parameters that your server might use to determine whether to accept a Reservation:

![Ngrok POST request log showing assignment callback with form parameters including AccountSid and TaskAttributes.](https://docs-resources.prod.twilio.com/229a5f7acca0fc0199d00f0917d3a8655383d581bc30f02b84f6be09af7d6bd3.png)

We're now one step further along the Task Reservation lifecycle:

*Task Created → eligible Worker becomes available → **Worker reserved** → Reservation accepted → Task assigned to Worker.*

Time to accept the Reservation.

[Next: Accept a Reservation with the REST API »](/docs/taskrouter/quickstart/ruby/reservations-accept-rest)
