Syntax Error in Terminal function call

Just one more silly doubt :

public func putPost(newPost : Types.Post) : async (){
        var curPPID : Nat = newPost.ppid;
        if(curPPID == 0){
            //make new xchange with hospost as newPost
            var newXid : Nat = mapXchange.size() + 1;
            var newXchange : bufferPost = Buffer.Buffer<Types.Post>(0);
            newXchange.add(newPost);
            mapXchange.put(newXid, newXchange);
        };
        if(curPPID != 0){
            for(curXchange in mapXchange.vals()){
                var curXchangeArray : [Types.Post] = curXchange.toArray();
                if(curXchangeArray[0].xid == newPost.xid){
                    curXchange.add(newPost);
                };
            };       
        };
        return ();
    };

Above is a function to put a entity in a hashmap.
**Entity : hostPost **

let hostPost : Types.Post = {
        pid = 1;    // Post Id
        uid = 1;    // User Id
        ppid = 0;   // Parent Post Id, Null = no parent, so this is a hostPost
        xid = 1;    // Xchange Id
        tid = 0;    // Thread Id
        cid = 0;    // Conversation (= Discourse = Issue = Subject = Topic) Id)
        iid = 0;    // Instance Id
        did = 0;    // Debate Id
        postType = "Introduction";
        speakerName = "Carl";
        createdAt = "2021-05-22 07:56:09.282+00";
        summary = "Etiam imperdiet ullamcorper lorem. Integer ac nisi eget arcu.";
        details = "<div><p>Pellentesque accumsan risus ut fermentum hendrerit!</p>\n<p>Nulla ac velit lobortis, iaculis mauris et, suscipit orci. Quisque viverra sem in aliquet bibendum. Etiam sodales tincidunt turpis convallis hendrerit. Maecenas luctus fringilla ex, vel rhoncus leo lobortis et. Cras laoreet sit amet justo vel viverra!</p></div>";
        thumbnail = "";
        titleFrame = "";
        votable = true;
        voteType = "resonate";
        video = "hd9dwdbd8xv";
        published = true;
    };

But when i am trying to call this function in terminal to put above entity in hashmap , it is showing some syntax error.
Can you please correct this?

dfx canister call canisterName putPost '(hostPost)'

Error :Invalid argument: Invalid Candid values: Candid parser error: Unrecognized token Id("hostPost") found at 0:8
Expected one of “(”, “blob”, “bool”, “decimal”, “float”, “func”, “hex”, “null”, “opt”, “principal”, “record”, “service”, “sign”, “text”, “variant” or "vec"

I think you need to pass the actual hostPost to the cli.
It should look like this or similar
dfx canister call canisterName putPost '({id: .., postType: ...})'

1 Like

So it means i can pass it as a single entity , after defining it in my code above?
and Its still not working , passing it that way.

Can you share how you pass it in the CLI?

1 Like
dfx canister call CanisterName putPost '({pid : 1, uid : 1 , ppid : 0, xid : 1, tid : 0, .........})'

Is there any other way?

What’s the error you are getting?

1 Like
error: parser error
  ┌─ Candid argument:1:2
  │
1 │ ({pid : 1, uid : 1 , ppid : 0, xid : 1, tid : 0, cid : 0, iid : 0, did :0, postType = "Introduction", speakerName : "Carl", createdAt : "", summary:"", details : "", thumbnail : "", titleFrame:"", votable : true, voteType : "resonate", video = "", published : true})
  │  ^ Unexpected token
  │
  = Expects one of "(", ")", "blob", "bool", "decimal", "float", "func",
    "hex", "null", "opt", "principal", "record", "service", "sign",
    "text", "variant", "vec"

Invalid argument: Invalid Candid values: Candid parser error: Unrecognized token `LBrace` found at 1:2
Expected one of "(", ")", "blob", "bool", "decimal", "float", "func", "hex", "null", "opt", "principal", "record", "service", "sign", "text", "variant" or "vec"

You need to add

'(record {.....})'

You can check more info here:

2 Likes