pramsey/pgsql-http

Doubts about escape single quote

Closed this issue · 2 comments

Hi Team

 I have a doubt about how i can escape single quote inside select sentence?, i've tryed to add single quote , but when i run ,


 SELECT *
     FROM http((
      'GET',
      'https://proxy1.sked24api.io/v1/Patients?$filter=DocumentNumber eq ''151515'' and DocumentType eq ''NationalId'' and DocumentCountry eq ''CL''',
       ARRAY[http_header('Authorization','Bearer XXXXXXXXXXX'),
			 http_header('Ocp-Apim-Subscription-Key','XXXXXXXXX')],
       NULL,
       NULL
    )::http_request);

I get the following message from the server

"

<TITLE>Bad Request</TITLE>

Bad Request


HTTP Error 400. The request is badly formed.

"

But if i run directly from postman without double single colon , it works.., what's the wrong??

https://proxy1.sked24api.io/v1/Patients?$filter=DocumentNumber eq '151515' and DocumentType eq 'NationalId' and DocumentCountry eq 'CL'

Regards,
Pablo

Depends a little bit on the API you are calling, but at a first approximation at a minimum you'll want to put everything after the filter= part of the URL through the urlencode function. Then the question of what the API considers to be a legal filter comes in, but that's not my problem, that's your problem.

Hello, good morning, indeed the problem that happened to me was because I had to use encode but from the question mark onwards.

I validated it from postman, and when it worked there without problems, I proceeded to repeat the experience, and here is the url encode

https://proxy1.sked24api.io/v1/Patients?**%24filter%3DDocumentNumber%20eq%20%2715015%27%20and%20DocumentType%20eq%20%27NationalId%27%20and%20DocumentCountry%20eq%20%27CL%27**

I'm posting this comment, just in case someone else has a similar problem and unsuccessfully tries to escape characters in the url.

Regards,
Pablo