Using the REST API with POST method (in Python)

Hi,

I’m sorry to post with what I think is a simple problem, but I’ve read the API documentation, etc, and I cannot see where I’ve gone wrong!

I am writing in Python and trying to send a message using the REST API. I have the following code:

The GET works fine - it returns all my information, so I knmow my API key is correct.
The POST returns: {“success”:false,“error”:“Not logged in”}

Can someone tell me what I am doing wrong?

Thanks!

The apikey doesn’t go in the headers like that. You can put it in the url or in the actual payload or use HTTP Basic Authentication (recommended method)

Here’s the section on authentication:

Thanks for your very quick reply! Yes, I’ve read and re-read that section many times!
It does sort of infer that it goes in the header, doesn’t it? It says for the GET method, you can use apikey or replace it by base64 coded Authorization (I tried that too!).
Then it shows the POST method with base64 coded Authorization in the header! So that is why I am confused.

Anyway, I’ve tried to follow your suggestion. Is this what you meant?

I got the following response: {“success”:false,“error”:“Required fields ‘data’, or ‘base64data’ missing”}

What am I doing wrong? Thanks for your help!

That’s a good sign. It means that you’re authenticated and just need to fill in some extra fields. Add data field to the payload and it should work

If you do want to use HTTP basic authentication there’s a super simple way to do it with the requests library here: Authentication — Requests 2.28.2 documentation
It’ll take care of the encoding for you

Actually it looks like if you just rename body to data in your payload you’ll be good

Ah, at last. I see my mistake! I have “body” written above rather than “data”. Oh dear…

Oops… I see you’ve discovered that mistake too.

Thanks for yiour help!

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