unit Unit1;
interface
uses
Vcl.Forms, Vcl.StdCtrls, REST.Client, REST.Types, System.Classes, System.SysUtils;
type
TForm1 = class(TForm)
btnCreateProduct: TButton;
RestClient1: TRestClient;
RestRequest1: TRestRequest;
RestResponse1: TRestResponse;
procedure btnCreateProductClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
RestClient1.BaseURL := 'https://api.rd.services';
RestClient1.Params.AddHeader('Authorization', 'Bearer YOUR_ACCESS_TOKEN');
RestRequest1.Client := RestClient1;
RestRequest1.Method := rmPOST;
RestRequest1.Resource := '/crm/v1/products';
RestRequest1.Params.Clear;
RestRequest1.Params.AddItem('Content-Type', 'application/json', pkHTTPHEADER, [poDoNotEncode]);
end;
procedure TForm1.btnCreateProductClick(Sender: TObject);
var
JSONBody: string;
begin
JSONBody := '{"name": "Produto de Teste", "code": "12345", "unit_value": 1000}';
RestRequest1.AddBody(JSONBody, ctAPPLICATION_JSON);
try
RestRequest1.Execute;
if RestResponse1.StatusCode = 201 then
ShowMessage('Produto criado com sucesso!')
else
ShowMessage('Erro ao criar produto: ' + RestResponse1.Content);
except
on E: Exception do
ShowMessage('Erro: ' + E.Message);
end;
end;
end.