2 Replies Latest reply: Jan 21, 2017 8:04 AM by Claudio Reis RSS

    Connection REST Post with request body

    Claudio Reis

      Hello!

       

      How to change request body in JSON script on WITH CONNECTION to read any pages? I'm using method POST with request body.

       

      My actual scenario is: on my string I can only pull twenty registries per page but I need to increment a loop to get all the others registries.

       

      Thanks.

        • Re: Connection REST Post with request body
          Gleybson Fernandes

          Hello Cláudio

           

          I'm having the exact same problem. Did you have any luck with that ? If so, could you share the solution ?

           

          Thanks

            • Re: Connection REST Post with request body
              Claudio Reis

              Hello, Gleybson


              I solved ... follow instructions below:


              1. Create a REST connection.


              Imagem_1.png


              2. Write the script below:


              LIB CONNECT TO 'Categoria';

               

              Config:

              SQL SELECT

                "total_de_paginas"

              FROM JSON (wrap on) "root" PK "__KEY_root"

              WITH CONNECTION(Url "http://XXXXXX/categorias/");

               

              Let total = Peek('total_de_paginas',0,'Config');

               

              Let totalfetched = 0;

              let vPagina = 1;

               

              for startAt = 1 to total

               

              let vRequestBody = '{"call":"ListarCategorias","app_key":"XXXXXXXX","app_secret":"XXXXXXXXXX","param":[{"pagina":"$(vPagina)","registros_por_pagina":100,"apenas_importado_api":"N"}]}';

               

              let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));

               

              RestConnectorMasterTable:

              SQL SELECT

                "__KEY_root",

                (SELECT

                "codigo",

                "conta_despesa",

                "conta_inativa",

                "conta_receita",

                "definida_pelo_usuario",

                "descricao",

                "descricao_padrao",

                "id_conta_contabil",

                "nao_exibir",

                "natureza",

                "tag_conta_contabil",

                "totalizadora",

                "transferencia",

                "__FK_categoria_cadastro"

                FROM "categoria_cadastro" FK "__FK_categoria_cadastro")

              FROM JSON (wrap on) "root" PK "__KEY_root"

              WITH CONNECTION(Url "http://XXXXXX/categorias/", BODY "$(vRequestBody)");

               

              vPagina = vPagina + 1;

               

              NEXT startAt;

               

              Categorias:

              LOAD

                [codigo] AS [codigo],

                [conta_despesa] AS [conta_despesa],

                [conta_inativa] AS [conta_inativa],

                [conta_receita] AS [conta_receita],

                [definida_pelo_usuario] AS [definida_pelo_usuario],

                  [descricao] AS [descricao],

                  [descricao_padrao] AS [descricao_padrao],

                [id_conta_contabil] AS [id_conta_contabil],

                [nao_exibir] AS [nao_exibir],

                [natureza] AS [natureza],

                [tag_conta_contabil] AS [tag_conta_contabil],

                [totalizadora] AS [totalizadora],

                [transferencia] AS [transferencia],

                [__FK_categoria_cadastro] AS [__KEY_root]

              RESIDENT RestConnectorMasterTable

              WHERE NOT IsNull([__FK_categoria_cadastro]);

               

              DROP TABLE RestConnectorMasterTable;