Search the Community
Showing results for tags 'trestrequest'.
Found 3 results
-
Passing an array parameter to a REST server using Trestrequest
HGRogers posted a topic in Network, Cloud and Web
Hi I'm going round in circles trying to pass an array parameter to a REST server the required json structure of the params looks like this { "payment_method": [ "credit-card", "open-banking" ], "transaction_type": "SALE", "full_name": "Joe Blogs", "email": etc etc } Using a TRESTRequest adding those parameters with name : value pairs is easy. For the array parameter I've tried the RESTRequest.Params.Options of poFlatArray or poListArray with various combinations of double quotes commas curly and square braces without success Any pointers as to how I add the required array parameter gratefully received. The approach below I found on Stackoverflow looked promising but my Delphi (10.4) wont accept a string as the parameter to TJSONObject.ParseJSONValue() ?? (That's despite the prototype in system.json having a version of ParseJsonValue that does take a string) var aParam: TRESTRequestParameter; begin aParam := RestReq.Params.AddItem(); //don't care about setting a name for it aParam.Value := TJSONObject.ParseJSONValue('{"payment_method":["credit-card","open-banking"]}'); ...... RestClient.Execute(); end; -
Delphi REST showing only one row on the client side ?
toufik posted a topic in Network, Cloud and Web
hi every one can some one help me with problem I'm using Delphi REST with server and client but when i tried to show data on the client side its show only one row for some reason, what did i do wrong ? PS : I'm using Delphi roi and restdataware the video down show what I'm deal with ; any help will be very appreciated ^^ thank you on the client side i'm using this code procedure listv; var jsonObj : TJsonObject; json, sucesso, erro,id_store ,nom_store, phone_saler: string; begin // FrmLogin.FloatAnimation2.Stop; // FrmLogin.FloatAnimation3.Stop; if FrmLogin.listvreq.Response.JSONValue = nil then begin // FrmLogin.ExibirCampos; ShowMessage('خطأ في إنشاء الحساب (JSON غير صالح)'); exit; end; try json := FrmLogin.listvreq.Response.JSONValue.ToString; jsonObj := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(json), 0) as TJSONObject; sucesso := jsonObj.GetValue('sucesso').Value; erro := jsonObj.GetValue('erro').Value; id_store := jsonObj.GetValue('id_store').Value; nom_store := jsonObj.GetValue('nom_store').Value; if sucesso <> 'S' then begin // FrmLogin.ExibirCampos; ShowMessage(erro); exit; end else // showmessage('تم احضار بيانات: ' + id_store+nom_store); // FrmLogin.ExibirCampos;/// // FrmLogin.ListView1.Items.Clear(); finally jsonObj.DisposeOf; end; end; procedure listverr(Sender: TObject); begin if Assigned(Sender) and (Sender is Exception) then begin // FrmLogin.ExibirCampos; showmessage(Exception(Sender).Message); end; end; procedure TFrmLogin.StartLogin2; begin TThread.CreateAnonymousThread( procedure var Success: Boolean; begin try RequestLogin.Execute; Success := RequestLogin.Response.Status.Success; except Success := False; end; TThread.Queue(nil, procedure begin AfterLogin2(Success); end ); end ).Start; end; procedure TFrmLogin.AfterLogin2(Success: Boolean); begin if Success then begin listvreq.Params.Clear; listvreq.AddParameter('type_store',ComboBox1.Selected.Text); /// **** listvreq.ExecuteAsync(listv, true, true, listverr); end else begin showmessage (' عفوا ...! لايمكن الاتصال بالخادم حاليا يرجى المحاولة لاحقا') end; on server side : procedure Tdm.DWEventsEventslistvReplyEvent(var Params: TDWParams; var Result: string); var type_store, erro : string; usuario : TUsuario; json : TJsonObject; begin try sleep(4000); type_store := Params.ItemsString['type_store'].AsString; json := TJsonObject.Create; usuario := TUsuario.Create(dm.conn); usuario.type_store := type_store; if NOT usuario.listv(erro) then begin //{"sucesso": "N", "erro":"Usuلrio nمo informado", "codusuario":"0"} json.AddPair('sucesso', 'N'); json.AddPair('erro', erro); json.AddPair('id_store', ''); json.AddPair('nom_store', ''); end else begin json.AddPair('sucesso', 'S'); json.AddPair('erro', ''); json.AddPair('id_store', usuario.id_store.ToString); json.AddPair('nom_store', usuario.nom_store); end; Result := json.ToString; finally json.DisposeOf; usuario.DisposeOf; end; and in class i add called unit usuario function TUsuario.listv(out erro: string): Boolean; var qry : TFDQuery; begin try qry := TFDQuery.Create(nil); qry.Connection := FConn; with qry do begin Active := false; SQL.Clear; SQL.Add('SELECT * from saler WHERE type_store = :any '); ParamByName('any').Value := type_store; Active := true; if RecordCount > 0 then begin id_store := FieldByName('id_store').AsInteger; nom_store := FieldByName('nom_store').AsString; erro := ''; Result := true; end else begin // id_store := 0; erro := 'تعذر جلب بيانات المعلنين'; Result := false; end; DisposeOf; end; except on ex:exception do begin erro := 'خطأ في التحقق من صحة تسجيل الدخول: ' + ex.Message; Result := false; end; end; bandicam_2021-05-01_17-50-29-913.mp4 -
Looking for some help from Delphi community as I'm blocked with my project. I am working with SynchroTeam API using their REST API. SynchroTeam API I can successfully GET and POST data without any problem. But I can't find out the right way to delete a job.. Delete a job After downloading all jobs Object, I'm trying to delete some of them. So, I know ID, MyID and NUM properties of each Job. However, when I'm using the following code: RESTClient:= TRESTClient.Create('https://ws.synchroteam.com/api/v3'); with RESTClient do begin Accept:= 'application/json'; AcceptCharset:= 'UTF-8'; Authenticator:= HTTPBasicAuthenticator; SecureProtocols := [THTTPSecureProtocol.TLS12]; end; RESTRequest.Method:= TRESTRequestMethod.rmDELETE; RESTRequest.Resource:= 'job/delete'; RESTRequest.AddParameter('Content-Type', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); RESTRequest.AddParameter('Accept', 'text/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]); RESTRequest.AddParameter('myId', '467925', TRESTRequestParameterKind.pkQUERY, [poDoNotEncode]); RESTRequest.Execute; I get the error 404: Job does not exists. I'm 100% sur about myId. I also tried with ID property: same result. I also tried with all relevant TRESTRequestParameterKind for myId parameter. I always get 404 What would be the correct way to delete a record using Delphi REST.Client.TRESTRequest ? Thank you for your help