Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue an invoice, PATCH method #633

Open
jeromecc opened this issue Feb 1, 2019 · 1 comment
Open

Issue an invoice, PATCH method #633

jeromecc opened this issue Feb 1, 2019 · 1 comment

Comments

@jeromecc
Copy link
Contributor

jeromecc commented Feb 1, 2019

Hello!

I am using django-silver version 0.7.0 installed through pip with Django 1.11, Python 2.7, djangorestframework version: 3.8.2

I am testing invoice creation through the API. I can create invoices without any problem (when adding appropriate currency related fields ;-) using httpie.

When I try to issue an invoice using the PATCH method indicated in the documentation, I get a 450 Method Not Allowed error:

(testcopper) user@debian:$ http --auth login:password PATCH http://127.0.0.1:8008/silver/invoices/5/state/ @issue1.json
HTTP/1.0 405 Method Not Allowed
Allow: PUT, OPTIONS
Content-Length: 42
Content-Type: application/json
Date: Fri, 01 Feb 2019 07:25:15 GMT
Server: WSGIServer/0.1 Python/2.7.15+
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
"detail": "Method "PATCH" not allowed."
}

When I use the PUT method, it works:

(testcopper) user@debian:~/dev/python/django/test-copper$ http --auth login:password PUT http://127.0.0.1:8008/silver/invoices/5/state/ @issue1.json
HTTP/1.0 200 OK
Allow: PUT, OPTIONS
Content-Length: 1837
Content-Type: application/json
Date: Fri, 01 Feb 2019 07:52:38 GMT
Server: WSGIServer/0.1 Python/2.7.15+
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
...
"id": 5,
...
"state": "issued",
...
}

I am relatively new to Django & I don't know much about DRF. Is it a documentation problem? Am I missing something?

Thanks.
jérôme

@bogdanpetrea
Copy link
Contributor

This is indeed an old and weird part of the API.
You can view the code here and indeed only PUT is allowed in code.

I think the logic behind it was that you create a transition (request), you don't just patch the state field.

The endpoint should've been somewhat similar to the newer payment method endpoint where the cancel transition has it's own endpoint and you send POST requests.

It might be worth reworking the transition endpoints for documents. The subscription ones look OK at a glance.

Regarding the docs, having them statically written means at some point they will no longer be in sync with the actual API. We were using Django Swagger at some point to generate the API docs, but I don't really remember what happened to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants