Rest Debugger Error?

This Create Customer request works on Postman, but errors when I try to port it to Embarcadero’s REST Debugger.

Headers
image
Body

{ “idempotency_key”: “76767660”,
“given_name”: “Amelia”,
“family_name”: “Earhart”,
“company_name”: “Square”,
“nickname”: “Yeo”,
“email_address”: “Amelia.Earhart@example.com”,
“address”:
{
“address_line_1”: “500 Electric Ave”,
“address_line_2”: “Suite 600”,
“locality”: “New York”,
“administrative_district_level_1”: “NY”,
“postal_code”: “10003”,
“country”: “US”
},
“phone_number”: “1-212-555-4240”,
“reference_id”: “321123”,
“note”: “a customer”,
“birthday”: “2008-03-05T00:00:00-00:00”
}

Returns the error:

{ “errors”: [
{ “code”: “BAD_REQUEST”,
“detail”: “Expected “{” (line 1, character 1)”,
“category”: “INVALID_REQUEST_ERROR”
} ] }

Can you suggest what might cause this error?

Sounds like the request is being malformed. Do you have an option to print the request to see what is malformed?

Not a print, but this is the values it stores. (sorry this is difficult to read)

object RESTClient1: TRESTClient
Authenticator = OAuth2Authenticator1
BaseURL = ‘https://connect.squareup.com/v2/customers
Params = <>
end
object RESTRequest1: TRESTRequest
AssignedValues = [rvConnectTimeout, rvReadTimeout]
Client = RESTClient1
Method = rmPOST
Params = <
item
Kind = pkHTTPHEADER
Name = ‘Authorization’
Options = [poDoNotEncode]
Value =
‘Bearer xxx’ +
‘IdtHnOy’
end
item
Kind = pkHTTPHEADER
Name = ‘Host’
Options = [poDoNotEncode]
Value = ‘connect.squareup.com
end
item
Kind = pkHTTPHEADER
Name = ‘state’
Options = [poDoNotEncode]
Value = ‘82201dd8d83d23cc8a48caf52’
end
item
Kind = pkHTTPHEADER
Name = ‘Content-Type’
Options = [poDoNotEncode]
Value = ‘application/json’
end
item
Kind = pkREQUESTBODY
Name = ‘bodyCAF2DBE50214484F822FC964F80D323D’
Value =
‘{“idempotency_key”: “76767660”, “given_name”: “Amelia”,"family_n’ +
‘ame": “Earhart”, “company_name”: “Square”, “nickname”: “Yeo”,"em’ +
‘ail_address": “Amelia.Earhart@example.com”,“address”: {"address_’ +
‘line_1": “500 Electric Ave”, “address_line_2”: “Suite 600”, "loc’ +
‘ality": “New York”, “administrative_district_level_1”: “NY”, "po’ +
‘stal_code": “10003”, “country”: “US” }, “phone_number”: "1-212-5’ +
‘55-4240", “reference_id”: “321123”, “note”: “a customer”,"birthd’ +
‘ay": “2008-03-05T00:00:00-00:00”}’
ContentType = ctAPPLICATION_JSON
end>
Response = RESTResponse1
end
object RESTResponse1: TRESTResponse
end
object OAuth2Authenticator1: TOAuth2Authenticator
AccessToken = ‘xxx’
end

I seem to have encountered a bug or something.

Postman includes the Content-Length, if I remove this parameter this request fails. The response incorrectly states:

{“errors”: [{“code”: “BAD_REQUEST”,“detail”: “At least one of given_name, family_name, company_name, email_address, or phone_number is required for a customer.”,“category”: “INVALID_REQUEST_ERROR”}]}

If the length is required then the returned response should show that specific error. The API does not mention Content-Length.

:wave: Typically when sending data, you specify in the Content-Length field the size of the data being sent (especially since sometimes it can be chunked). So completely omitting it on something other than a GET or DELETE isn’t ideal. We recommend following the common HTTP spec and specify the Content-Length in the request. :slightly_smiling_face:

Is Content-Length headers + body length?

Is Content-Length headers + body length?

The Content-Length indicates to the server the size of the request body that is added to the request. The server uses the value to parse the request body accurately.