Add subscribers to board using json

Trying to add subscribers to a board… Multiple errors.

const variables = ({
    boardId : suptBoardId,
    producerId: producer,
    kind: "owner",
});

const mutate = `mutation add_subscribers_to_board ($boardId: Int!, $producerId: Int!, $kind: SubscriberKind!) {
    add_subscribers_to_board(
      board_id: $boardId,
      user_id: $producerId,
      kind: $kind,
    )
    {
      id
    }
}`

monday.api(mutate, {variables}).then((res) => {
    console.log('add subscriber: ', res);
});

@ShawnBaden

i’m sorry to hear you are having issues with this mutation. I’ve just tried running one on my end, and was able to add a subscriber to a board within my account. Could you clarify if you are sending your user IDs as an array, i.e. [12345,678912,91266]?

Also, is the board within a Main Workspace or a Closed one?
I would also recommend removing quotes around owner, as this is a boolean and not a string value. That might help here!

-Alex

I changed SubscriberKind! to BoardSubscriberKind! and it worked. Not sure today how I arrived at that but it works.

I’m having a similar issue today with a board duplication though and can’t resolve it.

Here’s another example. The structure is slightly different…

const suptTemplateVars = ({
          boardId : suptTemplateId,
          duplicateType: "duplicate_board_with_structure",
          folderId: suptBoardFolderId,
        });
      
        console.log('!suptBoardExists: ')
        
        const mutateTemplate = `mutation duplicate_board ($boardId: Int!, $duplicateType: DuplicateBoardType!, $folderId: Int!) {
            duplicate_board(
              board_id: $boardId,
              duplicate_type: $duplicateType,
              folder_id: $folderId,
            )
            {
              id
            }
        }`
        
        monday.api(mutateTemplate, {suptTemplateVars}).then((res) => {
            console.log('add suptBoard: ', res);
        });
      }

I can’t get this to work.

I would love to understand how to build this from looking at the api documentation.

@ShawnBaden

Got it, I’m glad you were able to tackle the adding subscribers mutation!

I think the same issue is occurring here, as duplication type is also a boolean, and not a String, so sending it within quotes will not work. Could you try out that approach and let us know if it works?

Here’s how this works within Postman:

I’d love to understand how we could make the documentation better in that sense. Could you please shed more light on how we could improve that part of our docs? I’d love to get any kind of documentation improvements added :slight_smile:

-Alex

@AlexSavchuk - I don’t understand how it can be a boolean when there are 3 options:

  • duplicate_board_with_structure
  • duplicate_board_with_pulses
  • duplicate_board_with_pulses_and_updates

If it were a boolean I could pass in true or false right?

@AlexSavchuk - I would be interested in getting on a call with you to talk about where I’m not making the connection between the documentation and the code.

@ShawnBaden

Sorry, that’s an inaccuracy on my part. It is an enumerated type instead, and after testing this further, you should indeed pass it within quotes when sending it as a variable. Here’s a StackOverflow thread I’ve found with other GraphQL examlpes:

GraphQL - Passing an enum value directly to a mutation as an argument?

I’d love to discuss this further on the call.

In the future, it would really help us troubleshoot and understand how we can best assist with the issues you have using our API/Apps Framework if you could provide the exact errors you are seeing using the code you’ve provided. Those errors can be quite helpful to narrow down the root cause. :slight_smile:

-Alex

@AlexSavchuk - I’m still not having any success using the code sample you gave me. I’m guessing that something isn’t translating between the vanilla javascript and the Monday SDK.

When I use this…

let mutateTemplate = `mutation duplicate_board ($boardId: Int!, $duplicate_type: DuplicateBoardType!, $folderId: Int!, $board_name: String!) {
          duplicate_board ( board_id: $boardId, duplicate_type: $duplicate_type, folder_id: $folderId, board_name: $board_name ) {
            {
              id
            }
          }
      }`;

I get one error:

When I use this…

let mutateTemplate = `mutation duplicate_board ($boardId: Int!, $duplicate_type: DuplicateBoardType!, $folderId: Int!, $board_name: String!) {
          duplicate_board ( board_id: $boardId, duplicate_type: $duplicate_type, folder_id: $folderId, board_name: $board_name ) {
            board {
              id
            }
          }
      }`;

