Modify API result

I have this result from curl the API:

{
	"success": true,
	"results": {
		"id": "1d781c570ff2fc71047b225de95bac4a",
		"drive_id": "abcxyz"
	}
}

Since the player need the result from API to be in this format:

{
	"success": true,
	"results": {
		"file": "https://api.domain.com/1d781c570ff2fc71047b225de95bac4a.m3u8",
		"drive_id": "abcxyz"
	}
}

so I have this after curl function

if($results->success) {
    $dr_id = $results->results->id;
    $m3u8 = 'https://api.domain.com/'+$dr_id+'.m3u8';
    return $m3u8;
} else {
   return 'Error';

I know this is wrong but I don’t know how to change the api result to the correct format.

This isn’t JavaScript. The only things I really see wrong, is you don’t concatenate strings like that in PHP and you are making extra variables for no reason.

return "https://api.domain.com/{$results->results->id}.m3u8";

However, I don’t know what you are trying to return. If this is getting called, you should return a JSON message with the URL. If you are just building the page, the url itself works, but you lose separation of concerns.

Sponsor our Newsletter | Privacy Policy | Terms of Service