aweber / public-api-examples

Repository containing examples for api.aweber.com
BSD 3-Clause "New" or "Revised" License
22 stars 42 forks source link

Create Subscriber: 400 Bad Request #29

Closed fastesol closed 5 years ago

fastesol commented 5 years ago

Hi, while working on the API, I found that there are some missing or incorrect information in the documentation or may be I have miss interpreted.

I'm following this documentation to add subscriber to an account/list

First of all, as you see the ws.op parameter is required, but the example doesn't show the use of ws.op parameter.

Secondly, I've tried adding the subscriber using the following code

// add the subscriber if they are not already on the first list
$data = array(
    'email' => $email
);
$body = $client->post($SUBS_URL, [
        'json' => $data, 
        'headers' => ['Authorization' => 'Bearer ' . $accessToken]
    ]);

and got the following error

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://api.aweber.com/1.0/accounts/XXXXXX/lists/XXXXXX/subscribers` resulted in a `400 Bad Request` response: {"error": {"status": 400, "documentation_url": "https://labs.aweber.com/docs/troubleshooting#badrequest", "message": "In (truncated...) ' in /var/www/html/aweber/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /var/www/html/aweber/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /var/www/html/aweber/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /var/www/html/aweber/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 /var/www/html/aweber/vendor/guzzlehttp/promises/ in /var/www/html/aweber/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

Also tried appending the '?ws.op=create' in url but nothing works.

Please help, Thank you!

KMChappell commented 5 years ago

Thanks for reaching out, it looks like the error message got cut off, but it might have been "Invalid email address" since we don't have any others that start with "in" as far as I recall.

If you think it might be an invalid email then make sure you've specified a real email address and there's nothing goofy like an extra space or something going on and that the email isn't too long (50 characters max).

If you don't want to paste your account / list / test email details here in github you can send us an email at api@aweber.com with those and we can take a deeper look into the logs for you.

I'm currently unable to replicate any issues with this script so I think we've just got some simple thing like a problem with the email address on our hands here.

Kaitlyn C.

fastesol commented 5 years ago

Hi Kaitlyn, thank you for the quick reply. Here is the complete code snippet to create subscription.

const ACCOUNT_ID = 1382823;
const LIST_ID = 5329970;
$body = [
    'email' => 'info@fastesol.com'
];
$headers = [
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer ' . $accessToken
];
$url = "https://api.aweber.com/1.0/accounts/".ACCOUNT_ID."/lists/".LIST_ID."/subscribers/?ws.op=create"; 
$response = $client->post($url, ['json' => $body, 'headers' => $headers]);
fastesol commented 5 years ago

Well, I tried adding the try/catch block and used die($e->getResponse()->getBody()->getContents()); to check the error and here it is.

{"error": {"status": 400, "documentation_url": "https://labs.aweber.com/docs/troubleshooting#badrequest", "message": "email: Email address blocked. Please refer to https://help.aweber.com/hc/en-us/articles/204029356 .", "type": "WebServiceError"}}
KMChappell commented 5 years ago

Hello,

The email addresses starting with info@, contact@, support@, etc are what AWeber calls role-based email addresses. These are not permitted to be added via the API. The potential for spam complaints is drastically higher for these types of email addresses, as they are typically used as catchall inboxes. For a bit more information please take a look at the Knowledge Base article below, or the one in the error you posted. They're pretty similar.

https://help.aweber.com/hc/en-us/articles/204029336-Can-Subscribers-Using-Role-Based-Email-Addresses-Be-Added-To-My-List-

These email addresses can only be added from an HTML sign up form and will always be required to confirm.

I'd suggest using a different email address. If your email host allows you to make extra addresses with forwarding you could make one like @fastesol.com and use that, or you could make a free gmail or yahoo account to test with if you'd like.

cknave commented 5 years ago

Thanks for letting us know about the documentation issue, @fastesol. I've updated the documentation on api.aweber.com to remove the ws.op parameter from the add subscriber endpoint.

fastesol commented 5 years ago

Thank you! Its working with different email address