karel
karel

Reputation: 53

ExactOnline API en OData

I am struggling with the API of Exact Online. Using this example code to retrieve information of the server:

$response = $exactApi->sendRequest("crm/Accounts?$filter=substringof('test', Name) eq true', 'get');

Above returns a Bad Request. Anyone got a clue how to fix this?

The function 'send request':

    public function sendRequest($url, $method, $payload = NULL)
{
    if ($payload && !is_array($payload)) {
        throw new ErrorException('Payload is not valid.');
    }

    if (!$accessToken = $this->initAccessToken()) {
        throw new ErrorException('Access token was not initialized');
    }

    $requestUrl = $this->getRequestUrl($url, array(
        'access_token' => $accessToken
    ));

    // Base cURL option
    $curlOpt = array();
    $curlOpt[CURLOPT_URL] = $requestUrl;
    $curlOpt[CURLOPT_RETURNTRANSFER] = TRUE;
    $curlOpt[CURLOPT_SSL_VERIFYPEER] = TRUE;
    $curlOpt[CURLOPT_HEADER] = false;

    if ($method == self::METHOD_POST) {

        $curlOpt[CURLOPT_HTTPHEADER] = array(
            'Content-Type:application/json', 
            'access_token:' . $accessToken, 
            'Content-length: ' . strlen(json_encode($payload))
        );
        $curlOpt[CURLOPT_POSTFIELDS] = json_encode($payload);
        $curlOpt[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
    }
    $curlOpt[CURLOPT_ENCODING] = '';
    $curlHandle = curl_init();
    curl_setopt_array($curlHandle, $curlOpt);

    return curl_exec($curlHandle);
}

Upvotes: 3

Views: 688

Answers (1)

Lennert Coopman
Lennert Coopman

Reputation: 156

Tested this.

crm/Accounts?$select=Name&$filter=substringof('Lennert',Name) : OK

crm/Accounts?$select=Name&$filter=substringof('Lennert', Name) eq true : NOK, error 400

crm/Accounts?\$select=Name&$filter=substringof(Name, 'Lennert') eq true : NOK, error 400

First option works but is not according to OData v2 specifications which Exact Online uses. Will be discussed with development to see what can be done for this.

Upvotes: 1

Related Questions