How to Insert API data into database using Powershell

  • Hello,

    I am trying to teach myself how to INSERT data from an API into a SQL Server DB using PowerShell.  For this exercise, I am using a public API which is:  What I would like to do is insert this into a table using a Stored Procedure.  Below is my code.  I think I need to create a loop but not sure how to do this, can someone help me complete my code example?


    $Server = "xxxx" 
    $Database = "API_Test"
    $SqlConn = New-Object System.Data.SqlClient.SqlConnection("Server=$Server;Database=$Database;Integrated Security=True;")
    $cmd = $SqlConn.CreateCommand()
    $cmd.CommandType = 'StoredProcedure'
    $cmd.CommandText = '[dbo].[sp_APITest]'

    $pDate = $cmd.Parameters.Add('@date',[datetime])

    $pName = $cmd.Parameters.Add('@Name',[string])

    Invoke-RestMethod -Uri |
    Format-Table -Property Date, Name

    Thank you in advance for any assitance!

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply