2

My team and I our trying to get a cUrl request transcribed to vbscirpt (or csharp) so we can use it in an SSIS script Task to import the file into sql server 2014. We've tried postman, fiddler, and every other platform to try and get some sample code working. Following is the cUrl Statment:

set ID=80
set BeginDate=2019-01-01
set EndDate=2020-01-01
set APIKey=myAPIKey
set OutputPath=C:\Desktop\Output.json

curl https://Api.com/services/SomeReport/%ID%?q=report_begin_date=%BeginDate%:%EndDate% -u %APIKey%: > %OutputPath%e

The thing that seems to kill it every time is the authorization portion. There are examples of cUrl to vbscript, but they don't deal with authorization.

Does anybody have any ideas?

user692942
  • 16,398
  • 7
  • 76
  • 175
Chris
  • 265
  • 2
  • 16
  • Possible duplicate of [CURL request in classic ASP](https://stackoverflow.com/questions/46856852/curl-request-in-classic-asp) *(also applies to VBScript)*. – user692942 Nov 29 '19 at 00:28
  • Is this a VBScript question or not? If it isn’t, please [edit] the question because the current accepted answer makes no sense in relation to VBScript. – user692942 Dec 05 '19 at 22:52
  • 1
    The core solution to the authorization issue in in the first line of the accepted answer. The example is just that, an example/guide, don't get too hung up on vbscript that you miss the question and need. To provide an SSIS compatible example vbscript (or cscript) to replicate the authorization used by curl. – vhoang Dec 06 '19 at 05:21

1 Answers1

0

The -u options of curl adds a "basic" Authorization header.

The equivalent of "-u %APIKey%:" using a HttpWebRequest (C#) would be in the neighborhood of:

...
string username = myAPIKey;
string password = "";
string auth64 = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password));

request.Headers.Add("Authorization", "Basic " + auth64);
...
vhoang
  • 1,349
  • 1
  • 8
  • 9
  • It doesn't appear System.Text{} is available in ssis. Anyway to get around ASCIIEncoding.ASCII.GetBytes? – Chris Nov 28 '19 at 18:22
  • 1
    Should be there. open up #region Namespaces at the top of the task and add "using System.Text;". GetBytes converts a string to a byte array. You're free to replace it with something else (UTF8Encoding, etc, still in System.Text) or roll your own function but i recommend against that. – vhoang Nov 28 '19 at 18:40
  • I tried to add the reference already. It doesn't exist for some reason in SSIS. Reference list goes from System.Speech to System.Transactions – Chris Nov 28 '19 at 18:48
  • That's expected. You don't need to add it as a reference. It's part of System. The "using" in namespaces is just to keep from having to typing out "System.Text". You can use it this way also System.Text.ASCIIEncoding.ASCII.GetBytes(). – vhoang Nov 28 '19 at 19:01
  • 1
    This is not a VBScript solution, in fact it looks more like .Net using C#. How can you accept this as an answer? @Chris you’re either using VBScript in SSIS or your not, either way correct the question to match the answer or un-accept the answer because it makes no sense in the questions current context. – user692942 Dec 05 '19 at 22:50
  • Q: "(or csharp)". anyways, updated to avoid ambiguity. – vhoang Dec 06 '19 at 05:03
  • Lankymart -- You are correct. I do both languages and just went with the C sharp solution as SSIS will allow either. I've fixed the tag. – Chris Dec 07 '19 at 17:42
  • Do you _really_ need to do this in SSIS? SSIS is good at data but bad at web services. – Nick.Mc Oct 19 '20 at 10:16