How to pass a value from Meteor.call to corresponding Method, on an external API url to return one set of results

As the topic says, I have a list of Projects being pulled from an external API (Teamwork). I have my app working to display all projects (endpoint of just /projects.json).

Here’s the code that is listing those Projects out (much of this taken from Meteor Chef’s site and examples):

/****
Start
****/
import React from ‘react’;
import { Link } from ‘react-router’;
import { ListGroupItem, Button, Alert, Table } from ‘react-bootstrap’;
import { browserHistory } from ‘react-router’;

const handleNav = _id => browserHistory.push(/projects/${_id});

const renderProjects = (projects) => (
projects.length > 0 ?










{ projects.map((project) => <tr key={ project.id }>



)}

ID Name Project Manager
{ project.id }
<ListGroupItem key={ project.id } onClick={ () => handleNav(project.id) }>
{ project.name }

{ project.category.name }
: No projects found.
);

export class Projects extends React.Component {
render() {
const { projects } = this.props;

	return <div>
		<h4 className='page-header'>Projects</h4>
		{ renderProjects(projects) }
	</div>
}

}

Projects.propTypes = {
projects: React.PropTypes.array,
}

/****
End
****/

Basically, when you click on one of the projects, it routes correctly to /projects/<project.id> but I am unsure how to pass that project.id to my meteor method to then query the api to get the results of that endpoint. Here’s the URL structure for querying a single Project: ‘/projects/(project.id).json’

Here’s the method:

/***
Start
/
getProject() {
return callService(
‘GET’,
https://ironpaper.teamwork.com/projects/(project.id).json’,
apiUrl,
{
// auth removed for security
}
).then((result) => result).catch((error) => {
throw new Meteor.Error(‘500’, ${error.message});
});
}
/
*
End
****/

And here’s the method call:

/****
Start
****/
import { Project } from ‘…/…/pages/Project.js’;
import { Loading } from ‘…/…/components/Loading.js’;
import { Meteor } from ‘meteor/meteor’;
import { Bert } from ‘meteor/themeteorchef:bert’;
import composeWithTracker from ‘…/…/…/api/compose-with-tracker.js’;

const composer = (params, onData) => {
Meteor.call(‘getProject’, (error, response) => {
if (error) {
Bert.alert(error.reason, ‘danger’);
} else {
onData(null, {project: response.data.project});
var projectId = response.data.project.id;
}
});
};

export default composeWithTracker(composer, Loading)(Project);

/****
End
****/

When hardcoding a project ID into the method, it works…but I need to know how to pass the ID from the view into the method so that the correct URL is built to return that single project.

Any ideas?

This is how you pass arguments to methods:

var id = '345345'
Meteor.call('getProject',id, (error, response) => {
console.log(response);
//Do stuff
});
Meteor.methods({
getProject(id){
console.log(id);
//Do stuff
}
});

Upon review, I wasn’t clear as to the exact situation. The project.id isn’t available until the Meteor.call runs, so I can’t set the variable before that. It may not be possible to do this the way I have my code setup. Basically I need to pass a dynamic project.id which is in the URL of the page i’m on (/projects/12345 <-- pass that) to the method which is called to retrieve the data for that page.