Add repeated parameter in theTRESTRequest component of Delphi

0

Good afternoon.

I'm developing a class in Delphi using the Ticket API. The class is ready and functional, issuing tickets and generating shipping.

This class consists of the Delphi REST components (THTTPBasicAuthenticator, TRESTResponse, TRESTClient, TRESTRequest), which will be generated dynamically at runtime.

The problem refers to the parameter boleto.instrucao , which in the API can be added repeatedly, thus generating the statement lines.

But checking in my class, it adding only the last one. Debugging the code, I noticed that delphi is omitting repeated parameters.

There is a PHP code from their API documentation that they send this request in array format. But I do not know how to send in array, if the parameter that the TRequest component asks for is string.

Line that adds the parameter:

RSTRequest.AddParameter('....',FPagador.EnderecoComplemento,TRESTRequestParameterKind.pkGETorPOST);
.
.
.
. (mais de 10 parametros)

RSTRequest.AddParameter('boleto.instrucao',FInstrucao1.Text,TRESTRequestParameterKind.pkGETorPOST);
RSTRequest.AddParameter('boleto.instrucao',FInstrucao2.Text,TRESTRequestParameterKind.pkGETorPOST);
RSTRequest.AddParameter('boleto.instrucao',FInstrucao3.Text,TRESTRequestParameterKind.pkGETorPOST);

RSTRequest.Execute;

if RSTResponse.StatusCode <> 201 then
begin
    //erro
end
else
begin
    //sucesso
end;
    
asked by anonymous 10.12.2016 / 18:06

1 answer

2

As the parameter only accepts string , just transform JSON to string .

Then, to include a JSONArray do as follows:

var
    JSArray : TJSONArray;
begin
    JSArray  := TJSONArray.Create;
    try
        JSArray.Add('"Atenção! NÃO RECEBER ESTE BOLETO."');
        JSArray.Add('"Este é apenas um teste utilizando a API Boleto Cloud"');
        JSArray.Add('"Mais info em http://www.boletocloud.com/app/dev/api"');

        RESTRequest.AddParameter('boleto.instrucao',JSArray.ToString,TRESTRequestParameterKind.pkGETorPOST);
    finally
        JSArray.Free;
    end;

Do not forget to declare in uses System.JSON and REST.Types

    
12.12.2016 / 12:40