I have a sample php query that retrieves data from the API:
$http = new Client();
$response = $http->get('https://connection.toserver.com', [ 'GetRequest' => [
'identifier' => '123',
'identifierType' => 'code',
'language' => 'eng',
'maxCount' => 1,
'contain' => ['name', 'lastname', 'age']
]
],
[
'headers' => [
'API-LANGUAGE' => 'eng',
'API-CALL-NAME' => 'Get',
'API-AUTH-TOKEN' => 'somerandomtoken']
]
);
How can I make the same request from a Meteor server-side function using HTTP package? My last attempt looked like this:
Meteor.methods({
getItemByEAN: function(code) {
check(code, String);
this.unblock();
var x = HTTP.get(url,
{headers:{
"API-LANGUAGE": "eng",
"API-CALL-NAME": "Get",
"API-AUTH-TOKEN": "somerandomtoken"
},
data: {
identifier: code,
identifierType: 'code',
language: 'eng',
maxCount: 1,
contain: ['name', 'lastname', 'age']
}
});
return(x);
}
});
This code resulted in server error "ReferenceError: data is not defined" I am using meteor docs ( http://docs.meteor.com/#/full/http_call ) as a reference but with no success so far.
Thank You in advance
EDIT: I've updated the current meteor example to show full Meteor.methods() section
I don't know what your server expects, but one difference I see is that in php you wrap the data in a "GetRequest" object. Have you tried this:
HTTP.get(url,
{headers:{
"API-LANGUAGE": "eng",
"API-CALL-NAME": "Get",
"API-AUTH-TOKEN": "somerandomtoken"
},
data: { GetRequest: {
identifier: 123,
identifierType: 'code',
language: 'eng',
maxCount: 1,
contain: ['name', 'lastname', 'age']
}}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.