0

I am having trouble getting data back when programmatically calling an API. However, when I make the same call manually using Postman I get data back. Here is the code I used to make the call using python.

response = unirest.post(url='my api endpoint',
headers={"Accept": "application/json"}, params={"paramKey": [paramValue]})
print response.body

API call result: {"Success":true,"Message":null,"Data":[]}

  • What is the Status code? And error your getting? – Aravind Nov 29 '16 at 20:33
  • I get status code: 200. Not getting any errors. – NewToAppium Nov 29 '16 at 20:34
  • That's wrong how come u will get 200 for post request? – Aravind Nov 29 '16 at 20:37
  • My understanding is that you get that code back if successful no matter what the http method call is. – NewToAppium Nov 29 '16 at 20:53
  • Have a look at this link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status when you send a data for server to post it should return 201 if the data is inserted And server accepts the data. – Aravind Nov 29 '16 at 20:56
  • Check couple of things on Postman, like the return code you get there, and also if there's additional headers sent out. A full comparative example might help us help you (sent/received both in code and Postman) – sal Nov 29 '16 at 21:05
  • Postman Header: Cache-Control →no-cache Connection →keep-alive Content-Length →449 Content-Type →application/json; charset=utf-8 Date →Tue, 29 Nov 2016 21:07:27 GMT Expires →-1 Pragma →no-cache Server →Microsoft-IIS/8.5 X-AspNet-Version →4.0.30319 X-Powered-By →ASP.NET – NewToAppium Nov 29 '16 at 21:09
  • Code Header: {u'Message': None, u'Data': [], u'Success': True} 200 Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Tue, 29 Nov 2016 21:05:18 GMT Expires: -1 Pragma: no-cache Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 41 Connection: Close – NewToAppium Nov 29 '16 at 21:10
  • I notice a discrepancy in connection. In Postman, connection = keep-alive. In code header, connection = Close – NewToAppium Nov 29 '16 at 21:14

0 Answers0