Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

HTTP h;
h.addHeader('Content-Type', 'application/json');
h.addHeader('aftership-api-key', 'xxxxxxxxxxxxxxxxxxx');
h.setDebugMode(true);
Byte[] b = h.post('https://api.aftership.com/v4/trackings');
print(String(b)); 
print(h.getDebug());
print(h.getErrorMessage());

 

I'm trying to call Aftership's API via CRMScript in SO Online (Also tried a tenant in SOD), but i get the error:

HTTPConnection::endRequest(): Failure when receiving data from the peer

.. as well as an empty response and no output of "h.getDebug()". I tried with both .get and .post (as well as a post request with a json body)

I searched on the community, and as far as i can tell, the error relates to the endpoint using other ports than standard 80 or 443, but as you see this is a standard https 443 call, and it works fine with Post Man. Anyone who can see more than i can in relation to this error?

I tried to call google.com, and that returned html of google.com without any problems - i have other scripts on the same tenant running without issues.

PS:

I tried to use the same code in an on-premise SO 8, and there it works just fine, even getDebug returns something here:

{"meta":{"code":200},"data":{"page":1,"limit":100,"count":0,"keyword":"","slug":"","origin":[],"destination":[],"tag":"","fields":"","created_at_min":"2021-06-21T21:16:33+00:00","created_at_max":"2021-10-19T21:16:33+00:00","last_updated_at":null,"return_to_sender":[],"courier_destination_country_iso­3":[],"trackings":[]}}== Info
CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!

== Info
Trying 104.17.140.107...

== Info
TCP_NODELAY set

