Bad request when performing a POST API query using webwrite
up vote
1
down vote
favorite
I'm attempting to create an App that exchanges information with an api (Questrade API to be precise). The api uses oauth2 for security and authentication.
I have been successful1 in acquiring authorization tokens, refresh tokens and querying basic information (my account information and stock quotes).
However, I'm encountering an issue when I try to query stock option quotes (as described here).
I've tried many different permutations but to no avail. This is what I've done so far:
1). I've taken the example shown in the "Sample Request" section provided in the link above and performed jsondecode
to get the MATLAB equivalent and the "exact template" for which the parameter structure must be coded:
>> eg_param = jsondecode('{"filters":{"optionType":"Call","underlyingId":27426,"expiryDate":"2017-01-20T00:00:00.000000-05:00","minstrikePrice":70,"maxstrikePrice":80},"optionIds":[9907637, 9907638]}')
eg_param =
struct with fields:
filters: [1×1 struct]
optionIds: [2×1 double]
>> eg_param.filters
ans =
struct with fields:
optionType: 'Call'
underlyingId: 27426
expiryDate: '2017-01-20T00:00:00.000000-05:00'
minstrikePrice: 70
maxstrikePrice: 80
>> eg_param.optionIds
ans =
9907637
9907638
2). Substituted my actual values (real_params
) for those in the example:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
3). Changed weboptions
' RequestMethod
paramater to post
web_opt.RequestMethod = 'Post';
4). Used the webwrite
function, as opposed to 'webread' to post and query the server:
new_data = webwrite(['https://api01.iq.questrade.com/',...
'v1/markets/quotes/options'], real_params, web_opt);
However, when I do this, is get the error message:
*The server returned the status 400 with
message "Bad Request" in response to the
request to URL
https://api01.iq.questrade.com/v1/markets/quotes/options.*
I've tried many different permutations including changing brackets, , {},{{}} and using different values for the parameters however the result is the same. Also, whenever I tested, I made sure to refresh the access token and test that the connection works using the "account info" request, so this error doesn't have to do with any authorization, security or connection issue.
1 For example, to acquire account information, which the website instructs as:
GET https://api01.iq.questrade.com/v1/accounts
I've 1). used MATLAB's weboptions
and created an object to store token information in HeaderFields
:
web_opt = weboptions;
web_opt.RequestMethod = 'Get';
headerFields = {'Authorization', ['Bearer ', 'ZHHgMgh0up5UqJ9TSOIALpkoVpi0']};
web_opt.HeaderFields = headerFields;
and 2). queried the server using:
data = webread(['https://api01.iq.questrade.com/', 'v1/accounts'], web_opt);
And this accomplishes communication with the API server and MATLAB stores my account information as a structure array in the variable data
.
json matlab api post oauth-2.0
add a comment |
up vote
1
down vote
favorite
I'm attempting to create an App that exchanges information with an api (Questrade API to be precise). The api uses oauth2 for security and authentication.
I have been successful1 in acquiring authorization tokens, refresh tokens and querying basic information (my account information and stock quotes).
However, I'm encountering an issue when I try to query stock option quotes (as described here).
I've tried many different permutations but to no avail. This is what I've done so far:
1). I've taken the example shown in the "Sample Request" section provided in the link above and performed jsondecode
to get the MATLAB equivalent and the "exact template" for which the parameter structure must be coded:
>> eg_param = jsondecode('{"filters":{"optionType":"Call","underlyingId":27426,"expiryDate":"2017-01-20T00:00:00.000000-05:00","minstrikePrice":70,"maxstrikePrice":80},"optionIds":[9907637, 9907638]}')
eg_param =
struct with fields:
filters: [1×1 struct]
optionIds: [2×1 double]
>> eg_param.filters
ans =
struct with fields:
optionType: 'Call'
underlyingId: 27426
expiryDate: '2017-01-20T00:00:00.000000-05:00'
minstrikePrice: 70
maxstrikePrice: 80
>> eg_param.optionIds
ans =
9907637
9907638
2). Substituted my actual values (real_params
) for those in the example:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
3). Changed weboptions
' RequestMethod
paramater to post
web_opt.RequestMethod = 'Post';
4). Used the webwrite
function, as opposed to 'webread' to post and query the server:
new_data = webwrite(['https://api01.iq.questrade.com/',...
'v1/markets/quotes/options'], real_params, web_opt);
However, when I do this, is get the error message:
*The server returned the status 400 with
message "Bad Request" in response to the
request to URL
https://api01.iq.questrade.com/v1/markets/quotes/options.*
I've tried many different permutations including changing brackets, , {},{{}} and using different values for the parameters however the result is the same. Also, whenever I tested, I made sure to refresh the access token and test that the connection works using the "account info" request, so this error doesn't have to do with any authorization, security or connection issue.
1 For example, to acquire account information, which the website instructs as:
GET https://api01.iq.questrade.com/v1/accounts
I've 1). used MATLAB's weboptions
and created an object to store token information in HeaderFields
:
web_opt = weboptions;
web_opt.RequestMethod = 'Get';
headerFields = {'Authorization', ['Bearer ', 'ZHHgMgh0up5UqJ9TSOIALpkoVpi0']};
web_opt.HeaderFields = headerFields;
and 2). queried the server using:
data = webread(['https://api01.iq.questrade.com/', 'v1/accounts'], web_opt);
And this accomplishes communication with the API server and MATLAB stores my account information as a structure array in the variable data
.
json matlab api post oauth-2.0
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm attempting to create an App that exchanges information with an api (Questrade API to be precise). The api uses oauth2 for security and authentication.
I have been successful1 in acquiring authorization tokens, refresh tokens and querying basic information (my account information and stock quotes).
However, I'm encountering an issue when I try to query stock option quotes (as described here).
I've tried many different permutations but to no avail. This is what I've done so far:
1). I've taken the example shown in the "Sample Request" section provided in the link above and performed jsondecode
to get the MATLAB equivalent and the "exact template" for which the parameter structure must be coded:
>> eg_param = jsondecode('{"filters":{"optionType":"Call","underlyingId":27426,"expiryDate":"2017-01-20T00:00:00.000000-05:00","minstrikePrice":70,"maxstrikePrice":80},"optionIds":[9907637, 9907638]}')
eg_param =
struct with fields:
filters: [1×1 struct]
optionIds: [2×1 double]
>> eg_param.filters
ans =
struct with fields:
optionType: 'Call'
underlyingId: 27426
expiryDate: '2017-01-20T00:00:00.000000-05:00'
minstrikePrice: 70
maxstrikePrice: 80
>> eg_param.optionIds
ans =
9907637
9907638
2). Substituted my actual values (real_params
) for those in the example:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
3). Changed weboptions
' RequestMethod
paramater to post
web_opt.RequestMethod = 'Post';
4). Used the webwrite
function, as opposed to 'webread' to post and query the server:
new_data = webwrite(['https://api01.iq.questrade.com/',...
'v1/markets/quotes/options'], real_params, web_opt);
However, when I do this, is get the error message:
*The server returned the status 400 with
message "Bad Request" in response to the
request to URL
https://api01.iq.questrade.com/v1/markets/quotes/options.*
I've tried many different permutations including changing brackets, , {},{{}} and using different values for the parameters however the result is the same. Also, whenever I tested, I made sure to refresh the access token and test that the connection works using the "account info" request, so this error doesn't have to do with any authorization, security or connection issue.
1 For example, to acquire account information, which the website instructs as:
GET https://api01.iq.questrade.com/v1/accounts
I've 1). used MATLAB's weboptions
and created an object to store token information in HeaderFields
:
web_opt = weboptions;
web_opt.RequestMethod = 'Get';
headerFields = {'Authorization', ['Bearer ', 'ZHHgMgh0up5UqJ9TSOIALpkoVpi0']};
web_opt.HeaderFields = headerFields;
and 2). queried the server using:
data = webread(['https://api01.iq.questrade.com/', 'v1/accounts'], web_opt);
And this accomplishes communication with the API server and MATLAB stores my account information as a structure array in the variable data
.
json matlab api post oauth-2.0
I'm attempting to create an App that exchanges information with an api (Questrade API to be precise). The api uses oauth2 for security and authentication.
I have been successful1 in acquiring authorization tokens, refresh tokens and querying basic information (my account information and stock quotes).
However, I'm encountering an issue when I try to query stock option quotes (as described here).
I've tried many different permutations but to no avail. This is what I've done so far:
1). I've taken the example shown in the "Sample Request" section provided in the link above and performed jsondecode
to get the MATLAB equivalent and the "exact template" for which the parameter structure must be coded:
>> eg_param = jsondecode('{"filters":{"optionType":"Call","underlyingId":27426,"expiryDate":"2017-01-20T00:00:00.000000-05:00","minstrikePrice":70,"maxstrikePrice":80},"optionIds":[9907637, 9907638]}')
eg_param =
struct with fields:
filters: [1×1 struct]
optionIds: [2×1 double]
>> eg_param.filters
ans =
struct with fields:
optionType: 'Call'
underlyingId: 27426
expiryDate: '2017-01-20T00:00:00.000000-05:00'
minstrikePrice: 70
maxstrikePrice: 80
>> eg_param.optionIds
ans =
9907637
9907638
2). Substituted my actual values (real_params
) for those in the example:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
3). Changed weboptions
' RequestMethod
paramater to post
web_opt.RequestMethod = 'Post';
4). Used the webwrite
function, as opposed to 'webread' to post and query the server:
new_data = webwrite(['https://api01.iq.questrade.com/',...
'v1/markets/quotes/options'], real_params, web_opt);
However, when I do this, is get the error message:
*The server returned the status 400 with
message "Bad Request" in response to the
request to URL
https://api01.iq.questrade.com/v1/markets/quotes/options.*
I've tried many different permutations including changing brackets, , {},{{}} and using different values for the parameters however the result is the same. Also, whenever I tested, I made sure to refresh the access token and test that the connection works using the "account info" request, so this error doesn't have to do with any authorization, security or connection issue.
1 For example, to acquire account information, which the website instructs as:
GET https://api01.iq.questrade.com/v1/accounts
I've 1). used MATLAB's weboptions
and created an object to store token information in HeaderFields
:
web_opt = weboptions;
web_opt.RequestMethod = 'Get';
headerFields = {'Authorization', ['Bearer ', 'ZHHgMgh0up5UqJ9TSOIALpkoVpi0']};
web_opt.HeaderFields = headerFields;
and 2). queried the server using:
data = webread(['https://api01.iq.questrade.com/', 'v1/accounts'], web_opt);
And this accomplishes communication with the API server and MATLAB stores my account information as a structure array in the variable data
.
json matlab api post oauth-2.0
json matlab api post oauth-2.0
edited Nov 7 at 13:43
Dev-iL
16.3k64074
16.3k64074
asked Nov 7 at 11:15
kquests
61
61
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22
add a comment |
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Unfortunately I cannot test the solution since the API key you provided seems not to work, but it might help you anyway.
Can you spot the difference between the JSON produced using these two blocks?
% Original code:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":2.3255262E+7,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
% Slightly modified code:
real_params = struct();
real_params.optionIds = int32(23255262);
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":23255262,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
It might be that the automatic conversion is the culprit in this case (which for a lack of better reason, sent your optionIds
as a double
value, and not the integer that the API expects.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Unfortunately I cannot test the solution since the API key you provided seems not to work, but it might help you anyway.
Can you spot the difference between the JSON produced using these two blocks?
% Original code:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":2.3255262E+7,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
% Slightly modified code:
real_params = struct();
real_params.optionIds = int32(23255262);
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":23255262,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
It might be that the automatic conversion is the culprit in this case (which for a lack of better reason, sent your optionIds
as a double
value, and not the integer that the API expects.
add a comment |
up vote
1
down vote
Unfortunately I cannot test the solution since the API key you provided seems not to work, but it might help you anyway.
Can you spot the difference between the JSON produced using these two blocks?
% Original code:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":2.3255262E+7,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
% Slightly modified code:
real_params = struct();
real_params.optionIds = int32(23255262);
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":23255262,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
It might be that the automatic conversion is the culprit in this case (which for a lack of better reason, sent your optionIds
as a double
value, and not the integer that the API expects.
add a comment |
up vote
1
down vote
up vote
1
down vote
Unfortunately I cannot test the solution since the API key you provided seems not to work, but it might help you anyway.
Can you spot the difference between the JSON produced using these two blocks?
% Original code:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":2.3255262E+7,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
% Slightly modified code:
real_params = struct();
real_params.optionIds = int32(23255262);
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":23255262,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
It might be that the automatic conversion is the culprit in this case (which for a lack of better reason, sent your optionIds
as a double
value, and not the integer that the API expects.
Unfortunately I cannot test the solution since the API key you provided seems not to work, but it might help you anyway.
Can you spot the difference between the JSON produced using these two blocks?
% Original code:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":2.3255262E+7,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
% Slightly modified code:
real_params = struct();
real_params.optionIds = int32(23255262);
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = ;
real_params.filters.maxstrikePrice = ;
%{
>> jsonencode(real_params)
ans =
'{"optionIds":23255262,"filters":{"optionType":"Call","expiryDate":"2018-11-09T00:00:00.000000-05:00","underlyingId":40825,"minstrikePrice":,"maxstrikePrice":}}'
%}
It might be that the automatic conversion is the culprit in this case (which for a lack of better reason, sent your optionIds
as a double
value, and not the integer that the API expects.
answered Nov 7 at 14:04
Dev-iL
16.3k64074
16.3k64074
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188391%2fbad-request-when-performing-a-post-api-query-using-webwrite%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Unfortunately I thought I added hyperlinks to the questions but they are not showing up in the original message. The links are: [website][1] - questrade.com/api/documentation/rest-operations/account-calls/… (as described [here][2]. - questrade.com/api/documentation/rest-operations/market-calls/…
– kquests
Nov 7 at 11:22