# Primary Workflow Tutorial
source: https://developer.mastercard.com/agent-suite-for-merchants/documentation/tutorials-and-guides/pets-tutorial/index.md

👉 Replace the generic resource names, endpoints, payloads, and example field values in this tutorial with the real primary-resource workflow for your service. Update the authentication example if your service does not use OAuth 1.0a.

## Overview {#overview}

Use this tutorial to test the primary resource endpoints in the {Your Service Name} service.

The main service flow usually moves from primary and secondary resources into downstream transactions. Administrative records typically follow a separate operational flow.

## Prerequisites {#prerequisites}

* A project created for your service on Mastercard Developers.
* Sandbox credentials and downloaded keys stored safely.
* A configured API client such as Postman or Insomnia.
* Authentication configured before you send requests.

Example client configuration:

```json
{
  "scheme": "https",
  "base_path": "",
  "host": "sandbox.api.mastercard.com",
  "mastercard": {
    "consumerKey": "{your consumerKey}",
    "keyAlias": "{your keyAlias}",
    "keystoreP12Path": "/path/to/your/file",
    "keystorePassword": "{your keystorePassword}"
  }
}
```

<br />

## What You Will Learn {#what-you-will-learn}

* How to create a primary resource by posting one of the supported resource variants
* How to retrieve, update, filter, and delete primary resources

## Create a Primary Resource {#create-a-primary-resource}

1. To create a primary resource, first `POST` one of the supported resource variants.
2. To create the resource variant, submit the required fields:

```yaml
POST https://sandbox.api.mastercard.com/{your-service}/resource-b
```

```json
{
  "name": "Example Resource",
  "type": "SECONDARY",
  "category": "STANDARD",
  "status": {
    "value": "ACTIVE"
  }
}
```

3. When the request succeeds, the API returns a unique identifier. Copy and store this value because you will reuse it in the next steps.
4. Use the identifier as a path parameter to retrieve the created record:

```yaml
GET https://sandbox.api.mastercard.com/{your-service}/resource-b/{resource_id}
```

5. You can also use this identifier when updating the full record with `PUT`. Each time you update the record, increment the `If-Match` header by 1.

```yaml
PUT https://sandbox.api.mastercard.com/{your-service}/resource-b/{resource_id}
```

`If-Match (header)`: `0`

```json
{
  "name": "Updated Resource",
  "type": "SECONDARY",
  "category": "STANDARD",
  "status": {
    "value": "ACTIVE"
  }
}
```

## Update a Primary Resource {#update-a-primary-resource}

1. Once the resource exists, you can update a status-only field using the identifier:

```yaml
PUT https://sandbox.api.mastercard.com/{your-service}/resources/{resource_id}/status
```

`If-Match (header)`: `0`

```json
{
  "value": "INACTIVE"
}
```

## Query and Filter Primary Resources {#query-and-filter-primary-resources}

1. You can query and filter a list of resources by status. Set `status`, `limit`, `offset`, and `sort` as query parameters. `status`: `ACTIVE` `limit`: `25` `offset`: `0` `sort`: `+`

```yaml
GET https://sandbox.api.mastercard.com/{your-service}/resources?status=ACTIVE&limit=25&offset=0&sort=%2B
```

## Delete a Primary Resource {#delete-a-primary-resource}

1. Finally, you can remove a resource by using its identifier in a `DELETE` request.

```yaml
DELETE https://sandbox.api.mastercard.com/{your-service}/resources/{resource_id}
```

