Retrieving bearer token from API and use it to get data from the same API

Our team is struggling with communication with an API that we have made. I have tested the API using POSTMAN and everything seems to work fine.

In POSTMAN I use a post request with Content-Type: application/x-www-form-urlencoded and
Body: username and password.

In Appfarm it looks like this:

Where the text inside the URL is: return apApiUrl + token

Inside the request header:

The text inside body content is:
const body = username=${encodeURIComponent(APIUsername)}&password=${encodeURIComponent(APIPassword)};

return body

I have been experimenting with a lot of different ways to form the body content, different body types and content types.

I have tried to run this as a service which returns the code 204 - no content. And I have tried to run this with the other endpoint which contains results:

Which again gives the same code 204. I imagine that I have to actually get a response from the token web request first for the second web request to return something as well.

Could anyone help with this? I have been stuck with this for over a week. If I have forgotten to provide additional information that you need to help me I can do that as well

Thank you!

Hi Robin,

Try to change the body type of your web request to URL-encoded and send in your username and password there. Then you won’t have to set up any request header either. There might also be a chance that you have a typo somewhere, so double-check that you have typed everything correctly.

Hope this helps, and let me know if the problem persists!