Does Marketo API block curl on a per account basis?

327 views Asked by At

I am trying to connect to the Marketo.com REST API using curl. I can't get a response from the identity service. I only get an error message

"[curl] 6: Couldn't resolve host 'MY_CLIENT_ENDPOINT.mktorest.com'

, but I can print the constructed url and paste it into a browser address bar and this will provide the expected response with the access_token element.

I can use curl in php and in a terminal to access my gmail account so curl is able to access an https service. I have tried sending the parameters in the curl url as a get request and also by declaring them with curl's -F option as a post request

My application uses dchesterton/marketo-rest-api available on github, but I have also tried a simple php curl request just to get the access token.

private function getToken() {
    $url = "$this->client_url/identity/oauth/token?grant_type=client_credentials&client_id=$this->client_id&client_secret=$this->client_secret";

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    $errors = curl_error($ch);
    curl_close($ch);

    file_put_contents($this->logDir . 'access_token_response' . date('Y-m-d') . '.txt', $url . "\n" . $response . "\n", FILE_APPEND);
    if ($errors) {
        file_put_contents($this->logDir . 'access_token_errors' . date('Y-m-d') . '.txt', $errors . "\n", FILE_APPEND);
    }
    return $response['access_token'];
}

Again, this fails with the same error but produces a perfectly formed url that I can paste into the browser and get a valid response. I have also tried this using post instead of get as I have for every other test mentioned, and these have been tried on my localhost and on a test server.

Can anyone explain to me why this would fail? Does Marketo block curl on a per account basis?

1

There are 1 answers

1
Jide Okusanya On

I was trying to implement something similar but my code wasn't working. I'm not sure exactly what is failing but I tried your code and it seems to work perfectly after some slight modifications:

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($request_data));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($curl);
$errors = curl_error($curl);
curl_close($curl);

I hope this helps.