kpako1998
kpako1998

Reputation: 161

Disable urlEncoding in GuzzleHTTP 6

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"

Upvotes: -1

Views: 339

Answers (1)

kpako1998
kpako1998

Reputation: 161

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

Upvotes: 0

Related Questions