Custom App Body is not a valid JSON

:bullseye: What is your goal?

Use my client credentials to connect to FedEx tracking API

:thinking: What is the problem & what have you tried?

I took a working customs app for Amazon SP-API, changed the syntax and URL to match FedEx requirement. Any call I make with the FedEx module replies “Body is not a valid JSON” (see uploaded screenshot).

  • the connection passed the validation
  • I tested the call with regular HTTP module after manually obtaining an access token and it works fine with the same payload

Base:

{
	// Default request configuration
	"baseUrl": "https://apis.fedex.com",
	"headers": {                                          
		"authorization": "Bearer {{connection.apiKey}}"
	},

	// Default response handling
	"response": {
		"error": {                                        
			"message": "[{{statusCode}}] {{body.error}}"
		}
	},

	"log": {
		"sanitize": [                                    
			"request.headers.authorization"          
		]
	}
}

Module Communication:

{
    "qs": {
        "{{...}}": "{{toCollection(parameters.qs, 'key', 'value')}}"
    },
    "url": "{{parameters.url}}",
    "body": "{{parameters.body}}",
    "type": "text",
    "method": "{{parameters.method}}",
    "headers": {
        "{{...}}": "{{toCollection(parameters.headers, 'key', 'value')}}"
    },
    "response": {
        "output": {
            "body": "{{body}}",
            "headers": "{{headers}}",
            "statusCode": "{{statusCode}}"
        }
    }
}

Module Mappable Parameters:

[
	{		
		"name": "url",                                                                        
		"type": "text",
		"label": "URL",
		"required": true
	},
	{
		"name": "method",
		"type": "select",
		"label": "Method",
		"default": "GET",
		"options": [
			{
				"label": "GET",
				"value": "GET"
			},
			{
				"label": "POST",
				"value": "POST"
			},
			{
				"label": "PUT",
				"value": "PUT"
			},
			{
				"label": "PATCH",
				"value": "PATCH"
			},
			{
				"label": "DELETE",
				"value": "DELETE"
			}
		],
		"required": true
	},
	{		
		"name": "headers",        
		"spec": [
			{
				"name": "key",
				"type": "text",
				"label": "Key"
			},
			{
				"name": "value",
				"type": "text",
				"label": "Value"
			}
		],
		"type": "array",
		"label": "Headers",
		"default": [			
			{
				"key": "Content-Type",
				"value": "application/json"
			}
		]
	},
	{
		"name": "qs",
		"spec": [
			{
				"name": "key",
				"type": "text",
				"label": "Key"
			},
			{
				"name": "value",
				"type": "text",
				"label": "Value"
			}
		],
		"type": "array",
		"label": "Query String"
	},
	{
		"name": "body",
		"type": "any",
		"label": "Body"
	}
]

:clipboard: Error messages or input/output bundles

I looked at the input bundle and everything looks normal. The character encoding seems to suggest something to do with gzip compression but the API doesn’t use gzip compression. Has anyone encountered anything similar?

:camera_with_flash: Screenshots (scenario flow, module settings, errors)

It seems like you are passing type: text in your request, thus not sending valid JSON. Change to json or omit it (type defaults to json)

Cheers,
Henk

1 Like

Thank you for the reply. Real issue was me being stupid. I set this in the Base component:

"authorization": "Bearer {{connection.apiKey}}"

instead of

"authorization": "Bearer {{connection.accessToken}}"

So the authorization failed because it wasn’t using the access token obtained from Connection but I couldn’t see it from the error message given.

Also, isn’t it better to use “type”: “text” for universal module instead of “json” since that requires a JSON string instead of freeform JSON?

2 Likes