IOTA - SDK and Empty Body Errors

You may encounter the following error log when attempting to submit a request to IOTA via Tatum using the IOTA SDK.

IOTA SDK Error

{
  "id": "###",
  "method": "POST",
  "url": "/v3/blockchain/node/iota-testnet/api/core/v2/blocks",
  "agent": "iota-sdk/1.1.4",
  "ip": "###",
  "timestamp": ###,
  "request": {
    "body": {}
  },
  "response": {
    "error": {
      "code": "400",
      "message": "invalid parameter, error: failed to attach block: protocolVersion invalid: 0: invalid block: code=400, message=invalid parameter"
    }
  },
  "code": 400,
  "apiKey": "###",
  "requestRayId": "###",
  "userId": "###"
}

Key Error Messages:

  • "message": "invalid parameter, error: failed to attach block: protocolVersion invalid"
  • "code": 400, message=invalid parameter"

Cause

The primary issue here is with the Content-Type header set by the IOTA SDK, which is using application/vnd.iota.serializer-v1 instead of the standard application/json.

This non-standard Content-Type prevents the Tatum API from parsing the request body properly, resulting in a 400 Bad Request error, as the request body appears empty in Tatum’s logs.

Troubleshooting Steps

  1. Verify the SDK Request Format:
    Check that the IOTA SDK is indeed sending the request body in the expected format by examining the raw request data. You can use a network inspector tool or log the request details from your SDK to confirm the format.
  2. Override the Content-Type Header:
    If possible, configure the IOTA SDK to use application/json as the Content-Type. This adjustment may resolve the issue if the SDK allows header customization.
  3. Convert Request to JSON Format:
    If overriding the header isn’t an option, consider constructing the request manually in a way that adheres to Tatum’s requirements. Using a standard HTTP client (like Axios or Fetch in JavaScript, or Requests in Python) might allow for greater control over the request structure, including setting Content-Type to application/json.