$access_token – this is the same as your existing OAuth application access token – this has not changed, at least in my case.
$group_guid – this is the only new piece of information you might need. While you can query for this value via the API, for most people the simplest way to get it is to open into your Bitly account in a web browser, where you will find the GUID in the URL, as per this image:
$shorten_domain – if you have a custom domain – (for example, I have the domain “mwyr.es” for shortening purposes) – this is the value you need here. If you don’t have a custom domain, just use “bit.ly”.
$shorten_url – this is the URL you wish to shorten – simple!
So now you can call the function, with the required information.
Firstly, the input data required by the API is converted to JSON via the json_encode() function.
Secondly, we set up the cURL handle, and then supply it with the required data. Note the JSON data is passed within the “CURLOPT_POSTFIELDS” variable, and that the access token is passed as the “Authorization: Bearer” header in the “CURLOPT_HTTPHEADER” variable.
Then we execute with curl_exec() – and store and return the results for further processing.
To understand the returned JSON – (including the generated short link) – and the HTTP response codes, refer to the excellent Bitly API v4 documentation.