Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: REST, D10


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 20, 2018 11:43 AM Last Post By: Jim Sawyer
Jim Sawyer

Posts: 214
Registered: 1/3/10
REST, D10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 8:53 AM
How can I dynamically put into REST params the
values shown in the following CURL snippet?

{
"Channels": [22],
"Targets": ["+19727689383"],
"Message": "Eureka!  I found it!",
"Execute": true
}


This is a POST request.

Thanks,
Jim Sawyer

Edited by: Jim Sawyer on Feb 20, 2018 8:54 AM
Clement Doss

Posts: 76
Registered: 3/26/00
Re: REST, D10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 10:53 AM   in response to: Jim Sawyer in response to: Jim Sawyer
Hi,

How can I dynamically put into REST params the
values shown in the following CURL snippet?

{
"Channels": [22],
"Targets": ["+19727689383"],
"Message": "Eureka!  I found it!",
"Execute": true
}


This is a POST request.

You can you TJsonObject (System.JSON).
Try something like:

var
  lJsChannels : TJsonArray;
  ljsTargets : TJsonArray;
  lJsObj     : TJsonObject;
begin
  lJsObj := TJsonObject.Create;
 
  lJsChannels := TJsonArray.Create;
  lJsChannels.AddElement( TJsonNumber.Create(22) );
  
  lJsTargets := TJsonArray.Create;
  lJsTargets.AddElement( '+19727689383' );
 
 lJsObj.AddPair( 'Channels', lJsChannels );
 lJsObj.AddPair( 'Targets', lJsTargets );
 lJsObj.AddPair( 'Message', ''Eureka!  I found it!' );
 lJsObj.AddPair( 'Execute', TJsonTrue.Create );
 
lJsObj.ToString will display the jsonObject -> { "Channels": [22], "Targets": ["+19727689383"], "Message": "Eureka!  I found it!", "Execute": true } 
 
lJsObj := TJsonObject.ParseJSONValue( '{ "Channels": [22], "Targets": ["+19727689383"], "Message": "Eureka!  I found it!", "Execute": true }' ) as TJsonObject;


and you're good to go

HTH,
Clément
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: REST, D10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 11:43 AM   in response to: Clement Doss in response to: Clement Doss
Thanks! I've got a lot of work to try to understand what you've provided, and how I can utilize this
with the RESTClient, RESTResponse, and RESTRequest components. Or should I go another
way? I'm trying to utilize the TrueDialog SMS API, and am assuming I need to use these
REST components. If so, could you please provide an insight on how I do so. I am an
experienced VCL Delphi programmer (since 1988) but an completely confused by
Web Services.

Thank you so much!
Jim Sawyer

Clement Doss wrote:
Hi,

How can I dynamically put into REST params the
values shown in the following CURL snippet?

{
"Channels": [22],
"Targets": ["+19727689383"],
"Message": "Eureka!  I found it!",
"Execute": true
}


This is a POST request.

You can you TJsonObject (System.JSON).
Try something like:

var
  lJsChannels : TJsonArray;
  ljsTargets : TJsonArray;
  lJsObj     : TJsonObject;
begin
  lJsObj := TJsonObject.Create;
 
  lJsChannels := TJsonArray.Create;
  lJsChannels.AddElement( TJsonNumber.Create(22) );
  
  lJsTargets := TJsonArray.Create;
  lJsTargets.AddElement( '+19727689383' );
 
 lJsObj.AddPair( 'Channels', lJsChannels );
 lJsObj.AddPair( 'Targets', lJsTargets );
 lJsObj.AddPair( 'Message', ''Eureka!  I found it!' );
 lJsObj.AddPair( 'Execute', TJsonTrue.Create );
 
lJsObj.ToString will display the jsonObject -> { "Channels": [22], "Targets": ["+19727689383"], "Message": "Eureka!  I found it!", "Execute": true } 
 
lJsObj := TJsonObject.ParseJSONValue( '{ "Channels": [22], "Targets": ["+19727689383"], "Message": "Eureka!  I found it!", "Execute": true }' ) as TJsonObject;


and you're good to go

HTH,
Clément
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02