Jump to a Section
  • Introduction

    This walk-through demonstrates how to manipulate the JSON string returned from the Amazon Petstore API call in your previous Flow.

    [
      {
        "id": 4,
        "type": "Dog",
        "price": 999.99
      },
      {
        "id": 5,
        "type": "Dog",
        "price": 249.99
      },
      {
        "id": 6,
        "type": "Dog",
        "price": 49.97
      }
    ]
  • Parse the results

    1. In Admin Console, go to Workflow > Workflows console.
    2. In Workflows console, open the Flow that you created for Amazon Petstore.
    3. Scroll to the end of the Run When TRUE cards, and then click Add Another > Function > Text > Compose.
    4. In the Compose card, enter statusCode is and then drag and drop the Outputs statusCode field.
    5. Click Add Another > Function > JSON > Parse.
    6. Drag and drop the Outputs body field to the string field of the Parse card.
    7. In the Parse card, change the name of the output field to parsedString.
      Note: type is an object.
    8. Click Add Another > Function > Object > Get Multiple.
    9. Drag and drop the parsedString field from the Parse card to the object field of the Get Multiple card.
    10. In the Get Multiple card, create three output fields: 0.id, 0.type, and 0.price.
    11. Click Add Another > Function > JSON > Parse.
    12. Drag and drop the input string field (of the JSON Parse card from step 6) to the string field of this Parse card.
      Note: You can drag and drop inputs from one card to another. Workflows ensures that those inputs will map back to the same source.
    13. In this Parse card, changed the name of the output field to parsedListOfObjects.
    14. Change the type of output field to List of Objects.
      Note: If you don’t change the field type, then you won’t be able to map it to the input field of the List Pluck card in the next step. Compare to step 7.
    15. Click Add Another > Function > List > Pluck.
    16. Drag and drop the parsedListOfObjects field from the Parse card to the List field of the Pluck card.
      Note: The List Pluck card needs a list of objects. If you map to the output of the JSON Parse card from step 7, an error will occur. This is an update to the steps taken in the video.
    17. In the key field of the Pluck card, enter price.
    18. Click Add Another > Function > List > Flatten.
    19. Drag and drop the parsedString field from the Parse card to the lists field of the Flatten card.
    20. In the output list fields of the Flatten card, enter id, type, and price.
    21. Save your Flow.
  • Add a child Flow

    1. In Workflows console, click New Flow.
    2. Click Add Event, and then select Child Flow.
    3. In the Child Flow card, add the following Inputs to this Flow: id, type, and price.
    4. Click Add Another > Function > Text > Compose.
    5. In the Compose card, enter id, and then drag and drop the id field from the Child Flow card. Drop down a line, and then repeat for type and price.
    6. Save and name your child Flow.
    7. Toggle the Flow is OFF switch to ON.
  • Connect the Flows

    1. Return to the parent Flow.
    2. Click Add Another > Function > List > For Each.
    3. Drag and drop the list field from the Flatten card to the list field in the For Each card.
    4. In the For Each card, click Choose Flow, and then select the child Flow that you just created.
    5. In the With the following values drop-down menus, choose id, type, and price.
    6. In the concurrency field, enter 3.
    7. Save the Flow.
  • Test the Flow

    1. In Postman, copy the URL for the Petstore API.
    2. In Workflows console, return to your parent Flow, and then click the Test icon.
    3. Paste the URL into the url field.
    4. Enter the following values:
    5. Click Test.
    6. Verify that the Compose card has a status code output.
    7. Verify the JSON Parse card created an object as its output.
    8. Verify that the Get Multiple card has correct values in the id, type, and price fields.
    9. Verify that the Pluck card has the values that correspond to the prices.
    10. Verify that the list was flattened and called three times.
    11. Check your child flow and verify that the Flow History shows three Success listings.
  • Video Walkthrough

    Note: After the video was produced, an update introduced a check on type in the List Pluck card. The video does not include steps 11 through 14 or 16 in the Parse the results section.