2

Hi i am getting this error when I try to validate an email: [documentation] => https://code.docs.exacttarget.com/rest/errors/500 [errorcode] => 0 [message] => Internal Server Error

The code was working fine but suddently stops. Please help to solve this issue:

function getSalesForceToken(){
    $url = 'https://auth.exacttargetapis.com/v1/requestToken';
    $data = array(
     'clientId' => $this->clientId,
     'clientSecret' => $this->clientSecret
    );                                                                
    $data_string = json_encode($data);                                                                                 
    $ch = curl_init($url);                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string))                                                                       
    );          
    $result = curl_exec($ch);
    curl_close($ch);
    $token=json_decode($result);
    print_r($token);
    validateMail("[email protected]", $token->accessToken);
}
function validateMail($mail,$token){
    $this->request='{"method":"validateMail","data":  [{"email":"'.$mail.'"}]}';
    callETMethod(
        'https://www.exacttargetapis.com/address/v1/validateEmail', 
        $token,
        array(
         'email' => $mail,
         'validators' => array("SyntaxValidator", "MXValidator", "ListDetectiveValidator")
        ));

function callETMethod($url,$token,$data){
    $data_string = json_encode($data);                                                                                   
    $ch = curl_init($url);                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',   
        'Authorization: Bearer '.$token,                                                                         
        'Content-Length: ' . strlen($data_string))                                                                       
    );                                                                                                                   
    $result = curl_exec($ch);
    curl_close($ch);
    $result=json_decode($result);

    switch ($result->documentation) {
        case 'https://code.docs.exacttarget.com/rest/errors/400':
            $this->getSalesForceToken();
            break;
        case 'https://code.docs.exacttarget.com/rest/errors/500':
            echo($url."<br/>");
            echo($token."<br/>");
            print_r($data);  
            echo("<br/>");
            print_r($result);
            break;

        default:
            print_r (json_decode($result)); 
            break;
    }
}

I have no errors getting the access token but when I try to validate an email the error comes in.

Regards

MA

1
  • any chance you have the curl request that is being sent out? that may help solve the issue quicker, unless someone knows this specific library. May 20, 2015 at 17:19

1 Answer 1

1

This usually indicates that the RESTful request format is invalid. Have you tried making the request manually through a REST client? (For example, Postman or others). I've just tested the method using Postman and it works fine for me. Here is my request:

POST https://www.exacttargetapis.com/address/v1/validateEmail
Content-Type: application/json
Authorization: Bearer insertAccessTokenHere
{
  "email": "[email protected]",
  "validators": [ "SyntaxValidator", "MXValidator", "ListDetectiveValidator" ]
}

Which returns the response:

{
  "email": "[email protected]",
  "valid": true
}

From looking at your code, I see you are using the Content-Length header. Perhaps this is the problem. Can you try removing it? If that doesn't work, can you echo out the request that your PHP code is making to a log file?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .