# API Documentation

Everything you need to interact with AccessGrid.

## Supported Languages

- Terminal
- JavaScript
- Ruby
- GO
- Python
- C#
- Java
- php
- Elixir

## List Card Template Pairs

Enterprise only  
Only available for enterprise customers - allows you to retrieve a paginated list of Card Template Pairs. Card Template Pairs link iOS and Android card templates together for unified pass issuance.

### Parameters

#### page
- **Type:** nullable integer
- **Default Value:** 1  
  Page number for pagination.

#### per_page
- **Type:** nullable integer
- **Default Value:** 50, Max: 100  
  Number of results per page.

### Request Example

```bash
PAYLOAD="{}"
# Sign the payload
PAYLOAD_B64=$(printf '%s' "$PAYLOAD" | openssl base64 -A)
SIG=$(printf '%s' "$PAYLOAD_B64" | openssl dgst -sha256 -hmac "$SECRET_KEY" -hex | awk '{print $NF}')

curl -v -G \
-H "X-ACCT-ID: $ACCOUNT_ID" \
-H "X-PAYLOAD-SIG: $SIG" \
--data-urlencode "page=1" \
--data-urlencode "per_page=50" \
--data-urlencode "sig_payload=$PAYLOAD" \
"https://api.accessgrid.com/v1/console/card-template-pairs"
```

### Code Samples

#### Ruby
```ruby
require 'accessgrid'

acct_id = ENV['ACCOUNT_ID']
secret_key = ENV['SECRET_KEY']

client = AccessGrid.new(acct_id, secret_key)

response = client.console.list_pass_template_pairs(
page: 1,
per_page: 50
)

response['pass_template_pairs'].each do |pair|
puts "Pair: #{pair.name} (ID: #{pair.id})"
puts "  Android: #{pair.android_template&.name}"
puts "  iOS: #{pair.ios_template&.name}"
end

puts "Total: #{response['pagination']['total_count']} pairs"
```

#### JavaScript
```javascript
import AccessGrid from 'accessgrid';

const accountId = process.env.ACCOUNT_ID;
const secretKey = process.env.SECRET_KEY;

const client = new AccessGrid(accountId, secretKey);

const listPairs = async () => {
try {
    const result = await client.console.listPassTemplatePairs({
      page: 1,
      perPage: 50
    });

result.passTemplatePairs.forEach(pair => {
      console.log(`Pair: ${pair.name} (ID: ${pair.id})`);
      console.log(`  Android: ${pair.androidTemplate?.name}`);
      console.log(`  iOS: ${pair.iosTemplate?.name}`);
    });

console.log(`Total: ${result.pagination.total_count} pairs`);
} catch (error) {
    console.error('Error listing pairs:', error);
}
};

listPairs();
```

### Response Example
```json
{
"card_template_pairs": [
    {
      "id": "pair_9f3a12bc",
      "ex_id": "pair_9f3a12bc",
      "name": "Corporate Access Badge",
      "created_at": "2025-12-01T09:15:30Z",
      "android_template": {
        "id": "tpl_android123",
        "ex_id": "tpl_android123",
        "name": "Android Corporate Badge",
        "platform": "android"
      },
      "ios_template": {
        "id": "tpl_ios456",
        "ex_id": "tpl_ios456",
        "name": "iOS Corporate Badge",
        "platform": "apple"
      }
    },
    {
      "id": "pair_b81d77ef",
      "ex_id": "pair_b81d77ef",
      "name": "Student ID",
      "created_at": "2025-11-15T14:22:11Z",
      "android_template": {
        "id": "tpl_android789",
        "ex_id": "tpl_android789",
        "name": "Android Student ID",
        "platform": "android"
      },
      "ios_template": null
    }
],
"pagination": {
    "current_page": 1,
    "per_page": 50,
    "total_pages": 1,
    "total_count": 2
}
}
```

## Create Card Template Pair

Enterprise only  
Only available for enterprise customers - allows you to create a Card Template Pair by linking an Apple (iOS) and Google (Android) card template together. Both templates must be published. Supported combinations are either Apple SEOS paired with Google SEOS, or Apple DESFire paired with Google SmartTap.

### Parameters

#### name
- **Type:** string  
A name for the card template pair.

#### apple_card_template_id
- **Type:** string  
The ex_id of the Apple (iOS) card template.

#### google_card_template_id
- **Type:** string  
The ex_id of the Google (Android) card template.

### Request Example

```bash
PAYLOAD=$(cat <<EOF
{
"name": "Employee Badge Pair",
"apple_card_template_id": "0xapplet3mp14t3",
"google_card_template_id": "0xgoogl3t3mp14t3"
}
EOF)

# Sign the payload
PAYLOAD_B64=$(printf '%s' "$PAYLOAD" | openssl base64 -A)
SIG=$(printf '%s' "$PAYLOAD_B64" | openssl dgst -sha256 -hmac "$SECRET_KEY" -hex | awk '{print $NF}')

curl -v \
-X POST \
-H "X-ACCT-ID: $ACCOUNT_ID" \
-H "X-PAYLOAD-SIG: $SIG" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"https://api.accessgrid.com/v1/console/card-template-pairs"
```

### Response Example
```json
{
"id": "pair_9f3a12bc",
"ex_id": "pair_9f3a12bc",
"name": "Corporate Access Badge",
"created_at": "2025-12-01T09:15:30Z",
"android_template": {
    "id": "tpl_android123",
    "ex_id": "tpl_android123",
    "name": "Android Corporate Badge",
    "platform": "android"
},
"ios_template": {
    "id": "tpl_ios456",
    "ex_id": "tpl_ios456",
    "name": "iOS Corporate Badge",
    "platform": "apple"
}
}
```