I get 4 errors:

It works in the API Playground…

Still can’t get it to work in my app though.

@ShawnBaden

Thank you, that helps identify what might be happening here.

In both cases, the error is thrown likely due to formatting errors. In the first case, using the following API request:

let mutateTemplate = `mutation duplicate_board ($boardId: Int!, $duplicate_type: DuplicateBoardType!, $folderId: Int!, $board_name: String!) {
          duplicate_board ( board_id: $boardId, duplicate_type: $duplicate_type, folder_id: $folderId, board_name: $board_name ) {
            {
              id
            }
          }
      }

You have an extra right curly bracket, but either way, simply requesting id after a duplicate_board request will not work either, I’m afraid. it will always need to be { board { id }}.

In the second case, when you are sending your variables, they all arrive as “null” values to our API. Perhaps this is something to do with the way you are getting the values from a previous step in your code, or this might be related to the way those are JSON stringified:

The query seems to be formatted correctly in the API playground, and with providing exact values as variables, it does seem to work. Now, we just need to figure out how those variables should be passed to the SDK.

If you’re open to that, it would help us identify the issue if you share more of your code with us, as it seems like it’s not an API formatting issue, but might be related to the way those values are passed to the query.

-Alex

1 Like

@AlexSavchuk - The extra curly brace is because I just copied too much of the code.
When I console log all of the variables before the api call they all log valid values…

Here is my code block for the useEffect()

useEffect(() => {
    let filteredBoards = suptBoards.filter(board => (board.name === 'SUPT_' + showAbbr));
    console.log('boardNameExists: ', filteredBoards)

    if(filteredBoards.length){
      filteredBoards.forEach(board => {
        setSuptBoardId(Number(board.id));
        setSuptBoardSubscribers(board.subscribers);
        console.log('subscribers: ', board.subscribers);
        console.log('producer: ', producer)
        console.log('boardName: ', board.name)
      })
    }
    else{
      console.log('!suptBoardExists: ')
      console.log('templateId: ', suptTemplateId);
      console.log('suptBoardFolderId: ', suptBoardFolderId);
      console.log('showAbbr: ', showAbbr)
      
      let suptTemplateVars = ({
        boardId : suptTemplateId,
        duplicateType: "duplicate_board_with_structure",
        folderId: suptBoardFolderId,
        boardName: "SUPT_"+ showAbbr,
      });
      console.log('boardId: ', suptTemplateVars.boardId)
    
      let mutateTemplate = `mutation duplicate_board ($boardId: Int!, $duplicateType: DuplicateBoardType!, $folderId: Int!, $boardName: String!) {
        duplicate_board (
          board_id: $boardId,
          duplicate_type: $duplicateType,
          folder_id: $folderId,
          board_name: $boardName
        )
        {board {id}}
      }`;
      
      monday.api(mutateTemplate, {suptTemplateVars}).then((res) => {
          console.log('add suptBoard: ', res);
      });
    }
  }, [showAbbr]);

I’ll email you the entire app.js

Hey @ShawnBaden

Thanks for being so open to collaborate on this, and receptive to feedback :slight_smile:

I’ll try and review this in detail as soon as I can and get back to you with further suggstions.

-Alex

To anyone curious, we actually managed to figure this one out, although it’s quite silly.

The monday.api syntax is:

monday.api(query, options = {})

So in this case, we’d needed to make sure that we’re not sending suptTemplateVars, but instead, we’re sending a variables object. As soon as we’d made the adjustment, the values were recognized correctly.

Instead of sending:
monday.api(mutateTemplate, {suptTemplateVars})

We needed to send:
Monday.api(mutateTemplate, {variables})

Thank you for being available to review together, @ShawnBaden :slight_smile:

-Alex

1 Like

@AlexSavchuk - Thank you for all the help!

Wasn’t the issue also the naming convention? My variables object had to be named “variables”
Monday.api(mutateTemplate, {variables})

@ShawnBaden

Yes, exactly that! I’ll edit my post so that gets the same point across :slight_smile:

Thank you!

-Alex

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.