== Info
Connected to api.aftership.com (104.17.140.107) port 443 (#0)

== Info
ALPN, offering http/1.1

== Info
Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

== Info
successfully set certificate verify locations:

== Info
CAfile: C:\SuperOffice\Websites\Service/curl-ca-bundle.crt
CApath: none

== Info
TLSv1.2 (OUT), TLS header, Certificate Status (22):

== Info
TLSv1.2 (OUT), TLS handshake, Client hello (1):

== Info
TLSv1.2 (IN), TLS handshake, Server hello (2):

== Info
TLSv1.2 (IN), TLS handshake, Certificate (11):

== Info
TLSv1.2 (IN), TLS handshake, Server finished (14):

== Info
TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

== Info
TLSv1.2 (OUT), TLS change cipher, Client hello (1):

== Info
TLSv1.2 (OUT), TLS handshake, Finished (20):

== Info
TLSv1.2 (IN), TLS change cipher, Client hello (1):

== Info
TLSv1.2 (IN), TLS handshake, Finished (20):

== Info
SSL connection using TLSv1.2 / AES256-SHA

== Info
ALPN, server accepted to use http/1.1

== Info
Server certificate:

== Info
subject: CN=*.aftership.com

== Info
start date: Mar 8 00:00:00 2021 GMT

== Info
expire date: Apr 8 23:59:59 2022 GMT

== Info
subjectAltName: host "api.aftership.com" matched cert's "*.aftership.com"

== Info
issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Domain Validation Secure Server CA

== Info
SSL certificate verify ok.

=> Send header
GET /v4/trackings HTTP/1.1
Host: api.aftership.com
Accept: */*
Content-Type: application/json
aftership-api-key: xxxxxxxxxxxxxxxxxxxxxx


<= Recv header
HTTP/1.1 200 OK

<= Recv header
Date: Tue, 19 Oct 2021 21:16:33 GMT

<= Recv header
Content-Type: application/json; charset=utf-8

<= Recv header
Content-Length: 322

<= Recv header
Connection: keep-alive

<= Recv header
Surrogate-Control: no-store

<= Recv header
Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate

<= Recv header
Pragma: no-cache

<= Recv header
Expires: 0

<= Recv header
p3p: CP="AfterShip does not have a P3P policy. Learn why here: https://www.aftership.com/p3p"

<= Recv header
Access-Control-Allow-Origin: *

<= Recv header
Access-Control-Allow-Credentials: true

<= Recv header
Access-Control-Allow-Methods: GET,OPTIONS

<= Recv header
Access-Control-Allow-Headers: Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,aftership-api-key,aftership-agent,request-id

<= Recv header
X-RateLimit-Limit: 100

<= Recv header
X-RateLimit-Remaining: 98

<= Recv header
X-RateLimit-Reset: 1634761184

<= Recv header
X-Response-Time: 87.962ms

<= Recv header
Vary: Accept-Encoding

<= Recv header
Via: 1.1 google

<= Recv header
CF-Cache-Status: DYNAMIC

<= Recv header
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"

<= Recv header
Strict-Transport-Security: max-age=31536000; includeSubDomains

<= Recv header
Server: cloudflare

<= Recv header
CF-RAY: 6a0d0734c887d8a1-CPH

<= Recv header


<= Recv data
{"meta":{"code":200},"data":{"page":1,"limit":100,"count":0,"keyword":"","slug":"","origin":[],"destination":[],"tag":"","fields":"","created_at_min":"2021-06-21T21:16:33+00:00","created_at_max":"2021-10-19T21:16:33+00:00","last_updated_at":null,"return_to_sender":[],"courier_destination_country_iso­3":[],"trackings":[]}}
== Info
Connection #0 to host api.aftership.com left intact

So what is wrong in online? Maybe the SSL bundle that needs an update or? :) 

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

Hello,

If I run your code in Online and print the response headers there seems to be an DNS error, from what looks like the internal proxy that is used by Online.

Sample code:

#setLanguageLevel 3;

HTTP http;

http.addHeader('Content-Type', 'application/json');
http.addHeader('aftership-api-key', 'xxxxxxxxxxxxxxxxxxx');

http.setDebugMode(true);
NSStream responseStream = http.postAsStream('https://api.aftership.com/v4/trackings');

printLine(String(responseStream)); 
printLine(http.getDebug());
printLine(http.getErrorMessage());

Map headers = http.getResponseHeaders();

for (headers.first(); !headers.eof(); headers.next())
{
  	printLine (headers.getKey() + " => " + headers.getVal());
}

Response:

content-language => en
content-length => 3662
content-type => text/html;charset=utf-8
date => Wed, 20 Oct 2021 07
http/1.1 503 service unavailable =>
mime-version => 1.0
server => squid
vary => Accept-Language
x-squid-error => ERR_DNS_FAIL 0

Did you report this to support? this is propably something for the Online operations team.

By: David Hollegien 20 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

I tried your script using SuperOffice 10 onsite, and it works there. 

So I guess there is something on the way blocking the request to that particular host address, for example the proxy in Online. 

By: Stian Andre Olsen 20 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

I'll try to send it to support :)

By: Dennis Mortensgaard 20 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

From the header it seems like the squid proxy server is unable to lookup that host address in DNS. But difficult to know what actually is the problem from the error message, but most probably DNS related.

Agree that this is something for operations to look into. And now you can provide them with an address that does not work.

By: Stian Andre Olsen 20 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

503 is a server reply so it is able to reach out. The messega x-squid-error => ERR_DNS_FAIL 0 means error=0 so no DNS errors.

I tried also to test to connect to https://api.aftership.com/ both from inside and outside the online environment and i usually got the response: {"meta":{"code":200},"data":{"version":"v4","app_version":"1.3.509"}} but with some CONNECTION_FAILED in between regardless of location.

By: Per Kristian Eide 21 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

I'm not quite sure if it means that there's something wrong with aftership, or with the online environment?

As far as i have tested, the api works everytime i call it from here...

 

Hope you can figure out what is wrong :)

By: Dennis Mortensgaard 21 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

I'll just chime in and agree with Dennis. This doesn't work in Online or SOD.

This code works onsite, but not in Online or SOD.

#setLanguageLevel 3;

String URL = "https://api.aftership.com/v4/trackings";

HTTP http;
http.setOption("verifyPeer", "false");
http.setOption("verifyHost", "false");

http.setDebugMode(true);
String response = String(http.get(URL));

printLine(http.getResponseHeaders().toJson());
printLine(http.getErrorMessage());
printLine(http.getDebug());
printLine(response);

I believe Squid sets the header "x-squid-error" to "ERR_DNS_FAIL 0" when there IS an error. The 0 shouldn't be confused to indicate success.

You'll get the same error if you change the URL above to a non-existing domain.

So, if you ask me, this is a DNS issue inside in the SuperOffice environment.

By: Frode Lillerud 22 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

Dennis, you can try this workaround, which doesn't require any DNS lookups.

First, run nslookup to find what the IP is. Currently it looks like this:

Next, you change your URL in CRMScript to target one of the IP's instead.

Then, you need to set the Host-header, so that the receving webserver can do its virtual host routing.

And lastly, you need to tell curl to ignore certificate errors by disabling verifyHost.

#setLanguageLevel 3;

String URL = "https://104.17.139.107/v4/trackings";

HTTP http;
http.addHeader("Host", "api.aftership.com");
//http.setOption("verifyPeer", "false");
http.setOption("verifyHost", "false");

http.setDebugMode(true);
String response = String(http.get(URL));

printLine(http.getResponseHeaders().toJson());
printLine(http.getErrorMessage());
printLine(http.getDebug());
printLine(response);

 

By: Frode Lillerud 22 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

Thanks for the workaround Frode, works for now - hope for an official fix though as the ip address is targeting cloudflare CDN.

 

But hopefully the ip is static :)

 

 

By: Dennis Mortensgaard 27 Oct 2021

RE: HTTP Class calling aftership in online SO10 not working (Failure when receiving data from the peer) - works on on-premise SO8

Hi,

This error is now corrected by operations and it should be possible to call API from all online environments.

Sorry for the inconvenience and thank you for your patience.

/Michel

By: Michel Krohn-Dale 16 Nov 2021