Authorization with an API Key POST Request

Hello guys, I am trying to use my api token with POST Request. Here I am attaching it as an authorization in my request header.

Here as a header Value, I entered API KEY:aaaaa, just the api key also but it did not work.

If there is someone who worked with api key before, it would be grateful for me to hear the solution.

Thank you!

Hi @aalpersa , I think people will be able to help if you provide them the link to the API documentation. Perhaps there’s something you’ve overlooked in the doc.

3 Likes

Sure, here is the attaching

Here is the link of documentation: Requesting Access Tokens - Technical Documentation

2 Likes

Okay, hopefully someone will be able to assist you better with that info.

1 Like

Hi @aalpersa , once you generated the token, you can pass it via the headers like you are trying to do.

In the Header value, you need to paste the whole thing from Basic and your token:
“Basic MzjbR3w2fXtEwZ6byr694…”

Your Header key is correct already.

You may need to add the other header keys/values too, such as “Accept-Encoing”, “Content-Length”, and “Content-Type”. It all depends on what the api requires

From the api documentation though, it looks like they’re using Bearer instead of Basic, so please double check this

3 Likes

Unfortunately, It is still not working. Here I am attaching how I use postman to post with my credentials.

That is how my Headers

I added to my request body in POST Request Node as it is shown below,

Here this is my request headers,

In Postman the format is x-www-form-unlercoded, I may need to solve this problem. I entered my request body manually as you can see to solve it, but I am getting 400, 415 errors…

Maybe I am still missing something… :expressionless:

Here the response email from support center,

Could be sth like this with python node

> import requests
> import base64
> 
> # Zalando Merchants API endpoint
> url = "https://api.zalando.com/merchants/"
> 
> # Client ID and Secret
> client_id = "your_client_id"
> client_secret = "your_client_secret"
> 
> # Encode the Client ID and Secret as base64
> auth_string = f"{client_id}:{client_secret}"
> auth_bytes = auth_string.encode("ascii")
> base64_bytes = base64.b64encode(auth_bytes)
> base64_auth = base64_bytes.decode("ascii")
> 
> # Headers including the Authorization header
> headers = {
>     "Authorization": f"Basic {base64_auth}",
>     "Content-Type": "application/json"
> }
> 
> # POST request to the endpoint with the specified headers and payload
> payload = {
>     # add your payload data here
> }
> response = requests.post(url, headers=headers, json=payload)
> 
> # Check the response status code
> if response.status_code == 200:
>     print("Success!")
> else:
>     print(f"Error: {response.status_code} - {response.text}")
1 Like

Some possible solutions around x-www-form-urlencoded are covered in here as well:

2 Likes

Hi @aalpersa the client id and client secret are generally used to generate a token. You then use the token with your api calls.

Are you generating the tokens via api too, or are you generating them via a UI (usually a portal or something similar)?

2 Likes

Hi @bruno29a. Yes I need to generate a token with my credentials via POST Request. Then I will use it with my API Calls :slight_smile:

Hi @Daniel_Weikert, thanks for your advise.

Hi @aalpersa , were you able to make it work in Postman? If you could not, then you will not be able to make it work in Knime.

You need to first understand how to use the API.

Based on what I am reading, and what you showed what you did in Postman, you’re not exactly doing what their instructions are saying for requesting a token.

You should not pass the client id and client secret to the request token api. Instead, what you need to pass is the base64 encoded of the concatenation of client_id:client_secret as Basic Authorization.

I can definitely build a workflow that can send the correct information, but I think you should first understand how to use the api if you are going to use it (that part has nothing to do with Knime. Knime comes after that).

1 Like

Hello @bruno29a. Sure I already did it in Postman with credentials and in python too and works well without problem.

Here I am passing basic authorization, base64 coded format of client credentials that works well with my python code. So I am sure that it is working…

Here passing body parameters;

Where is the mistake that I am making? Could you please tell me?

If you achieved in in python which script did you use? Just curious
KNIME should give you some error message about what the issue is
br

Hi @aalpersa , in your request body, just use plain text like this:
image

No need for JSON.

Your request headers look good, which should contain the Content-Type and Authorization.

Just make sure you are hitting the correct url which should be the auth/token one.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.