-1

I am working on a project that needs to be integrated into the Sage Accounting platform, and the API key I was given is enclosed in curly braces. The issue I am having is on making the POST request, Guzzle converts the apiKey to an encoded string which results in a 401 Forbidden error from Sage due to the encoding by Guzzle.

Is there a workaround around disabling urlEncoding in Guzzle 6?

 $url = "https://resellers.accounting.sageone.co.za/api/2.0.0/Item/Get?apiKey={********-****-****-****-70258015CCD1}&CompanyId=13732";
            $username = "*********";
            $password = "******";
            $body = [
                'Description' => $request->product_description,
                'Category' => $request->cat_id,
                'Active' => 1,
                'PriceInclusive' => $request->price,
                'QuantityOnHand' => $request->quantity
            ];
            $client = new Client();
            $response = $client->post($url, ['auth' => [$username, $password],'headers' => ['Accept' => 'application/json'], 'form_params' => $body]);

            $decodeResponse = json_decode($response);

This is the url I get on sending a POST request:

 "https://resellers.accounting.sageone.co.za/api/2.0.0/Item/Get?apiKey=%7B********-****-****-****-70258015CCD1%7D&CompanyId=13732"
kpako1998
  • 141
  • 1
  • 12
  • Url encoding is expected behaviour and hard to disable. The only thing I found which you could consider is implementing your own `Uri` class as suggested [here](https://github.com/guzzle/guzzle/issues/1758#issuecomment-581111911) – PtrTon Mar 21 '21 at 08:51
  • @PtrTon Please can you give more explanation on how I can do that. Having issues understanding it. – kpako1998 Mar 21 '21 at 08:55
  • Open a ticket at SAGE and tell them to correct their implementation... [Curly](https://meta.stackexchange.com/questions/79057/curly-brackets-in-urls) brackets are [not allowed](https://tools.ietf.org/html/rfc3986#section-3.4). – Ulrich Thomas Gabor Mar 21 '21 at 08:59
  • Can you pass them as separate parameters (as in https://stackoverflow.com/questions/23372598/adding-query-string-params-to-a-guzzle-get-request) – Nigel Ren Mar 21 '21 at 09:02
  • @NigelRen Done that before. Got thesame error. It encodes query params. – kpako1998 Mar 21 '21 at 09:06

1 Answers1

0

I fixed this error by using CURL. I got to find out that there was no workaround using Guzzle.

kpako1998
  • 141
  • 1
  • 12