Announcement

  •  » Extensions
  •  » API not responding as expected

#1 2016-12-18 19:23:03

Riley
Guest

API not responding as expected

Hello/Hi/Greetings,

I'm having some trouble trying to POST to a Piwigo installation (I'm just trying to log in currently). I've tried a few different methods, from a Python library, to CURL in Bash, to a Chrome app called Postman. No matter what, I keep getting this response back:

{"stat":"fail","err":501,"message":"Missing \"method\" name"}

This is on my own installation as well as the example one (URL listed below). For instance when posting thusly:

POST http://piwigo.org/demo/ws.php?format=json
Headers:
  Content-Type: application/json
Data:
  {"username":"somerandomstring","password":"someotherrandomstring"}

I don't understand what I'm doing wrong. Especially  because if I go here to test it works fine:

  http://piwigo.org/demo/tools/ws.htm#top

(using pwg.session.login).

I'd like to point out that I'm no developer by a stretch, but I have written python scripts in the past that do interface with APIs, and I'm just stuck and frustrated. Not sure what  I'm doing wrong. Any help appreciated!

 

#2 2016-12-19 14:58:10

rvelices
Former Piwigo Team
2005-12-29
1960

Re: API not responding as expected

You cannot post using json. You must post form url encoded; you can only specify the output format.

Offline

 

#3 2016-12-20 11:28:47

Riley
Guest

Re: API not responding as expected

Thank you. I'm not extremely experienced in dealing with APIs and manually making http requests so some things that may be obvious to others are not yet obvious to me :)

Based on what you said I used this header instead:

content-type: application/x-www-form-urlencoded

But it still keeps failing with the same response as before. I only assume I am missing some simple thing with the way I am setting the header. Any idea what that is?

 

#4 2016-12-20 11:42:59

Riley
Guest

Re: API not responding as expected

I just noticed that if I use a url such as:

http://piwigo.org/demo/ws.php?format=js … ndomstring

Then the server responds saying the method name is invalid. Maybe I'm getting closer. I tried:

http://piwigo.org/demo/ws.php?format=js … sion.login

But the server responded by saying:

405 This method requires HTTP POST

But I had POSTed. I'm confused. This method parameter wasn't brought up in Piwigo's API Explorer, but it seems it might be a key...

 

#5 2016-12-21 18:57:11

rvelices
Former Piwigo Team
2005-12-29
1960

Re: API not responding as expected

If the tools/ws.htm works fine, then it's a problem because you didn't POST.

Offline

 

#6 2016-12-22 18:38:32

Riley
Guest

Re: API not responding as expected

I was posting, but I think I found the problem. The form data needed to include a 'username' and 'password' of course, but also a 'method' needed to be sent in the form as well. The method in this case was 'pwg.session.login'.

 

#7 2019-12-18 10:13:55

Kees Kemper
Member
2019-12-18
1

Re: API not responding as expected

I have the same issue.
What is the solution?

Offline

 
  •  » Extensions
  •  » API not responding as expected

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact