-1

I would like to retrieve product data using the POST method and pass the security key in the header. I get an HTTP 400 error:

def api(request):
   headers={'content-type':'application/json','security-key': 'valu-key'}
   url = 'http://api-content/product/GetProduct'

   x = requests.post(url, headers = headers)
   content=x.status_code
   return HttpResponse(content)
asynts
  • 2,213
  • 2
  • 21
  • 35
  • 1
    Well we've absolutely no idea what API you're calling or how your code matches what that expects, so it's unclear how you think we could help you with that. – jonrsharpe Sep 12 '22 at 15:01
  • the question needs sufficient code for a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – D.L Sep 12 '22 at 15:07
  • on the API it is at the level of Request body that we put the security key. So how do you implement that then? – TodorossHack Sep 12 '22 at 15:39
  • 1
    Typically the point of a `POST` request is that you're sending data to the server. But that request is sending only headers, not any data... – John Gordon Sep 12 '22 at 18:46

1 Answers1

0

The HTTP 400 status code returned by API may be caused by various causes, depending on how the backend handles the incoming request. (Required header not present, incorrect post data type, incorrect query format etc.)
Maybe you can check with GetProduct's API spec since you only pass security-key header into post method (Spec describes endpoint required header, query, body etc.)

ShiriNmi
  • 39
  • 5
  • on the API it is at the level of Request body that we put the security key. So how do you implement that then? – TodorossHack Sep 12 '22 at 15:39
  • Usually, I'll put a security key in the header named Authorization just like your sample code did, maybe my answer caused your misunderstanding :/. About the origin 400 status code did you try to print out the entire response body and see if anything was passed back by API? – ShiriNmi Sep 13 '22 at 01:19