API Testing Examples

📚 Documentation Navigation


Prerequisites

  • API running locally or deployed
  • Valid API Key from reward_partner table
  • Valid JWT Bearer token

Using PowerShell

Basic GET Request

$headers = @{
    "apikey" = "your-api-key-here"
    "Authorization" = "Bearer your-jwt-token-here"
}

Invoke-RestMethod -Uri "https://reporting.api.myezrewards.com/odata/Partners" -Headers $headers -Method Get

Get Partners with Filtering

$headers = @{
    "apikey" = "your-api-key-here"
    "Authorization" = "Bearer your-jwt-token-here"
}

$uri = "https://reporting.api.myezrewards.com/odata/Partners?`$filter=Id eq 123"
Invoke-RestMethod -Uri $uri -Headers $headers -Method Get

Get Tracking Activities with Date Filter

$headers = @{
    "apikey" = "your-api-key-here"
    "Authorization" = "Bearer your-jwt-token-here"
}

$date = (Get-Date).AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ssZ")
$uri = "https://reporting.api.myezrewards.com/odata/TrackingActivities?`$filter=CreatedAt gt $date&`$orderby=CreatedAt desc&`$top=100"
Invoke-RestMethod -Uri $uri -Headers $headers -Method Get

Using curl (Windows)

Get All Partners

curl -X GET "https://reporting.api.myezrewards.com/odata/Partners" ^
  -H "apikey: your-api-key-here" ^
  -H "Authorization: Bearer your-jwt-token-here" ^
  -k

Get Partners with Select

curl -X GET "https://reporting.api.myezrewards.com/odata/Partners?$select=Id,Name" ^
  -H "apikey: your-api-key-here" ^
  -H "Authorization: Bearer your-jwt-token-here" ^
  -k

Get Rewards with Pagination

curl -X GET "https://reporting.api.myezrewards.com/odata/Rewards?$top=20&$skip=0&$orderby=Id" ^
  -H "apikey: your-api-key-here" ^
  -H "Authorization: Bearer your-jwt-token-here" ^
  -k

Get Count of Tracking Activities

curl -X GET "https://reporting.api.myezrewards.com/odata/TrackingActivities/$count" ^
  -H "apikey: your-api-key-here" ^
  -H "Authorization: Bearer your-jwt-token-here" ^
  -k

Using Postman

Setup Environment Variables

Create a Postman environment with:

  • baseUrl: https://reporting.api.myezrewards.com
  • apiKey: your-api-key-here
  • bearerToken: your-jwt-token-here

Request Configuration

Headers:

apikey: {{apiKey}}
Authorization: Bearer {{bearerToken}}

Example Requests

1. Get All Partners

GET {{baseUrl}}/odata/Partners

2. Get Partner by ID

GET {{baseUrl}}/odata/Partners(123)

3. Filter Partners by Name

GET {{baseUrl}}/odata/Partners?$filter=contains(Name,'fitness')

4. Get Rewards with Specific Fields

GET {{baseUrl}}/odata/Rewards?$select=Id,Title,DiscountString,IsActive

5. Get Tracking Activities for User

GET {{baseUrl}}/odata/TrackingActivities?$filter=UserId eq 456&$orderby=CreatedAt desc

6. Get Impressions with Reward and User Details

GET {{baseUrl}}/odata/TrackingImpressions?$expand=Reward,User&$top=50

7. Complex Query - Active Rewards by Country

GET {{baseUrl}}/odata/Rewards?$filter=IsActive eq true and CountryId eq 1&$orderby=Title&$select=Id,Title,DiscountString

Using C# HttpClient

using System.Net.Http.Headers;
using System.Text.Json;

var client = new HttpClient();
client.BaseAddress = new Uri("https://reporting.api.myezrewards.com");
client.DefaultRequestHeaders.Add("apikey", "your-api-key-here");
client.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", "your-jwt-token-here");

// Get partners
var response = await client.GetAsync("/odata/Partners?$top=10");
var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<dynamic>(json);

Console.WriteLine(json);

Common Query Patterns

1. Pagination

/odata/Partners?$top=20&$skip=40

Gets items 41-60

2. Search by Text (contains)

/odata/Partners?$filter=contains(Name,'fitness')

3. Date Range Filter

/odata/TrackingLogins?$filter=LoginTime ge 2024-01-01T00:00:00Z and LoginTime le 2024-01-31T23:59:59Z

4. Multiple Filters with AND

/odata/TrackingActivities?$filter=Type eq 'click' and UserId eq 456

5. Multiple Filters with OR

/odata/TrackingActivities?$filter=Type eq 'click' or Type eq 'view'

6. Sorting Multiple Fields

/odata/Rewards?$orderby=CountryId asc,Title asc

7. Get Count with Filter

/odata/TrackingActivities/$count?$filter=Type eq 'click'

8. Select with Expand

/odata/TrackingImpressions?$select=Id,CreatedAt&$expand=Reward($select=Id,Title)

Testing Scenarios

Scenario 1: Daily Activity Report

Get all tracking activities for the last 24 hours:

GET /odata/TrackingActivities?$filter=CreatedAt ge {{yesterday}}&$orderby=CreatedAt desc

Scenario 2: Reward Performance

Get all impressions for a specific reward with counts:

GET /odata/TrackingImpressions?$filter=RewardId eq 123&$count=true

Scenario 3: User Activity History

Get all activities for a specific user:

GET /odata/TrackingActivities?$filter=UserId eq 456&$orderby=CreatedAt desc&$top=100

Scenario 4: Active Rewards by Country

Get all active rewards for a specific country:

GET /odata/Rewards?$filter=IsActive eq true and CountryId eq 1&$select=Id,Title,DiscountString

Scenario 5: Login Analytics

Get login count by date range:

GET /odata/TrackingLogins/$count?$filter=LoginTime ge 2024-01-01T00:00:00Z and LoginTime le 2024-01-31T23:59:59Z

Response Format

Successful Response

{
  "@odata.context": "https://reporting.api.myezrewards.com/odata/$metadata#Partners",
  "@odata.count": 150,
  "value": [
    {
      "Id": 1,
      "Name": "Example Partner",
      "Description": "Example partner description",
      "WebsiteUrl": "https://example-partner.com",
      "IsActive": true,
      ...
    }
  ]
}

Error Response

{
  "error": {
    "code": "401",
    "message": "Invalid API key provided"
  }
}

Performance Testing

Load Test with PowerShell

$headers = @{
    "apikey" = "your-api-key-here"
    "Authorization" = "Bearer your-jwt-token-here"
}

1..100 | ForEach-Object -Parallel {
    Invoke-RestMethod -Uri "https://reporting.api.myezrewards.com/odata/Partners?`$top=10" -Headers $using:headers
} -ThrottleLimit 10

Troubleshooting

401 Unauthorized

  • Check API key is valid and exists in database
  • Verify Bearer token is properly formatted
  • Ensure both headers are present

400 Bad Request

  • Check OData query syntax
  • Verify field names match entity properties
  • Check date format (ISO 8601)

500 Internal Server Error

  • Check database connection
  • Verify entity relationships
  • Review application logs

Additional Resources