APIs & Integrations

aga1
Member

Single Send API response

I’m in the process of testing the Single Send API and trying to build some logic in my application based on the sendResult field sent back to me in the response. I’m able to send an email successfully and I do get the “SENT” result back.

But when I change the emailId field passed in the JSON to one that is not set up for Singe Send (doing this purposely to test different results), my call to get the response is failing with a “System.Net.WebException: The remote server returned an error: (400) Bad Request.”

I was expecting to successfully get back a response of “MISSING_CONTENT” as described in the documentation. I’m not sure if this is the intended behavior or if I’m doing something wrong here.

Thanks,
Aga

0 Upvotes
8 Replies 8
aga1
Member

Single Send API response

I tried testing my call through an application called Postman and I can see that HubSpot is returning the JSON response I was expecting when a web exception is thrown.

I am making my call through Dynamics AX in X++. Not sure if you have any customers doing the same thing but once the request.GetResponse() throws the exception (it throws a CLR exception), there’s no way for me to get the accompanying response body. Or at least I have not been able to find a solution after searching different Dynamics AX forums for days.

But the Postman app did help me verify that a response was sent along with the web exception.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Single Send API response

@aga I don’t have any experience in X++ to lend out. Can you use a different library to make the request?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Single Send API response

@aga The email id it self wouldn’t be considered Content for Us. Also you did supply an ID just an incorrect one. This is working how it is designed and it sounds like you are testing correctly!

0 Upvotes
aga1
Member

Single Send API response

I’m still a little confused. In what scenario then would I receive the response described below from the documentation page?

“MISSING_CONTENT — The emailId is invalid, or the emailId is an email that is not set up for Single Send.”

I’ve also tried taking out the @ symbol from the recipient address and I’m getting the same Bad Request error instead of the response below:

“INVALID_TO_ADDRESS — The recipient address is invalid.”

This is the JSON I am sending which gives me a “SENT” response. I’m changing just the “emailId” field for testing purposes and sending the rest of the JSON as is.

{“emailId”: 4999114648 , “message”: {“to”: "gunia1014@gmail.com"}, “customProperties”: [ { “name”: “order_number”, “value”: “SO01112634”}, { “name”: “po_number”, “value”: “Hillary”}, { “name”: “ship_date”, “value”: “03/29/2017”}, { “name”: “payment_method”, “value”: “Credit card”}, { “name”: “payment_type”, “value”: “Visa”}, { “name”: “shipping_method”, “value”: “Fedex Ground”}, { “name”: “order_total”, “value”: “26.45”}, { “name”: “shipping_amount”, “value”: “9.90”}, { “name”: “sales_tax”, “value”: “1.30”}, { “name”: “billing_name”, “value”: “Justin Dunham”}, { “name”: “billing_company”, “value”: “Jenks Martial Arts Academy, LLC”}, { “name”: “billing_street”, “value”: “708 W. Main Street”}, { “name”: “billing_city”, “value”: “Jenks”}, { “name”: “billing_state”, “value”: “OK”}, { “name”: “billing_zip”, “value”: “74037”}, { “name”: “shipping_name”, “value”: “Justin Dunham”}, { “name”: “shipping_company”, “value”: “Jenks Martial Arts Academy, LLC”}, { “name”: “shipping_street”, “value”: “9521 Riverside Parkway , B101”}, { “name”: “shipping_city”, “value”: “Tulsa”}, { “name”: “shipping_state”, “value”: “OK”}, { “name”: “shipping_zip”, “value”: “74137”}, { “name”: “shipping_phone”, “value”: “9182820344”} ]}

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Single Send API response

@aga Can you post the full return as well, also the call?(please x out your hapikey/token) I’d like to be able to see it. There does seem to be a discrepancy in our documentation and what you are experiencing .

0 Upvotes
aga1
Member

Single Send API response

Full return:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
— End of inner exception stack trace —
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ClrBridgeImpl.InvokeClrInstanceMethod(ClrBridgeImpl* , ObjectWrapper* objectWrapper, Char* pszMethodName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)

Call:
clrObj = System.Net.WebRequest::Create(url);
request = clrObj;
request.set_Method(“POST”);
request.set_ContentType(“application/json”);

byteArray = utf8.GetBytes(strJSON);
request.set_ContentLength(byteArray.get_Length());

dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.get_Length());
dataStream.Close();

response = request.GetResponse();

url = https://api.hubapi.com/email/public/v1/singleEmail/send?hapikey=xxxx
strJON =
{“emailId”: 4974715505 , “message”: {“to”: "gunia1014@gmail.com"}, “customProperties”: [ { “name”: “order_number”, “value”: “SO01112634”}, { “name”: “po_number”, “value”: “Hillary”}, { “name”: “ship_date”, “value”: “03/29/2017”}, { “name”: “payment_method”, “value”: “Credit card”}, { “name”: “payment_type”, “value”: “Visa”}, { “name”: “shipping_method”, “value”: “Fedex Ground”}, { “name”: “order_total”, “value”: “26.45”}, { “name”: “shipping_amount”, “value”: “9.90”}, { “name”: “sales_tax”, “value”: “1.30”}, { “name”: “billing_name”, “value”: “Justin Dunham”}, { “name”: “billing_company”, “value”: “Jenks Martial Arts Academy, LLC”}, { “name”: “billing_street”, “value”: “708 W. Main Street”}, { “name”: “billing_city”, “value”: “Jenks”}, { “name”: “billing_state”, “value”: “OK”}, { “name”: “billing_zip”, “value”: “74037”}, { “name”: “shipping_name”, “value”: “Justin Dunham”}, { “name”: “shipping_company”, “value”: “Jenks Martial Arts Academy, LLC”}, { “name”: “shipping_street”, “value”: “9521 Riverside Parkway , B101”}, { “name”: “shipping_city”, “value”: “Tulsa”}, { “name”: “shipping_state”, “value”: “OK”}, { “name”: “shipping_zip”, “value”: “74137”}, { “name”: “shipping_phone”, “value”: “9182820344”}]}

This strJSON value sends successfully with a correct emailId. The one supplied in the example is valid, but not set up for Single Send.

0 Upvotes
aga1
Member

Single Send API response

The failure is happening at the request.GetResponse() step. The ‘response’ variable is never set.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Single Send API response

@aga Can you post the 400 return as well? In the JSON of the return it should tell you the SendResult and give you the proper message.

0 Upvotes