So I have the following APi URL: https://.../username/verifytoken
and I have the following function to fetch the APi
def player_verification_token(username, token) do
url = "https://.../#{username}/verifytoken"
with {:ok, %{body: body}} <- Api.post(url, body_should_come_here) do
body
end
end
So the api is a bit tricky, I cannot send the verifytoken into the URL like /username/verifytoken?...
Instead, I have to put it into the BODY of the request. I only know how to do basic headers in HTTPoison, but how can I do that with body?
Did a quick example of using HTTPoison example of the curl request you shared . Its a mix project. Just run iex -S mix in the shell tab and do Httpost.run()
can chk the code here
but most likely what’s really needed (key in header):
def run do
HTTPoison.start()
headers = [{"accept", "application/json"}, {"Authorization", "Bearer #{api_key"}]
body = Jason.encode!(data_to_post)
HTTPoison.post(
"https://httpbin.org/post",
body,
headers
)
end
Nope, not ever, but I did have my fair share of “please POST to this endpoint with actual body and not form data”. HTTP can be weird like that and many companies just rolled with it.