Call of REST API with JSON

Hello,

Sorry for disturbing again…

I’m currently trying to do something and I didn’t find answers in the forum. Bwarf… I found answer but it seems not to work anymore (topics of 2019…)

I have a windows service who is a webserver : it’s a REST API that updates title, logs title, calls others services…etc… It use a json payload to get needed data. Like this :

{
    "player": "B",
    "title": "Dance the night",
    "artists": "DUA LIPA",
    "playedtime": "04/09/2023 21:03:10",
    "type": "piMusic"
}

I found some topics that explain we can use IRESTClient to call REST API with a json. But, when I try it, I got the error "unknow type ‘IRESTClient’.

Here is my code. I don’t understand why IRESTClient doesn’t exist…It is still available ?

procedure OnPlayerStart(PlaylistIndex: integer; PlayerIndex: integer; Item: IPlaylistItem);
var
  build_response: IPersistentObject;
  client: IRESTClient;
begin
  SystemLog('Call of Service');
  build_response := Factory.CreatePersistentObject;

  build_response.SetString('player', 'RP');
  build_response.SetString('title', 'Dance the night');
  build_response.SetString('artists', 'DUA LIPA');
  build_response.SetString('playedtime', '04/09/202 21:03:10');
  build_response.SetString('type', 'piMusic');
  //message := build_response2.AsJSon(true, true);

  client := CreateRESTClientWithCredentials('https://heaven.local:9080', '', '');
  client.PostJSON('/api/save-tile/heaven-rewind', build_response);
end;

Any help would be appreciated !
Regards,

Sylvain

I think about that : maybe this IRESTClient interface is not provided because I use a Home Studio licence… I thought that REST API option (as I see it in the licence features comparison) was about when we want to call Mairlist from outside. But not when we want mairlist to call REST Api outside…

What do you think ?

Exactly, the REST scripting functions are not available in Home Studio.

Use this as a workaround:

HTTPPostRaw('https://heaven.local:9080/api/save-tile/heaven-rewind', 'application/json', build_response.AsJSON(false, false));
1 Like

Great ! Thanks a lot Torben ! I will try this tonight :slight_smile:

Hope it will work, but no reason it won’t ^^