Event Handler fails because of undefined object

Hi,
hope you are doing well and staying healthy.

I am using an Event Handler and from it I am making a GET HTTP request, like that:

const url = 'https://some.api.url/latest/price';

 return Backendless.Request.get(url)
      .query({ marketing_type: 'sell' })
      .then(function(response) {
...
}

The problem is, it sends a request with an error. For some reason there is an undefined and empty object in the end and I have no idea where it comes from. If I remove query() at all it stays anyway.

https://some.api.url/latest/price?marketing_type=sell undefined {}

Do you maybe have an idea how can I fix that? I am already out of ideas, unfortunately.
Thanks a lot!

Hi @nike-teo,

Let me ask you a few questions in order to identify the issue.

For some reason there is an undefined and empty object in the end

In the end of what?

https://some.api.url/latest/price?marketing_type=sell undefined {}

Where do you see this string?

Regards,
Stanislaw

Hi, thanks for your answer.

I am using

Backendless.Request.verbose = true

to log requests and response, and this is what I get

9:46:46.111 | SERVER_CODE | INFO | [24609] GET https://some.api.url/latest/price?marketing_type=sell undefined {}
19:46:46.196 | SERVER_CODE | ERROR | [24609] Error:

So I assume that it is a request url is being composed that way, I tried hitting that api just from browser with that in the end and I get exactly same error what I get here.

Thank you for the details.

The log you are seeing, it consists from a few parts:

  1. The HTTP method (GET in your case)
  2. The path (https://some.api.url/latest/price?marketing_type=sell)
  3. The body (undefined - because this is a GET request, there are no body in GET request, it’s OK)
  4. The headers (empty object, no custom headers passed)

So, this is not the root of the error.
I tried to open this URL in my browser and see that this URL is just not valid - some.api.url - is not a registered domain, seems it’s just some copied example value from docs or tutorial.

Or maybe you have changed real domain to some.api.url for this topic only on purpose?

In any case, you should see the error text right after 19:46:46.196 | SERVER_CODE | ERROR | [24609] Error: log. Do you see something there?

Regards,
Stanislaw

Okay, I think I finally figured out the issue. Seems like it works from curl, from browser and from phone, but not from the Event Handler, I think backendless is blocked or restricted in some way. Is there a way to get a dedicated IP address for cloud code or something like that to bypass that issue?

Thanks for your help,
best,

Nick.

Yes, seems like AWS WAF firewall thinks that Backendless is a bot. That is what I get

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>

<HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD>

<BODY>
    <H1>403 ERROR</H1>
    <H2>The request could not be satisfied.</H2>
    <HR noshade size="1px"> Request blocked. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
    <BR clear="all"> If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
    <BR clear="all">
    <HR noshade size="1px">
    <PRE>
Generated by cloudfront (CloudFront)
Request ID: _TfRXvHPIiWd2QoWdt_PvhZGhcJR0Ak1xKn_8H5vd8GZVs_9NgyT9FA==
</PRE>
    <ADDRESS>
</ADDRESS>
</BODY>

</HTML>