Creating a new conversation message via API

Hi,
I’m attempting to add a message in the conversation of an item when I’m creating a new item,
as if:

I want to populate this field, of a specific item id.

I have been struggling with this for quite some time,

anyone has an example for such a mutation?

Regards!

Hello @danieln,

The API for creating an update can be found here.
Once you create your item, you can use the created item id and create an update
Hope this helps :slight_smile:

Hi, thanks for the quick response :slight_smile:
Unfortunately it is not working for me, I have attempted in this form:

  let conversationQuery =
    'mutation {create_update (item_id: 3837363913, body: "This update will be added to the item") { id }}';
  // const updateConversationQuery = `mutation { update_item( item_id: 3837270521, conversation: "hiiiii" ) { id conversation } }`;
  const response2 = await fetch("https://api.monday.com/v2", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: MondayService.apiKey,
    },
    body: JSON.stringify({ conversationQuery }),
  });

and no success.

the item id is for sure existing.

Your code looks correct. Do you receive any error message?
Also does the same code work in the playground?

hi :slight_smile:
works via playground…
but it cannot be related to my authorization, as a moment before that I’m doing a create_item, which is working,

i don’t understand where else it can go wrong

Do you have a catch block for any errors you might be getting. Also, are there any errors in your browser?

   'content-security-policy' => "frame-ancestors https://monday.com https://*.monday.com https://bigbrain.me https://*.bigbrain.me https://teams.microsoft.com https://*.teams.microsoft.com https://*.microsoftonline.com https://*.office365.com https://*.microsoft.com https://webbyawards.com https://www.webbyawards.com https://msteams.backend.monday.app https://monday.lightning.force.com https://monday.force.com https://www.office.com https://*.www.office.com https://outlook.office.com https://outlook-sdf.office.com https://outlook.office365.com https://outlook-sdf.office365.com https://outlook.live.com https://outlook-sdf.live.com https://app.eu.pendo.io https://msteams-eu.backend.monday.app https://msteams-au.backend.monday.app https://monday.vitally.io; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.monday.com https://webpack.llama.fan:3444 https://*.microsoft.com https://*.hsforms.com https://*.pusher.com https://accounts.google.com https://ajax.googleapis.com https://api.embed.ly https://apis.google.com https://app.box.com https://appvizer.one/ariadne/v1/ariadne.js https://bat.bing.com https://cdn.broadcast.am https://cdn.pdst.fm https://cdn.simpo.io/actionbar.js https://cdn.simpo.io/simpo-client.js https://cdn.taboola.com https://cdn.walkme.com https://cdnjs.cloudflare.com https://code.highcharts.com https://connect.facebook.net https://ct.capterra.com https://d18vk66ftlazd2.cloudfront.net https://d2c7xlmseob604.cloudfront.net https://edge.fullstory.com https://rs.fullstory.com https://googleads.g.doubleclick.net https://js.hsforms.net https://js.live.net https://maps.googleapis.com https://monday.com https://s.pinimg.com https://s.ytimg.com https://snap.licdn.com https://snippet.growsumo.com https://songbird.cardinalcommerce.com https://static.cloudflareinsights.com https://static.zdassets.com https://tpc.googlesyndication.com https://translate.googleapis.com https://*.zopim.com https://ws.bluesnap.com https://www.dropbox.com https://www.google-analytics.com https://www.google.com https://www.googleadservices.com https://www.googletagmanager.com https://www.gstatic.com https://www.youtube.com https://bigbrain.me https://*.bigbrain.me https://informer-cdn.monday.com https://cdn.eu.pendo.io https://app.eu.pendo.io https://data.eu.pendo.io https://pendo-eu-static-6485021788340224.storage.googleapis.com https://js.appboycdn.com/web-sdk/3.2/appboy.no-amd.min.js https://js.appboycdn.com/web-sdk/3.2/appboy.min.js https://sdk.iad-06.braze.com https://*.cdn2.monday.app https://microfrontends.monday.com https://js.braintreegateway.com https://assets.braintreegateway.com https://*.paypal.com https://cdn.monday.com https://browser.sentry-cdn.com https://*.hotjar.com https://static.ads-twitter.com https://analytics.twitter.com https://analytics.tiktok.com https://s.yimg.jp/images/listing/tool/cv/ytag.js https://cdn.linkedin.oribi.io https://trc.taboola.com https://pips.taboola.com https://cds.taboola.com https://cdn.servicebell.com https://api.servicebell.com wss://api.servicebell.com wss://ws.servicebell.com; worker-src 'self' 'unsafe-inline' blob:; connect-src 'self' https://*.monday.com https://monday.com wss://webpack.llama.fan:3444 https://webpack.llama.fan:3444 https://grsm.io https://forms.hsforms.com https://*.algolia.net https://*.algolianet.com https://bat.bing.com https://*.braze.com https://api.smartling.com https://us-central1-adaptive-growth.cloudfunctions.net https://appvizer.one https://www.facebook.com https://graph.microsoft.com https://graph.facebook.com https://api.giphy.com https://ct.pinterest.com https://storage.monday.app https://trc-events.taboola.com https://broadcast.am https://stats.g.doubleclick.net https://rs.fullstory.com https://*.cloudfront.net https://dapulse-res.cloudinary.com https://static.cloudflareinsights.com https://*.bigbrain.me https://www.dropbox.com https://www.googletagmanager.com https://ipinfo.io https://*.cardinalcommerce.com https://www.bluesnap.com https://connect.facebook.net https://app.box.com https://code.highcharts.com https://js.live.net https://monday.zendesk.com https://static.zdassets.com https://ekr.zdassets.com https://ekr.zendesk.com https://maps.googleapis.com wss://*.pusher.com https://*.pusher.com wss://*.zopim.com https://*.zopim.com https://www.google-analytics.com https://api.simpo.io https://cdn.simpo.io https://zh081jts88wj.statuspage.io https://www.googleapis.com https://cdn.eu.pendo.io https://app.eu.pendo.io https://data.eu.pendo.io https://pendo-eu-static-6485021788340224.storage.googleapis.com https://api.braintreegateway.com https://client-analytics.braintreegateway.com https://*.braintree-api.com https://*.paypal.com https://*.sentry.io https://cdn.jsdelivr.net https://prod-use1-crm-billing.s3.amazonaws.com https://prod-use1-crm-communication.s3.amazonaws.com https://files-monday-com.s3.amazonaws.com https://prod-apse2-crm-billing.s3.ap-southeast-2.amazonaws.com https://prod-apse2-crm-communication.s3.ap-southeast-2.amazonaws.com https://prod-apse2-files-monday-com.s3.amazonaws.com https://prod-euc1-crm-billing.s3.eu-central-1.amazonaws.com https://prod-euc1-crm-communication.s3.eu-central-1.amazonaws.com https://prod-euc1-files-monday-com.s3.amazonaws.com https://microfrontends.monday.com https://*.hotjar.com https://*.hotjar.io https://static.ads-twitter.com https://analytics.twitter.com https://analytics.tiktok.com https://s.yimg.jp/images/listing/tool/cv/ytag.js https://cdn.linkedin.oribi.io https://trc.taboola.com https://pips.taboola.com https://cds.taboola.com https://cdn.servicebell.com https://api.servicebell.com wss://api.servicebell.com wss://*.hotjar.com wss://ws.servicebell.com https://rum.browser-intake-datadoghq.eu https://session-replay.browser-intake-datadoghq.eu;",
      'x-robots-tag' => 'none',
      'x-xss-protection' => '1; mode=block',
      'content-encoding' => 'gzip',
      'x-monday-rgn' => 'use1',
      'cf-cache-status' => 'DYNAMIC',
      'set-cookie' => '__cf_bm=XXXXX
