

The Amplify API category provides an interface for retrieving and persisting your model data. The API category comes with default built-in support for AWS AppSync. The Amplify CLI allows you to define your API and provision a GraphQL service with CRUD operations and real-time functionality.

## Goal

To setup and configure your application with Amplify API to save items in the backend.

## Prerequisites

import ios1 from "/src/fragments/lib/graphqlapi/ios/getting-started/10_preReq.mdx";

<Fragments fragments={{ios: ios1}} />

import android2 from "/src/fragments/lib/graphqlapi/android/getting-started/10_preReq.mdx";

<Fragments fragments={{android: android2}} />

import flutter3 from "/src/fragments/lib/graphqlapi/flutter/getting-started/10_preReq.mdx";

<Fragments fragments={{flutter: flutter3}} />

## Configure API

To start provisioning API resources in the backend, go to your project directory and **execute the command**:

```bash
amplify add api
```

Enter the following when prompted:
```console
? Please select from one of the below mentioned services:
    `GraphQL`
# The part below will show you some options you can change, if you wish to change any of them you can navigate with
# your arrow keys and update any field, otherwise you can click on `Continue` to move on
? Here is the GraphQL API that we will create. Select a setting to edit or continue
    `Continue`
? Choose a schema template:
    `Single object with fields (e.g., “Todo” with ID, name, description)`
? Do you want to edit the schema now?
    `No`
```

<Callout warning>

**Troubleshooting:** The AWS API plugins do not support conflict detection. If AppSync returns errors about missing `_version` and `_lastChangedAt` fields, or unhandled conflicts, disable **conflict detection**. Run `amplify update api`, and choose **Disable conflict detection**.  If you started with the Getting Started guide, which introduces DataStore, this step is required.

</Callout>

The guided schema creation will output `amplify/backend/api/{api_name}/schema.graphql` containing the following:
```graphql
type Todo @model {
  id: ID!
  name: String!
  description: String
}
```

To push your changes to the cloud, **execute the command**:

```bash
amplify push
```

import ios4 from "/src/fragments/lib/graphqlapi/ios/getting-started/12_amplifyConfig.mdx";

<Fragments fragments={{ios: ios4}} />

import android5 from "/src/fragments/lib/graphqlapi/android/getting-started/12_amplifyConfig.mdx";

<Fragments fragments={{android: android5}} />

import flutter6 from "/src/fragments/lib/graphqlapi/flutter/getting-started/12_amplifyConfig.mdx";

<Fragments fragments={{flutter: flutter6}} />

import ios7 from "/src/fragments/lib/graphqlapi/ios/getting-started/40_codegen.mdx";

<Fragments fragments={{ios: ios7}} />

import android8 from "/src/fragments/lib/graphqlapi/android/getting-started/40_codegen.mdx";

<Fragments fragments={{android: android8}} />

import flutter7 from "/src/fragments/lib/graphqlapi/flutter/getting-started/40_codegen.mdx";

<Fragments fragments={{flutter: flutter7}} />

## Install Amplify Libraries

import ios9 from "/src/fragments/lib/graphqlapi/ios/getting-started/20_installLib.mdx";

<Fragments fragments={{ios: ios9}} />

import android10 from "/src/fragments/lib/graphqlapi/android/getting-started/20_installLib.mdx";

<Fragments fragments={{android: android10}} />

import flutter11 from "/src/fragments/lib/graphqlapi/flutter/getting-started/20_installLib.mdx";

<Fragments fragments={{flutter: flutter11}} />

## Initialize Amplify API

import ios12 from "/src/fragments/lib/graphqlapi/ios/getting-started/30_initapi.mdx";

<Fragments fragments={{ios: ios12}} />

import android13 from "/src/fragments/lib/graphqlapi/android/getting-started/30_initapi.mdx";

<Fragments fragments={{android: android13}} />

import flutter14 from "/src/fragments/lib/graphqlapi/flutter/getting-started/30_initapi.mdx";

<Fragments fragments={{flutter: flutter14}} />

## Create a Todo

import ios15 from "/src/fragments/lib/graphqlapi/ios/getting-started/50_createtodo.mdx";

<Fragments fragments={{ios: ios15}} />

import android16 from "/src/fragments/lib/graphqlapi/android/getting-started/50_createtodo.mdx";

<Fragments fragments={{android: android16}} />

import flutter17 from "/src/fragments/lib/graphqlapi/flutter/getting-started/50_createtodo.mdx";

<Fragments fragments={{flutter: flutter17}} />

Upon successfully executing this code, you should see an instance of `todo` persisted in your dynamoDB table.

To navigate to your backend, run `amplify console api` and choose `GraphQL`. This will open the AppSync console to your GraphQL service. Select `Data Sources` and select the Resource link in your `TodoTable` to bring you to the DynamoDB Console. Select the `items` tab to see the `Todo` object that has been persisted in your database.

## Next steps

Congratulations! You've created a `Todo` object in your database. Check out the following links to see other Amplify API use cases:

* [Fetch data](/lib/graphqlapi/query-data)
* [Update data](/lib/graphqlapi/mutate-data)
* [Subscribe to data](/lib/graphqlapi/subscribe-data)
* [Concepts](/lib/graphqlapi/concepts)
* [Configure authorization modes](/lib/graphqlapi/authz)

<!-- TODO: * [Authorizing API calls with Cognito User Pool] -->
