0

I'm totally stuck here. I need to post data to an API with bearer authentification.

I am using the request module in node.js . The request documentation only describes the get method. But I need a "POST".

request.get('http://some.server.com/', {
  'auth': {
    'bearer': 'bearerToken'
  }
});

Something like this (which of course is not working, otherwise I wouldn't post this question):

request.post('http://some.server.com/', {
  'auth': {
    'timeout': 1000,
    'bearer': 'bearerToken',
    'body': '{SomeSerializedJSON}'
  }
});

Any clues?

LongHike
  • 4,016
  • 4
  • 37
  • 76

1 Answers1

0

We need some more informations here !

Did you already sign in and have your bearer token ?

Moreover if there is no POST method in your targeted API you won't be able to use POST, you have to use the GET method implemented by their developers because this is how they want to receive the data.

And finally I will say that you may not need POST method, GET and POST can both transmit data to your API, the way of doing it is just different (HTTP Methods GET vs POST by w3c).

Tiekeo
  • 1
  • 2
  • I apologize for not being sufficiently specific. – LongHike Dec 30 '15 at 09:12
  • I apologize for not being sufficiently specific. First of all, the API is (supposedly) fully REST-compliant. I can retrieve data with that bearer token. I should have mentioned that. Again, I am sorry for omitting this bit. The documentation for the API requires a POST method, when creating a new record/item. I believe I do understand the differences of http verbs. Really, at this point, I need to be able to execute a POST. This is how this particular API (and many REST-APIs I've been working with so far) works when it comes to create a new record/item. – LongHike Dec 30 '15 at 09:23
  • Then you should consider this topic : http://stackoverflow.com/a/6158966/5726514 My first thought is that your 'body' should not be inside 'auth' and then i usually work with API that need more informations like : '' 'Content-Type': 'application/x-www-form-urlencoded' " or " 'Content-Type': 'application/json' " in the header of your HTTP request. Is there any other POST request documented of this API ? If yes, then just try to do it the same way but replacing url and body content. – Tiekeo Dec 30 '15 at 10:11