GithubHelp home page GithubHelp logo

Comments (7)

azz avatar azz commented on August 24, 2024 3

Hi there @lawyerz8! In Windows, curl is actually an alias for Invoke-WebRequest, which has its own syntax for passing headers. You'll want to try something like this:

$creds = 'up:yeah:...'
Invoke-WebRequest 'https://api.up.com.au/api/v1/util/ping' -Headers @{ 'Authorization' = "Bearer $creds" }

You can even try using Invoke-RestMethod, which will give you a nicer output:

$creds = 'up:yeah:...'
Invoke-RestMethod 'https://api.up.com.au/api/v1/util/ping' -Headers @{ 'Authorization' = "Bearer $creds"  }

from api.

deecewan avatar deecewan commented on August 24, 2024 1

also @lawyerz8 - your third screenshot was so close. If you want to go down the curl path, you can:

$headers = @{ "Authorization" = "Bearer up:yeah:...." }
curl "https://api.up.com.au/api/v1/util/ping" -H $headers

But, I agree - Invoke-RestMethod does give a much nicer output 😄

from api.

deecewan avatar deecewan commented on August 24, 2024 1

@lawyerz8 - i might have led you astray there. It seems that in powershell, you can use either ' or " - it doesn't matter. so, all of these work:

curl "https://api.up.com.au/api/v1/util/ping" -H @{ 'Authorization' = 'Bearer up:yeah:....' }
curl 'https://api.up.com.au/api/v1/util/ping' -H @{ "Authorization" = "Bearer up:yeah:...." }
curl 'https://api.up.com.au/api/v1/util/ping' -H @{ 'Authorization' = "Bearer up:yeah:...." }

which is a bit confusing - it's generally recommended to pick one kind and stick with it.

from api.

d11wtq avatar d11wtq commented on August 24, 2024

@lawyerz8 welcome to programming! So good to hear you're rolling up your sleeves and keen to have a go with this. I don't have a good answer for you right now (I'll try and get one... I'm less familiar with Windows). But what I can say is that you definitely don't need to (and should not) prefix a $ sign to the token.

Imagine your token was: up:yeah:xyz123abc (but much longer in reality), then the correct header to send would be:

Authorization: Bearer up:yeah:xyz123abc

from api.

d11wtq avatar d11wtq commented on August 24, 2024

Try taking out that backslash before the -H too. The backslash is just an escaping character to handle a single curl command spanning multiple lines, but given you're supplying it all on one line, it shouldn't be needed (I imagine it will not be causing any problems, as it likely just "skips" the following space character, but remove it nevertheless).

from api.

lawyerz8 avatar lawyerz8 commented on August 24, 2024

Thank you all! You guys are legends. Both queries above work! I'll work my way down the other examples :)

Was very confused about the " as well. Glad to note it is actually part of the query.

Interesting how Invoke-Rest method uses ' but curl/Invoke-WebRequest uses "

from api.

lawyerz8 avatar lawyerz8 commented on August 24, 2024

Oh man I just discovered Postman https://www.postman.com/downloads/ isn't this so much better than CLI haha...

Now i'll try to write it to a database..?

from api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.