path=/; expires=Thu, 19-Jan-23 å15:43:38 GMT; domain=.monday.com; HttpOnly; Secure; SameSite=None',
      'strict-transport-security' => 'max-age=15552000; includeSubDomains; preload',
      'server' => 'cloudflare',
      'cf-ray' => 'XXXX'
    },
    [Symbol(headers map sorted)]: null
  }
}

Does the scope (see OAuth menu) of your app includes updates:write?

Hi : )

The only piece of information I get is the one I have posted (the console.log of fetch’s response).

Regards

What Bas is referring to is the app’s OAuth scopes.
In your app settings, the updates:write option should be checked before your app can be allowed to write updates

Hi,

Is it a must to create an App?
As I have been using the Token which’s @ ‘Click on Avatar → Developers → Developer → Token’, and I have been able to create new items, read items and so on only using the Token on my Javascript application.

A token has a list of things that is permitted to do.
The list of permissions allowed for the token is what you can select in the OAuth screen.
For example, if you don’t select updates:write for your token, then the token cannot create or edit an update.

Hi @danieln,

Are you still experiencing this issue?

@kolaai & @basdebruin thank you for your helpful contributions! :slight_smile:

hi @kolaai
thanks for the help :slight_smile:

it doesn’t make much sense though, at least to me, as through the playground I’m able to make a new update. Why would it be any different than my api request via the react application i’m creating?

in case there is a difference, is there a way to edit token’s permissions ? or is it only for apps? as I haven’t found anything on tokens.

@alessandra, still experiencing the issue.

regards :_)

Hello @danieln,

If the token you are using is an OAuth token you got, your scopes need to include updates:write. It won’t work otherwise.

If you are using the API to create the update in your own account and the API key you are using is from a user that has access to that board, that item and can create items there via UI, then your query should work with that API key.

Please let me know which one is the case here.

If you want to include a screen recording of the whole process, that could help too. Be sure not to include any sensitive information if you do.

Cheers,
Matias

Hi, the token I’m using is the one provided in ‘Avatar->Developers->Developer->My Access Token’ for both playground and for my project.

I’m able to create new item and add an update to it via playground,
I’m able to only create new item via the project.

The weird thing is that, as showed my code before, the fetch request to Monday’s API is the same as my create item’s request (which works), besides the query which I copy pasted from playground (which works there) into my project.

:smiling_face_with_tear:

Hello again,

What happens if you log the error message you get from our server? You can use something like this:

 let conversationQuery =
    'mutation {create_update (item_id: 3837363913, body: "This update will be added to the item") { id }}';
  // const updateConversationQuery = `mutation { update_item( item_id: 3837270521, conversation: "hiiiii" ) { id conversation } }`;
  const response2 = await fetch("https://api.monday.com/v2", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: MondayService.apiKey,
    },
    body: JSON.stringify({ conversationQuery }),
  })
	   .then(res => res.json())
	   .then(res => console.log(JSON.stringify(res, null, 2)));

What do you see in your console when adding this?

Hi :slight_smile:

I have received the following:

{
“errors”: [
{
“message”: “No query string was present”
}
],
“account_id”: XXXXXX
}

Hello again,

Oh. I believe I might know how to solve this. If it is what I think, it is not related to a monday issue, but to the syntax.

Can you please try this:
body: JSON.stringify({'query' : conversationQuery})

1 Like

That’s the solution, haha, unbelievable how sometimes it’s just in front of us.

@Matias.Monday and @kolaai, big thanks to the both of you! :_)