I have 3 server keys in my google console for different servers.
In the beginning only one key seemed to work, and that was my local IP address.
After debugging with cURL on the staging server I found that the response was:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
This didn't really make sense to me, because the key was provided and the key was definitely set with the appropriate IP address.
So I started the debugging process and for the staging server I tried some cURL IP discovery tools.
Suddenly icanhazip.com gave me the IPv6 address to my server, after adding this to the Allowed IP list it suddenly worked. Some weird behavior if you ask me.
So I still had my Production server to fix, and I found out that this one doesn't have an IPv6 address. The same tool returns the IPv4 address for me and in my control panel I also didn't set up an IPv6 address.
As google doesn't have a big support platform, I'm hoping someone here has ran into the same problem.
I'm trying to use google's custom search API.
Apparently I was using cURL in the wrong way on my server. It now works like a charm!
(Had to add apostrophes around the URL)
If everything else fails, you could just scrape a google search page and parse the results? Something like this (PHP):
$ch = curl_init ('');
$query = 'Pepijn';
curl_setopt ($ch, CURLOPT_URL, 'http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q='.$query);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
You would need to "sort" through all the returned html and all, but the results are basically in the list items in #search ol.
Related
I am using Mailtrap's SMTP to send my development/test e-mails to a fake inbox.
Their SMTP server feature works well, but I'm now trying to implement their API v2 instead.
Every time I hit the https://send.api.mailtrap.io/api/send endpoint, I keep getting the following error:
{"errors":["Unauthorized"]}
More info
I have a Paid account and generated an API Token which has full Admin rights
Only the send.api.mailtrap.io/api/send endpoint fails, other endpoints such as mailtrap.io/accounts are working
I am getting the same error whether I use their API Doc Request testing tool or my code
I am getting the same error message with their API v1
cURL request used (from their API docs)
curl -X POST "https://send.api.mailtrap.io/api/send" \
-H "Accept: application/json" \
-H "Api-Token: xxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"to":[{"email":"john_doe#example.com","name":"John Doe"}],"from":{"email":"sales#example.com","name":"Example Sales Team"},"subject":"Your Example Order Confirmation","html":"<p>Congratulations on your order no. <strong>1234</strong>.</p>"}'
Similar cURL request via PHP (same error message)
<?php
$post = [];
$post['to'] = 'test#test.com';
$post['from'] = ['name' => 'Test', 'email' => 'test#test.com'];
$post['subject'] = 'Test';
$post['html'] = '<h2>This is a test</h2><p>It works!</p>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://send.api.mailtrap.io/api/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Api-Token: xxxxxxxxxxxxxxxxxxxxxxxxx']);
$result = curl_exec($ch);
print_r($result);
echo "\n";
I finally found the answer, here are my conclusions:
As of Today (Sep 2022), Mailtrap's Sending API cannot be used to send e-mails to your Mailtrap Sandbox (i.e. Fake Inbox). It can only be used to send real/production e-mails, to real users.
If your Mailtrap account is older than a year, you will most likely be missing the "Send API" section in your account and only see the "API" section. The only solution to address that was to create a new account.
If you still plan to use Mailtrap's Sending API (to send production e-mails), you will need to reach out to Support for some pre-configuration (This is not mentioned in the documentation) otherwise you will receive "Forbidden" from the API, without any additional details.
Does it mean we needs to write separate logic for dev/staging (using SMTP) and for prod (using API) in our apps? Sounds really strange.
I've looked into this and I have found the solution to your problem.
When looking at the send documentation, it states that you must also include an inbox id in your url and also use the sandbox url.
So, if you change your url from https://send.api.mailtrap.io/api/send to https://sandbox.api.mailtrap.io/api/send/1234567 then it should work - At least it did for me!
You can get the inbox id by going to the specific inbox in the webinterface and copy it from the url.
After 4 years of reliable operation, my PHP listener script started to fail from October 8th, 2019 onwards with the
Error - The request was aborted: Could not create SSL/TLS secure channel.
I have not changed anything on my server. The SSL certificate is a valid v3 from Lets Encrypt. TLS is 1.2.
I have been on support calls for hours with no resolution, other than them telling me that I need to install their certificates here: https://www.docusign.com/trust/compliance/public-certificates
The problem is that I don't know how I would integrate that with my server, and my web host doesn't know either. When asked, they are not able to explain it either.
The listener script on my server is fairly simple:
function guid() {
$uuid = '';
if (function_exists('com_create_guid')){
$uuid = com_create_guid();
// somehow the function com_create_guid includes {}, while our webservice
// doesn't. Here we are changing the format by taking those curly braces out.
$uuid = str_ireplace("{", "", $uuid );
$uuid = str_ireplace("}", "", $uuid );
} else {
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
}
return $uuid;
}
// Figure out the URL of this server
// NOTE: DocuSign only pushes status to HTTPS!
$postBackPath = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
$postBackPath .= ($_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] );
$postedXml = #file_get_contents('php://input');
if (!empty($_POST['post'])) {
// if this is a sample load
$xml = simplexml_load_file("post.sample") or die("Unable to load sample XML file!");
$xml->EnvelopeStatus->EnvelopeID = guid(); // here we replace the GUID so we have unique files
// using the curl library to get the post
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,30);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_URL, $postBackPath);
curl_setopt($curl, CURLOPT_HEADER, array("Content-Type: application/xml"));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_exec ( $curl );
curl_close ($curl);
}
else if(!empty($postedXml)) {
// see if this is a post to this page if it is then we have to save it.
$xml = simplexml_load_string($postedXml);
$post = $xml;
print 'Got Envelope ID: ' . $xml->EnvelopeStatus->EnvelopeID . '<br />';
}
After that code, it just parses data from the xml that I pass into my CRM.
On the Docusign Connect setup, I have the log enabled and require acknowledgement. All of the integration and security settings are unchecked (HMAC signature, Include basic authentication header, require mutual TLS, use SOAP interface, enable mutual TLS are all unchecked).
UPDATE: A response from my webhost assisting in this issue:
Hello again.
I took a look at the SSL you presently have installed for
sub.domain.com (you can see the info from Chrome browser) If you
click on the lock in the url bar and then click on Certificate >
Details > Version you (or docusign) can see that that cert is version
3 as they specified that you need.
I'm not clear on where they think that you should install their
certificate though. The cert at the link provided is to cover
na2.docusign.net which is not hosted on your server so there's no
place to install that that I'm aware of. You can verify that by
downloading the NA2 certificate from the link they provided:
https://www.docusign.com/trust/compliance/public-certificates
Open the .cer file in the simplest text editor you have available and
paste the contents in here:
https://www.sslshopper.com/certificate-decoder.html
That will give you all the information about the certificate. Under
"Subject:" you'll see CN = na2.docusign.net which means that it covers
their domain not yours.
I'm afraid we'll need more information from DocuSign to be able to
assist you. If this SSL were installed on your domain, it would fail
authenticity checks run by any browser connecting to your site which
isn't going to instill any confidence for your visitors.
This was my impression as well, so I feel like we are misunderstanding how this certificate from Docusign would work in conjunction with the certificate we already have from Lets Encrypt.
Is this a coding issue?
I am using a very simple Docusign connect integration, which is just a php listener catching the XML from a completed envelope and parsing it so I can pass that to my CRM.
I had the same issue today. after 5 hours digging into the internet, Here my change which resolved my issue:
+=+ all the update is related to the Haproxy certification setting, I added these three lines to the haproxy.conf file:
tune.ssl.default-dh-param 2048
ssl-default-bind-ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11
I was able to find this article: https://developers.docusign.com/esign-rest-api/guides/mutual-tls-apache2 and pass this to my server administrator. This was apparently had the missing info they needed to get it working. Not really an answer, but if you are struggling like I was, this will help steer you in the right direction.
see information on this page:
https://www.docusign.com/trust/compliance/public-certificates
"The renewed Connect certificates listed below are slated to be introduced into the DocuSign Service in the September 2019 - November 2019 timeframe. The ‘offer’ date specified below is the date the renewed certificate will be available for consumption and the ‘enforce’ date is when the renewed certificate will be the only option i.e. the current certificate will no longer be available for consumption."
You would have to update the certificate from that page on your server to fix this.
I'm new to using the curl library in php. I have been experimenting with some APIs where I came across this command
curl -i -H "API-KEY:xxxxxx" https://www.experiment.com/api/v2/list/
The API-KEY is given. Request is GET. The return format is in JSON. The service is using REST. I created a small PHP script
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://www.experiment.com/api/v2/list/");
curl_setopt($cSession, CURLOPT_HTTPHEADER, array("API-KEY: XXXXXXXXX"));
$result=curl_exec($cSession);
$result turns out to be false. Is there something I'm missing.
Thanks.
I'm using drupal 7 with the Media Youtube module. The module calls the youtube oEmbed API.
This is an example of url the module will call:
http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=YZqqD1Rv5BI
On my desktop, this returns a json file, all fine.
However on my website's server, I get a 503 Service unavailable error.
Actually I frst get a 302 not found, saying the url has moved, then a 503 error:
Here is what I get when I do a wget manually:
wget http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=YZqqD1Rv5BI
--2014-09-28 21:55:49-- http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=YZqqD1Rv5BI
Resolving www.youtube.com (www.youtube.com)... 2a00:1450:4007:808::1004, 173.194.40.131, 173.194.40.132, ...
Connecting to www.youtube.com (www.youtube.com)|2a00:1450:4007:808::1004|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://ipv6.google.com/sorry/IndexRedirect?continue=http://www.youtube.com/oembed%3Furl%3Dhttps://www.youtube.com/watch%3Fv%3DYZqqD1Rv5BI [following]
--2014-09-28 21:55:49-- http://ipv6.google.com/sorry/IndexRedirect?continue=http://www.youtube.com/oembed%3Furl%3Dhttps://www.youtube.com/watch%3Fv%3DYZqqD1Rv5BI
Resolving ipv6.google.com (ipv6.google.com)... 2a00:1450:4007:808::1008
Connecting to ipv6.google.com (ipv6.google.com)|2a00:1450:4007:808::1008|:80... connected.
HTTP request sent, awaiting response... 503 Service Unavailable
2014-09-28 21:55:49 ERROR 503: Service Unavailable.
Any help would be much much appreciated.
Thanks in advance
I met the same error, but the issue is not with the module, unfortunately (I would be able to fix it and commit a patch for the module mantainer).
As you already tested, even a simple wget gives the same issue and it comes from the fact that it uses IPv6. If you can force requests to youtube to be handled through IPv4 the problem will be solved. But this is just a work-around, not a real fix.
I found a way to force IPv4 DNS resolving in PHP:
$url = 'http://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZVSd5aSXlQ0';
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$json = curl_exec($c);
$status = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
This solution is actually working for me.
I'm trying to communicate with a third party server using curl.
The authentication system is as follows:
Use credentials to ask for cookie
Set cookie
Make requests
This in itself has not been a problem and I am able to make requests etc, but whatever I send the server always responds 200 even if i send an invalid data format. If i put the same url in the browser it returns error messages about the invalid format.
Does anyone know why this might be? Thanks in advance,
function go($url,$postvars=null)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie_.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie_.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POST,count($postvars));
$postfields = http_build_query($postvars);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_exec($ch);
curl_close($ch);
}
go($url,$login_array); //login=>'',pass=>''
go($url,$some_request_array);
One very likely possibility is a bug in the server code that means it sends 200 statuses with its error messages. Hence while in the browser it'll be an error message, because that's what is in the body, it'll still be "successful". Put an intercept (firebug network, fiddler, etc) on the browser access and see what the status is.
If this is the case you've two options:
Get the party responsible for the server to fix it.
Parse for the error message yourself, and then treat it as an error condition.