Notification payload

Hi Monday Team,

In your API documentation, for creating notifications, it says we can add JSON payload, but I am getting 500s constantly when I try to add it (without that argument it works well):

    monday.api(`
      mutation {
        create_notification(
          text: ${JSON.stringify(notificationText)},
          user_id: ${userId},
          target_id: ${itemId},
          payload: ${JSON.stringify(1234)},
          target_type: Project,
          internal: true
        ) { 
          text 
        }
      }
    `);

Response:
{error_message: "Internal server error", status_code: 500}

Am I doing something wrong? Could you help me, please?

Additionally I have a couple questions as well: if it will work, how we can get the payload when opening a notification? I will be in the context? What is “post” target_type (I tried it but it results as 500 on my side)?
In this documentation you used “internal” argument for creating notification, what does it mean?

Thanks,
Krisztian

Hi @kkocsis

Welcome to the community. I am using a function to send notifications.

static async sendNotification(token, userId, targetId, notificationText) {
    try {
      const mondayClient = initMondayClient({ token });
      const query = `mutation create_notification($userId: Int!, $targetId: Int!, $notificationText: String!){
        create_notification(user_id: $userId, target_id: $targetId, text: $notificationText, target_type: Project) {
            text
          }
        }
        `;

      const variables = { userId, targetId, notificationText };
      const response = await mondayClient.api(query, { variables });
      return response;
    } catch (err) {
      console.log(err);
    }
  }
} 

I am calling this function with:

mondayService.sendNotification(token, userId, boardId, notificationText);

The UserId here is the userId of the user who gets the notification.

Hope this helps.

Thanks @basdebruin, I can make it work, I just would like to know how I can send contextual data with a notification.

Hey @kkocsis - could you expand a bit on what you’re referring to by contextual data?

Hi @dsilva, I see you’ve recently responded to this so hopefully I can get some support from you guys.

Not to hijack the thread but I’m also getting 500’s with this query. Also want to give you a heads up that the documentation in https://monday.com/developers/v2#mutations-section-notifications is incorrect.

The example shows ‘project’ in lowercase, when it should be in upper case as the API rejects it otherwise.

Can you guys let me know if this API is broken or experiencing issues on your end? Here’s a snippet of our Python code that calls this

    def notify_setter(self, msg, user_id):
        query = 'mutation ' \
                '($user_id: Int!, $target_id: Int!, $msg: String!) ' \
                '{ ' \
                'create_notification (' \
                'user_id: $user_id, ' \
                'target_id: $target_id, ' \
                'text: $msg, ' \
                'target_type: Project' \
                ') {text} }'
        query_vars = {
            'user_id': self.sender_id,
            'target_id': user_id,
            'msg': msg,
        }

The resulting query string becomes:
'mutation ($user_id: Int!, $target_id: Int!, $msg: String!) { create_notification (user_id: $user_id, target_id: $target_id, text: $msg, target_type: Project) {text} }'