```endpoint.get( '/posts/{postId}', ( req, res ) =...
# general
s
Copy code
endpoint.get( '/posts/{postId}', ( req, res ) => {
    const post = req.params.postId;
    console.log( post );
    postsTable.get( { post } ).then( ( value ) => {
        res.status( 200 ).json( value );
    } );
} );
w
How did you define your table? It sounds like you did not specify
post
as a primary key for this table.
s
``` const postsTable = new cloud.Table( 'feedPosts', 'postId' ); // Create an API endpoint const endpoint = new cloud.API( 'feed-posts' ); // Add a new Feed Post endpoint.post( '/posts/add', ( req, res ) => { const feedPost = JSON.parse( req.body ); console.log( feedPost ); postsTable.insert( { postId: feedPost.postId, title: feedPost.title, body: feedPost.body, } ).then( () => { res.status( 200 ).json( feedPost ); }, res.status( 500 ).end() ); } ); // Get a single Feed Post endpoint.get( '/posts/{postId}', ( req, res ) => { const post = req.params.postId; console.log( post ); postsTable.get( { post } ).then( ( value ) => { res.status( 200 ).json( value ); } ); } );
That was my code; after your message I updated my get to use postId for the assignment to the parameter and passed that into the query, that worked fine.
I guess the table.get {query} is looking at the key name itself, not assuming the value is the primary key.
w
That's right - that JS code is a shorthand for
postsTable.get( { post: post } )
, so it's getting the primary key
"post"
whose value matches the value of
post
.