4 Replies Latest reply on Nov 7, 2018 12:36 AM by Mohammad Al Taj

    Atrium Integrator Spoon-Rest API

    Mohammad Al Taj

      Hi Experts ,

       

      I need to know how i can call rest API and how i can pass paramiter to API  using atrium integrator spoon ?

       

      Thanks

        • 1. Re: Atrium Integrator Spoon-Rest API
          Peter Lundqvist

          From 9.1.x (I think?) there is a REST Client step. Before that it was possible to use the HTTP Web Client step (I might remember the name wrong).

          Usually I generate the API call in a row and make the step use that.

           

          There is a JSON Input step that can help you extract the response using JSON path. It works just fine most of the time, but sometimes you need to bust out the javascript step to parse it.

           

          There is a lot on this topic if you search the forum

          Like e.g. this:

          Pentaho Spoon and REST Client

          2 of 2 people found this helpful
          • 2. Re: Atrium Integrator Spoon-Rest API
            Mohammad Al Taj

            Thank Mr.Peter, 

             

            I tried to call google API and it working fine without any pass variables, but i think as you mention maybe i need to create javascript step, so please if you have any sample share it with me.

             

            Thanks 

            • 3. Re: Atrium Integrator Spoon-Rest API
              Peter Lundqvist

              Yeah, the documentation on this is maybe not the best even if you look at the pentaho documentation.

               

              First, if you can - use the the JSON input step. This site is a great tool if you need a realtime test for you jsonpath:

              http://jsonpath.com/

               

              If you really need it, use the javascript step.

              You can parse the result field from the rest client using the JSON object:

              var tmp=JSON.parse(result);

               

              If you need to return multiple rows for each input row you can do something like this:

              var tmp=JSON.parse(result);
              var model="";
              var imei="";
              var phone_number="";
              
              if( typeof tmp !== 'undefined' && 'results' in tmp)
              {
                  for (i=0; i < tmp.results.length; ++i)
                  {
                      var nrow=createRowCopy(getOutputRowMeta().size())
                      var jrow = tmp.results[i];
                      var idx = getInputRowMeta().size()
                
                      if( jrow.hasOwnProperty('common_model') )
                          model=jrow.common_model;
                      nrow[idx++] = model;
              
                      if( jrow.hasOwnProperty('common_imei') )
                          imei=jrow.common_imei;
                      nrow[idx++] = imei;
              
                      if( jrow.hasOwnProperty('common_current_phone_number') )
                          phone_number=jrow.common_current_phone_number;
                      nrow[idx++] = phone_number;
              
                      putRow(nrow);
                  }
              }
              else {
                  writeToLog('m', 'Could not parse the JSON object:');
                  writeToLog('m', result);
              }
              
              // Skip forwarding the row that entered this step
              // We have already processed it
              
              trans_Status = SKIP_TRANSFORMATION;
              
              

               

              you would need to add the extracted attributes to the output of the step as well (in the above example model, imei, and phone_number).

               

              Edit: I see I should have added some comments to that code, I add it outside just to make it clear it was added afterwards.

              This line creates a copy of the line that entered the step:

              var nrow=createRowCopy(getOutputRowMeta().size());

               

              This extends nrow with a new field and assign it the value of model:

              nrow[idx++] = model;

               

              This releases the nrow from the step:

              putRow(nrow);

              1 of 1 people found this helpful