Skip to content

JSON Array in RequestBody not supported?

0

I am attempting to use the HTTP Third party api connection task for my step function. The endpoint I am trying to connect to requires the request body to be sent as an array of JSON elements. It is using GraphQL with JSON as the data language. Example:

[{
    "resourceType": "TimesheetSearch",
    "resourceParams": {
        "filter": {
            "matchIds": ["1"],
            "endDate": { "from" : "2024-10-12T00:00:00", "to":"2024-10-12T00:00:00" }
        }
    }
}]

However whenever I set such a RequestBody, I get an error of "Cannot merge connection body authorization parameters with request body." Reading the docs it appears that the Eventbridge Connection and the HTTP task get merged together when sending. My guess is that the merge code can't handle merging a JSON array with the Eventbridge Connection body.
Is there any way I can send my data as a JSON Array without hitting this error?

1 Answer
1
Accepted Answer

You're correct in your understanding that AWS Step Functions merges the request body from the EventBridge connection with the HTTP Task definition. However, the issue you're encountering with sending a JSON array in the RequestBody is indeed a limitation of the current implementation.

The merging process is designed to work with JSON objects, not arrays. When you try to send a JSON array as the RequestBody, the system cannot properly merge it with the connection body parameters, resulting in the error you're seeing.

Unfortunately, there isn't a direct way to send your data as a JSON array using the HTTP Task in Step Functions without encountering this error. However, there are a few potential workarounds you could consider:

  1. Wrap your array in an object: Instead of sending the array directly, you could wrap it in a JSON object with a single key. For example:

    {
      "data": [{
        "resourceType": "TimesheetSearch",
        "resourceParams": {
          "filter": {
            "matchIds": ["1"],
            "endDate": { "from" : "2024-10-12T00:00:00", "to":"2024-10-12T00:00:00" }
          }
        }
      }]
    }

    This approach allows the merging process to work as expected, and you can modify your API endpoint to expect this structure.

  2. Use a Lambda function: If modifying the API isn't possible, you could create a Lambda function that acts as a proxy. The Lambda function would receive the data from Step Functions, construct the array, and make the API call. You would then use a Task state in your Step Functions workflow to invoke this Lambda function instead of directly calling the HTTP endpoint.

  3. Stringify the array: You could try converting the array to a JSON string and sending it as a string value in the RequestBody. However, this approach may require changes on the API side to parse the string back into an array.

  4. Contact AWS Support: If none of these workarounds are suitable for your use case, you may want to reach out to AWS Support to inquire about potential solutions or to request enhancement of the HTTP Task functionality to support JSON arrays in the RequestBody.

Remember that when working with the HTTP Task, it's important to ensure that the Content-Type header is set correctly (usually to "application/json") to ensure proper handling of the request body by the target API.

These limitations highlight the importance of understanding how Step Functions handles data merging and the current constraints of the HTTP Task feature when integrating with third-party APIs that expect specific data structures.

Sources
Call third-party APIs in Step Functions workflows - AWS Step Functions
RequestBody - Amazon Bedrock
Community | AWS StepFunctions HTTP Endpoint demystified

answered 2 years ago
EXPERT
reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.