How to make API Request in SQL Server | Pt. 1

Поделиться
HTML-код
  • Опубликовано: 11 дек 2024

Комментарии • 58

  • @DrayWilliams
    @DrayWilliams 4 года назад +8

    For anybody troubleshooting possible NULL values in the table while using the Basic authentication authHeader, change the setRequestHeader value from 'Authentication' to 'Authorization'. Also, adjust the DECLARE value for authHeader NVARCHAR from (64) to something bigger. Only realized that from testing in Postman and it worked for me.

    • @ProgenysEnd
      @ProgenysEnd 4 года назад

      Absolute lifesaver.

    • @SMTechSoft
      @SMTechSoft Месяц назад

      can you please give me an example of calling the API with these values, this is for my stock brokerage to place orders.
      App Key
      App Secret
      Callback URL
      Access Token
      Refresh Token
      Id Token
      Below is the order
      {
      "orderType": "MARKET",
      "session": "NORMAL",
      "duration": "DAY",
      "orderStrategyType": "SINGLE",
      "orderLegCollection": [
      {
      "instruction": "BUY",
      "quantity": 1,
      "instrument": {
      "symbol": "SPY",
      "assetType": "EQUITY"
      }
      }
      ]
      }

  • @joestocker660
    @joestocker660 2 года назад

    Awesome! I was looking for something to update sales tax info, from a state API. Had no idea I could contain it all in SQL Server. I can parse what I need from the results. Thanks so much!

  • @CurtTreece
    @CurtTreece 4 года назад +1

    FYI, you don't need to select the text in order to execute the entire script. Just make sure nothing is selected and click the "Execute" button. It will run the entire script.

  • @patiurco
    @patiurco 2 года назад

    Dudee what a great explanation, simply awesome thank you so much for sharing this at this detailed level. Greetings from México and sorry for my english

  • @houstonfirefox
    @houstonfirefox 4 года назад +1

    @Sigma Coding Great video. Concise and very well explained. Was able to modify your examples to build out a set of OAuth 2.0 stored procedures to interact with 3rd party vendors outside of our organization. With everything moving to the 'cloud', this seems to be the future with regard to data interchanges. I've noticed more and more vendors moving from older methods to OAuth 2.0. Keep up the great work!

    • @GP3_907
      @GP3_907 2 года назад

      Was that easy for you

    • @houstonfirefox
      @houstonfirefox 2 года назад

      @@GP3_907 Dealing with APIs is never easy getting started, especially when dealing with 'token timeouts' and all that mess. Our shop gets around that by simply requesting a new token when the job starts regardless of how old the 'old' token was. It simplified us having to worry about if a token is about to expire or not since a new one will always last Way beyond however long a job will take. Once you get the hang of it then it's pretty easy to deal with. Parsing the resulting JSON from many different vendors on the other hand can be a pain in the behind deciphering their layouts.

    • @MarijnTF
      @MarijnTF 2 года назад

      @@houstonfirefox Hi there, I'm struggling to set up an OAuth2.0 connection. Could you by any chance share some of your wisdom? Would really help me out!

    • @houstonfirefox
      @houstonfirefox 2 года назад

      @@MarijnTF The process usually follows the same steps. Using either a username or password, or a token given to you from the provider, authenticate with the API and get a bearer token to use during any subsequent calls. If you are new to this then I recommend practicing with Python or some other language until you are comfortable, then bringing that knowledge over to SQL Server and replicating it in a stored procedure. Every API provider is different so you'll have to weave and bob around the way the provider chose to implement it. I would start off locating the API documentation they should have available and following the examples they hopefully provided.

  • @Juan-Hdez
    @Juan-Hdez Год назад

    Very useful. Thank you!

  • @karlbasson6695
    @karlbasson6695 2 года назад

    Thank you for the help! Good video.

  • @maethebae8202
    @maethebae8202 3 года назад +1

    I get null values. When I exclude the insert to json part, the result is unable to open http connection.

  • @ReverendHogwash
    @ReverendHogwash 3 года назад +2

    Great for a one time import of API data, but what if the data in that API is updated multiple times per day - how does one make sure the date in SQL is syncd with the latest data?

    • @nmarks
      @nmarks 3 года назад +2

      You would need to schedule a job:
      docs.microsoft.com/en-us/sql/ssms/agent/schedule-a-job?redirectedfrom=MSDN&view=sql-server-ver15

  • @seangillespie4601
    @seangillespie4601 2 года назад

    Awesome video man, I kept returning NULL and spinning my wheels, your workaround changed the game for me! Do you have any videos on doing this with CSV instead of JSON?

  • @dmikester1
    @dmikester1 2 года назад

    Are the two 'sp_configure' calls at the top temporary that only happen in the context of this query? Or does that change the database going forward? Would I need to revert them back after I am done?

  • @premkumardr
    @premkumardr 3 года назад

    Thank you. How do send a response to the request. For example, customer_id request response will be first name, last name and other in JSON format.

  • @skerdilajdshtylla7263
    @skerdilajdshtylla7263 2 года назад

    Hello! I want to update multiple rows with where clause! The data that i want to update, i get it from excel. How to get a lot of o data from excel? Is there any method i can copy them all at the same time in sql server and not getting them one by one with copy command??

  • @werneralonzo1230
    @werneralonzo1230 3 года назад

    greate tutorial dude!! thanks..

  • @ernestmedina2448
    @ernestmedina2448 11 месяцев назад

    Greate Video only thing is that you probably should make the @apiKey bigger nvarchar(32) may not be enough. Also the @json is going to be blank or NULL because where it says: EXEC @ret = sp_OACreate 'MSXML.XMLHTTP' , @token OUT; should be: EXEC @ret = sp_OACreate 'MSXML2.XMLHTTP' , @token OUT; the 2 is missing.

  • @rachelsurendra
    @rachelsurendra 4 года назад

    Thanks for the video.. I have to access an API from SQL server, this has three header values. I get an error ' Invalid number of parameters.' Do i have to concatenate it to one and set the request header?

  • @madhavareddy3488
    @madhavareddy3488 2 года назад

    I built the request successfully, on 'Send' I have below error.
    Please help to fix! Let me pls know in case of addl info.
    A certificate is required to complete client authentication

  • @SMTechSoft
    @SMTechSoft Месяц назад +1

    @Sigma Coding can you please give me an example of calling the API with these values, this is for my stock brokerage to place orders.
    App Key
    App Secret
    Callback URL
    Access Token
    Refresh Token
    Id Token
    Below is the order
    {
    "orderType": "MARKET",
    "session": "NORMAL",
    "duration": "DAY",
    "orderStrategyType": "SINGLE",
    "orderLegCollection": [
    {
    "instruction": "BUY",
    "quantity": 1,
    "instrument": {
    "symbol": "SPY",
    "assetType": "EQUITY"
    }
    }
    ]
    }

  • @sanjoyroy
    @sanjoyroy 4 года назад

    Would you kindly share the previous video link? I just came to page first. Thanks.

  • @danielrobertson9747
    @danielrobertson9747 4 года назад

    Really good video, thank you

  • @evemarenghi690
    @evemarenghi690 4 года назад +1

    Thanks for the video! Super helpful. I followed your instructions exactly, I'm not getting any errors but when I select from @json it's empty. I checked and my URL is functional. Any recommendations for how to troubleshoot?

    • @ryanmorse5470
      @ryanmorse5470 4 года назад

      Same thing happened to me. Did you figure this one out?

    • @user-jk6jo1pu3j
      @user-jk6jo1pu3j 4 года назад

      not from this video but I was calling the Open Weather API specifically so I used this - maybe it can help you. github.com/JosephMagiya/Weather-Data-and-Forecasts-from-Open-Weather-API/blob/master/Weather_API%20(Current%20%2B%20Forecast).ipynb

  • @nandinisharma2340
    @nandinisharma2340 3 года назад

    wow! thanks!

  • @marcosoliveira8731
    @marcosoliveira8731 4 года назад

    Learned new stuff here!
    100th like

  • @ajitheshgupta3017
    @ajitheshgupta3017 3 года назад

    Can somone point to create a post request in SP

  • @sameerunawane
    @sameerunawane Год назад

    can we make SSIS package of this script. if yes then how?

  • @bobsnijders4182
    @bobsnijders4182 4 года назад +4

    Playback speed 1.25 :)

  • @cristianmene
    @cristianmene 4 года назад

    How could I do it with the cURL command?

  • @TechandArt
    @TechandArt 4 года назад

    Grt learning

  • @karangupta4518
    @karangupta4518 3 года назад

    Thank sir

  • @patolobos8266
    @patolobos8266 4 года назад

    Can you create a store procedure or a SSIS package so it can run every night? I did not work for me, the code and parsing work perfect, can insert, select a perfect table, but it fails in SSIS or the SQL agent...

    • @houstonfirefox
      @houstonfirefox 4 года назад

      @pato lobos Consider placing your code in a stored procedure and scheduling an agent job to call it every night. Make sure that the SQL Server Agent service is set to startup automatically and is indeed running.

  • @herrieeffendi7748
    @herrieeffendi7748 4 года назад

    Hi, I've tried to follow your script, but I still failed to put existing file with json file, Can I see your result script for SELECT api_key FROM [SigmaCodingDatabase].[dbo].[API_Services] WHERE service_name = 'Alpha Vantage' ? Thanks

    • @SigmaCoding
      @SigmaCoding  4 года назад +1

      That just returns my API key, so I can't share the actual result with you.

  • @busiyatdah
    @busiyatdah 3 года назад

    thanks bro

  • @karangupta4518
    @karangupta4518 3 года назад

    Thanku sir

  • @riddhipatel3104
    @riddhipatel3104 4 года назад

    I created loop as I need multiple json extract based on key. after 500 Calls I am getting Unable to open HTTP connection. Looks like I am getting error after exact 512 calls. How can I fix that?

    • @houstonfirefox
      @houstonfirefox 4 года назад

      @riddhi patel it sounds like your API service provider has a "cap" on the number of calls within a certain time period. Read the API documentation or get in contact with them to determine if this is the case. Many data providers will put a cap in place based on subscription level or to prevent their systems being monopolized by a single customer.

    • @riddhipatel3104
      @riddhipatel3104 4 года назад

      I don't think its restriction issue source as as soon as I disconnect session and restart new session I am again able to call 512 records. Is there a way disconnect session automatically after 512 calls?

    • @houstonfirefox
      @houstonfirefox 4 года назад

      @@riddhipatel3104 Another possibility is 'pagination' where the API provider limits a single request to a fixed number of records. They do this to prevent people from requesting multi-million row recordsets in one call and overwhelming the resource server. Think of it as providing recordsets in 'chunks' of 512 records, then requesting the next set of 512 records. How the resource provider does this is usually covered in their documentation. Let us know what you find.

  • @alpinestone1
    @alpinestone1 4 года назад

    Hello, It does not work with bearer token, please advice

    • @houstonfirefox
      @houstonfirefox 4 года назад

      @Rahul Girl Ensure your variable holding the token is long enough to hold the entire token. I have seen cases where the variable was declared too small and only part of the token was being sent.

  • @patolobos8266
    @patolobos8266 4 года назад

    I have a problem parsing, I just can't get it ... I have post it the issue here... any tips? stackoverflow.com/questions/62223028/parse-json-in-microsoft-sql

    • @patolobos8266
      @patolobos8266 4 года назад

      Solved! Thanks and to @kane from Stackoverflow!

  • @mallikarjuna1235
    @mallikarjuna1235 2 года назад

    Can you please share me theoretical documents

  • @ponkyzw
    @ponkyzw 4 года назад +1

    I have an API that uses Basic Authentication and a body to POST to the API , how do I do the connection for this?

    • @ponkyzw
      @ponkyzw 4 года назад +1

      Sorry I need to read the data from API to SQL server. I need to use basic Authentication with body content.

    • @paulstanitzek
      @paulstanitzek 4 года назад

      @@ponkyzw I've got the same problem have you found a solution already? Thank you in advance!