-2

I am trying to make an autentication from R into a demo account that is using API REST and json.

Based on input from user, I have now digged into the httr and POST details and my code looks like this. When I look into the details it seems that the webclient test i perform is identical but the identfier and password is being sent in with " ". I have checked the documentation for httr, POST and body, but do not find that "" can be used where I need it. Any suggestions?.

POST (
url = "https://demo-api.ig.com/gateway/deal/session", 
add_headers(
"X-IG-API-KEY" = "xxx",
"VERSION" = "2", 
"X-SECURITY-TOKEN" = "xxx", 
"CST" = "xxx", 
"Content-Type" = "application/json; charset=UTF-8", 
"Accept" = "application/json; charset=UTF-8"), 
body = "{identifier: xxx, password: xxx}", 
verbose())
Toolbox
  • 2,333
  • 12
  • 26

1 Answers1

2

Helping you read documentation is out of the scope of SO questions. You made a number of API call mistakes according to the docs and your POST was not formatted properly as well. I'm not really posting this as an answer, per-se, but it's impossible to show a code snippet this large in a comment.

You should also study up on and practice httr calls before attempting something like this in the future.

POST(url="https://demo-api.ig.com/gateway/deal/session",
     encode="json",
     accept_json(),
     add_headers(`X-IG-API-KEY`="[xxx]",
                 `VERSION`="2",
                 `X-SECURITY-TOKEN`="[xxx]"),
     body=list(identifier="[xxx]", 
               password="[xxx]")
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205