How to Construct a URL for Webservices using variable parameters












0















I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.



My application will pass 2 parameters to the URL, namely date, and Staff.ID. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.



Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID. I have tried constructing the URL by using declare statements and the parameters but did not work.



The script:



DECLARE @response NVARCHAR(max);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
@response OUTPUT;
BEGIN
--Insert into Schedules
--(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response) ;
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY
OpenJson(Blocks)
WITH
(StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END;
go









share|improve this question





























    0















    I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.



    My application will pass 2 parameters to the URL, namely date, and Staff.ID. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.



    Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID. I have tried constructing the URL by using declare statements and the parameters but did not work.



    The script:



    DECLARE @response NVARCHAR(max);
    --get the data from the provider as JSON
    EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
    @response OUTPUT;
    BEGIN
    --Insert into Schedules
    --(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
    Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
    FROM OpenJson(@response) ;
    with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
    OUTER APPLY
    OpenJson(Blocks)
    WITH
    (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
    END;
    go









    share|improve this question



























      0












      0








      0








      I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.



      My application will pass 2 parameters to the URL, namely date, and Staff.ID. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.



      Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID. I have tried constructing the URL by using declare statements and the parameters but did not work.



      The script:



      DECLARE @response NVARCHAR(max);
      --get the data from the provider as JSON
      EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
      @response OUTPUT;
      BEGIN
      --Insert into Schedules
      --(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
      Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
      FROM OpenJson(@response) ;
      with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
      OUTER APPLY
      OpenJson(Blocks)
      WITH
      (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
      END;
      go









      share|improve this question
















      I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.



      My application will pass 2 parameters to the URL, namely date, and Staff.ID. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.



      Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID. I have tried constructing the URL by using declare statements and the parameters but did not work.



      The script:



      DECLARE @response NVARCHAR(max);
      --get the data from the provider as JSON
      EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
      @response OUTPUT;
      BEGIN
      --Insert into Schedules
      --(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
      Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
      FROM OpenJson(@response) ;
      with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
      OUTER APPLY
      OpenJson(Blocks)
      WITH
      (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
      END;
      go






      sql sql-server tsql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 23:25









      Makyen

      20.5k83971




      20.5k83971










      asked Nov 22 '18 at 22:10









      PaulBPaulB

      61




      61
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I've assumed your query all works, and I've just encapsulated it within a SP:



          create procedure dbo.MyProcedureName
          (
          @Date date
          , @StaffId int
          )
          as
          begin
          DECLARE @response NVARCHAR(max), @Url varchar(max);

          set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);

          --get the data from the provider as JSON
          EXECUTE dbo.GetWebService @Url, @response OUTPUT;

          --insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
          select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
          FROM OpenJson(@response);
          with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
          OUTER APPLY OpenJson(Blocks)
          WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
          END
          go





          share|improve this answer
























          • Dale,Works perfectly thank you.Paul

            – PaulB
            Nov 22 '18 at 23:17











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438511%2fhow-to-construct-a-url-for-webservices-using-variable-parameters%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I've assumed your query all works, and I've just encapsulated it within a SP:



          create procedure dbo.MyProcedureName
          (
          @Date date
          , @StaffId int
          )
          as
          begin
          DECLARE @response NVARCHAR(max), @Url varchar(max);

          set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);

          --get the data from the provider as JSON
          EXECUTE dbo.GetWebService @Url, @response OUTPUT;

          --insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
          select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
          FROM OpenJson(@response);
          with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
          OUTER APPLY OpenJson(Blocks)
          WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
          END
          go





          share|improve this answer
























          • Dale,Works perfectly thank you.Paul

            – PaulB
            Nov 22 '18 at 23:17
















          0














          I've assumed your query all works, and I've just encapsulated it within a SP:



          create procedure dbo.MyProcedureName
          (
          @Date date
          , @StaffId int
          )
          as
          begin
          DECLARE @response NVARCHAR(max), @Url varchar(max);

          set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);

          --get the data from the provider as JSON
          EXECUTE dbo.GetWebService @Url, @response OUTPUT;

          --insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
          select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
          FROM OpenJson(@response);
          with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
          OUTER APPLY OpenJson(Blocks)
          WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
          END
          go





          share|improve this answer
























          • Dale,Works perfectly thank you.Paul

            – PaulB
            Nov 22 '18 at 23:17














          0












          0








          0







          I've assumed your query all works, and I've just encapsulated it within a SP:



          create procedure dbo.MyProcedureName
          (
          @Date date
          , @StaffId int
          )
          as
          begin
          DECLARE @response NVARCHAR(max), @Url varchar(max);

          set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);

          --get the data from the provider as JSON
          EXECUTE dbo.GetWebService @Url, @response OUTPUT;

          --insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
          select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
          FROM OpenJson(@response);
          with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
          OUTER APPLY OpenJson(Blocks)
          WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
          END
          go





          share|improve this answer













          I've assumed your query all works, and I've just encapsulated it within a SP:



          create procedure dbo.MyProcedureName
          (
          @Date date
          , @StaffId int
          )
          as
          begin
          DECLARE @response NVARCHAR(max), @Url varchar(max);

          set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);

          --get the data from the provider as JSON
          EXECUTE dbo.GetWebService @Url, @response OUTPUT;

          --insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
          select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
          FROM OpenJson(@response);
          with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
          OUTER APPLY OpenJson(Blocks)
          WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
          END
          go






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 22:19









          Dale BurrellDale Burrell

          3,10032351




          3,10032351













          • Dale,Works perfectly thank you.Paul

            – PaulB
            Nov 22 '18 at 23:17



















          • Dale,Works perfectly thank you.Paul

            – PaulB
            Nov 22 '18 at 23:17

















          Dale,Works perfectly thank you.Paul

          – PaulB
          Nov 22 '18 at 23:17





          Dale,Works perfectly thank you.Paul

          – PaulB
          Nov 22 '18 at 23:17


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438511%2fhow-to-construct-a-url-for-webservices-using-variable-parameters%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'