Reputation: 3238
I have a REST Service. By default, the JSON data being returned has all the NULLs eliminated. This is causing me difficulties, so I have a request header setting that changes the behavior. The request header I need to add is: Accept-Formatting: json-nulls=include
I have been able to get to work from POSTMAN, using the following format.
I have not been able to get this to work from my application.
My application has a TRestClient, TRestResponse and TRestRequest.
I have tried adding this as a parameter on both TRestClient and TRestRequest. While the REST service returns the data, the NULL fields are not being displayed, which tells me that my format (or something else relating to the request header) is not correct. Where and HOW should this be added?
Any thoughts appreciated.
Upvotes: 6
Views: 12623
Reputation: 2219
In case you want to send the firebase notification programmatically you can try the way I use and it is working for me.
{Send a notification to Firebase Messaging.
@param Titulo Notification title
@param Mensagem Notification message
@param Page The page the user will be redirected after the notification is clicked Ex: `/home`}
function EnviarNotificacao(Titulo, Mensagem, Page: string): string;
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
JsonBody, JsonNotification, JsonData, JsonResponse: TJSONObject;
begin
RESTClient1 := TRESTClient.Create(nil);
RESTRequest1 := TRESTRequest.Create(nil);
RESTResponse1 := TRESTResponse.Create(nil);
RESTRequest1.Client := RESTClient1;
RESTRequest1.Response := RESTResponse1;
RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Params.AddItem('Authorization', 'key=AAAd...', pkHTTPHEADER, [poDoNotEncode]);
RESTClient1.BaseURL := 'https://fcm.googleapis.com/fcm/send';
JsonBody := TJSONObject.Create;
JsonNotification := TJSONObject.Create;
JsonData := TJSONObject.Create;
JsonNotification.AddPair('title', Titulo);
JsonNotification.AddPair('body', Mensagem);
JsonData.AddPair('click_action', 'FLUTTER_NOTIFICATION_CLICK');
JsonData.AddPair('page', Page);
JsonBody.AddPair('notification', JsonNotification);
JsonBody.AddPair('data', JsonData);
JsonBody.AddPair('to', '/topics/your_topic');
RESTRequest1.AddBody(JsonBody);
RESTRequest1.Execute;
JsonResponse := RESTResponse1.JSONValue as TJSONObject;
Result := JsonResponse.ToString;
end;
You should also free the TJSONObject
, I didn't do that because I was in a hurry.
Upvotes: 1
Reputation: 2358
Try directly call from Tools > Rest debugger, if all working copy/paste component to your project and try manuly change some parameter.
Example:
Upvotes: 3