Problems defining url string whose query string parameter contains the dollar sign ($)

3

I'm using a WS API in JSON

the URL is

https://api.movidesk.com/public/v1/persons?token=52ee6ca5-8639-422b-bafe-470013c11176&$filter=profileType eq 2

which is the example in which the API documentation passes. when playing in the browser is

https://api.movidesk.com/public/v1/persons?token=52ee6ca5-8639-422b-bafe-470013c11176&$filter=profileType%20eq%202

But the information appears

My problem is when I use the API in PHP

Example

 <?php $json = file_get_contents("https://api.movidesk.com/public/v1/persons?token=52ee6ca5-8639-422b-bafe-470013c11176&$filter=profileType%20eq%202");
      $cliente = json_decode($json);

I get the following error

  

Notice: Undefined variable: filter in C: \ xampp \ htdocs \ Maps \ json.php on line 54

     

Warning: file_get_contents ( link $ filter = profileType% 20eq% 202): failed to open stream: HTTP request failed! HTTP / 1.1 500 Internal Server Error in C: \ xampp \ htdocs \ Maps \ json.php on line 54

    
asked by anonymous 18.04.2017 / 22:33

1 answer

2

As I understand it, the url parameter has a value called $filter .

In the section where you try to make the request with file_get_contents , you are using double quotation marks. When you do this, PHP interprets values that start with $ as being the value of the variable.

This is because you are using double quotation marks. Just use single quotation marks that will solve the problem.

$json = file_get_contents('https://api.movidesk.com/public/v1/persons?token=52ee6ca5-8639-422b-bafe-470013c11176&$filter=profileType%20eq%202');

$cliente = json_decode($json);

For more information, read:

Difference between single and double quotation marks in PHP

    
18.04.2017 / 22:36