Bird
0
0

You need to submit a composite operation that creates a new product, adds it to inventory, and then updates the supplier's record. Which JSON structure correctly models this sequence?

hard📝 Application Q8 of 15
Rest API - Advanced Patterns
You need to submit a composite operation that creates a new product, adds it to inventory, and then updates the supplier's record. Which JSON structure correctly models this sequence?
A{ "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "${1.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] }
B{ "batch": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "PUT", "path": "/inventory", "body": { "productId": "${1.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] }
C{ "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "1", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] }
D{ "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "${2.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] }
Step-by-Step Solution
Solution:
  1. Step 1: Understand operation dependencies

    The inventory addition depends on the product created in the first operation, so it references "${1.id}".
  2. Step 2: Verify JSON structure

    { "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "${1.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] } uses the correct "operations" key and proper method types (POST, POST, PATCH).
  3. Step 3: Check placeholders

    { "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "${1.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] } correctly references the first operation's result with "${1.id}".
  4. Final Answer:

    { "operations": [ { "method": "POST", "path": "/products", "body": { "name": "Notebook" } }, { "method": "POST", "path": "/inventory", "body": { "productId": "${1.id}", "quantity": 100 } }, { "method": "PATCH", "path": "/suppliers/55", "body": { "lastUpdated": "2024-06-01" } } ] } correctly models the composite operation.
  5. Quick Check:

    Check for "operations" array and correct placeholder usage [OK]
Quick Trick: Use "${1.id}" to reference prior operation results [OK]
Common Mistakes:
MISTAKES
  • Using incorrect keys like 'batch' instead of 'operations'
  • Hardcoding IDs instead of referencing previous results
  • Referencing wrong operation indices for placeholders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes