3

I'm working with a networking appliance that has vague API documentation. I'm able to execute PATCH and GET requests fine, but POST isn't working. I receive HTTP status error 422 as a response, I'm missing a field in the JSON request, but I am providing the required fields as specified in the documentation. I have tried the Python Requests module and the vendor-provided PyCurl module in their sample code, but have encountered the same error.

Does the REST API have a debug method that returns the required fields, and its value types, for a specific POST? I'm speaking more of what the template is configured to see in the request (such as JSON {str(ServerName) : int(ServerID)}, not what the API developer may have created.

LampShade
  • 93
  • 2
  • 11
  • 2
    Many servers support the `OPTIONS` method, if that does not work you have to see the docs, if you don't have docs good luck! – Klaus D. Sep 27 '16 at 13:56
  • @KlausD. Thanks for that idea, I have given that a try, but gives me the same information as GET. Still, no luck! – LampShade Sep 27 '16 at 17:13

1 Answers1

1

No this does not exist in general. Some services support an OPTIONS request to the route in question, which should return you documentation about the route. If you are lucky this is machine generated from the same source code that implements the route, so is more accurate than static documentation. However, it may just return a very simple summary, such as which HTTP verbs are supported, which you already know.

Even better, some services may support a machine description of the API using WSDL or WADL, although you probably will only find that if the service also supports XML. This can be better because you will be able to find a library that can parse the description and generate a local object model of the service to use to interact with the API.

However, even if you have OPTIONS or WADL file, the kind of error you are facing could still happen. If the documents are not helping, you probably need to contact the service support team with a demonstration of your problem and request assistance.

Neil Slater
  • 26,512
  • 6
  • 76
  • 94
  • Thanks for that, I gave OPTIONS a try but it gives me the same results as performing a GET. I also tried reformatting the JSON to match what the results were, but still no luck. Does REST (or JSON?) care if the fields are in tuples vs. dictionaries? – LampShade Sep 27 '16 at 17:17
  • 1
    REST and JSON won't care, it depends on your Python JSON library, and how it converts tuples. – Neil Slater Sep 27 '16 at 17:32
  • I haven't been able to get anything working, so I routed the issue to the vendor and specified their Dev team review it and provide feedback, since it seems they'd be the most likely to know how it works. Thanks! – LampShade Sep 27 '16 at 19:54