https://slingdata.io logo
I am using sling to call an API that
# sling-help
s
I am using sling to call an API that returns a complex json document with two nested arrays. I would like to save this data to two different SQL tables. What is the best way to do this? Example document:
Copy code
{
  "success": true,
  "statusCode": 0,
  "errorMessage": "string",
  "additionalMessage": "string",
  "returnedRows": 0,
  "totalRowCount": 0,
  "emails": [
    {
      "reference_id": 0,
      "mail_id": "string",
      "received": "2026-02-09T10:33:52.058Z",
      "sent": "2026-02-09T10:33:52.058Z",
      "read": true,
      "priority": "Normal",
      "subject": "string",
      "attachmentCount": 0,
      "attributeCount": 0,
      "attributeList": [
        {
          "reference_id": 0,
          "mail_attribute_id": "string",
          "mail_id": "string",
          "key": "string",
          "value": "string",
          "keep": true,
          "comment": "string"
        }
      ]
    }
  ]
}
In this case I want to create one email table, and one email_attributes table.
f
hey @stegus64 I would use the queues for this. I encountered this before, and this was the solution to manipulate things a bit. you can push custom shaped objects to a queue and then receive in another endpoint which would use this as the source data, sort of like a "fake result" (avoiding a duplicate API call):
Copy code
yaml
queues:
    - email_attribute_records

endpoints:

  email:
    description: "Retrieve emails and push attribute records to queue"

    request:
      url: "{state.base_url}/emails"
      parameters:
        limit: "{state.limit}"

    response:
      records:
        jmespath: "emails[]"
        primary_key: ["reference_id"]

      processors:
        # For each email record, construct an object per attribute
        # and push it into the queue with the parent mail_id attached
        - expression: >
            jmespath(record, "attributeList[].{
              reference_id: reference_id,
              mail_attribute_id: mail_attribute_id,
              mail_id: mail_id,
              key: key,
              value: value,
              keep: keep,
              comment: comment
            }")
          output: "queue.email_attribute_records"

        - expression: object_delete(record, "attributeList")
          output: record

  # no extra API call when iteration into "response.records"
  email_attribute:
    description: "Emit email attributes from queue"

    iterate:
      over: "queue.email_attribute_records"
      into: "response.records"

    response:
      records:
        primary_key: ["reference_id"]
s
Thanks! Looks interesting. I will test this tomorrow
2 Views