How to consume an API by json with PHP

-1

I have a query that seems maybe something simple, but searching the web I could not find the answer.

It turns out that I have an api with its documentation, which shows which parameters are accepted via Json, but I have no clear idea how to use this API from my Php code.

Please, if someone has an accurate example, it will be a great help!

Here is the API documentation: link

Of course, thank you very much!

    
asked by Alejandro Zbrun 14.07.2018 в 07:04
source

1 answer

1

You can use this library link

Once you have it installed or instantiated in your project you can do the following:

Requests::register_autoloader();

$data_to_send = json_encode(array("apikey"=>"theapikey","text"=>"Hola soy un mensaje...")));**

All the parameters that you want to send would go inside the array.

Once you have defined it, you execute a request in the http method that you want, here I give you an example.

$request = Requests::post('endpinturl', array('content-type'=>'application/json'), $data_to_send);**

Once the request has been made, you can check the answer with print_r ($ request- > body).

    
answered by 16.01.2019 в 23:22