odata-client-php icon indicating copy to clipboard operation
odata-client-php copied to clipboard

Headers and query params

Open StalkAlex opened this issue 6 years ago • 7 comments

How can I pass them? Could you show an example please?

StalkAlex avatar Oct 31 '18 14:10 StalkAlex

If it is helpful, I was able to pass headers this way:

$odataClient = new ODataClient($serviceURL, function($request) {
    $request->headers['APIKEY'] = 'SuperDuperSecretKey';
});

For query parameters I use ->where() for oData's filter.

calebtr avatar Jan 14 '19 20:01 calebtr

Thanks for the hint! It could be done like this, but in my case I need to change them every time before a new request. So I solved this problem by creating ODataRequest instance for every request. But this is not an ideal solution.

StalkAlex avatar Jan 15 '19 09:01 StalkAlex

@StalkAlex, thanks for opening this.

I think we can achieve this by adding a headers or withHeaders method onto the QueryBuilder to allow for appending to/modifying the headers collection set on the ODataRequest.

Can you give an example of the headers you're wanting to set? Just curious.

anderly avatar Jan 30 '19 19:01 anderly

@anderly currently I found way to get around this problem. Here's my way and example of the header

            $request = new ODataRequest('POST', $requestUrl, $this->client);
            $request->addHeaders([
                'Content-Type' => 'text/xml'
            ]);
            $request->attachBody($fileContent);
            $response = $request->execute();

StalkAlex avatar Feb 11 '19 09:02 StalkAlex

So how do I add a custom parameter to query?

For example I need: https://api.domain.com/v1/Orders?exported=false

solokhind avatar Dec 15 '20 22:12 solokhind

getting below error while query, can you help me with solution #message: "cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)" #code: 0 #file: "C:\wamp64\www\drupal\xxx\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php"

manojiksula avatar Oct 14 '21 05:10 manojiksula

@manojiksula, that's unrelated to this package, but see here for how to resolve your certificate issue https://stackoverflow.com/a/31830614

anderly avatar Oct 14 '21 13:10 anderly