How to call API from external script?

How do you call this API from an external PHP script?  I'm assuming via cURL?  How would you pass in the username and password in a GET scenario?

I'm still curious if this can be called via cURL, or is the URL format you gave above the only way to call it?

tim

cURL has no limitations of HTTP Basic Auth or GET, POST, PATCH, DELETE requests. See cURL RESTful examples on the web.

OK.  Apparently the data needs to be passed  as JSON.  This works:

curl -X POST --user 'name:pass' --header 'Content-Type: application/json' 
--data '{"code":"xx","name":"Xtra","url_type":"none"}' https://domain.com/api.php/languages

Is there any way to allow us to pass normal cURL key=value pairs and have the API convert it to JSON, if needed?

Nevermind.  I worked it out and converted it to use the cURL key=value pairs.

Was there a reason you chose JSON for the input here or was it just personal preference?  Just curious if I should use it as-is, or go with my converted script.

tim

JSON dominates the industry when it comes to APIs and portable data. I think it's clean flexible and robust. Easier to read and has compatibility with most if not all programming languages.

You said PHP so simply do json_encode($data) instead of http_build_query($data).

View code on GitHub