API - create a new conversation Issue

Hello everyone,

I’m trying to launch an Assistant via API, but it’s not working. Has anyone here successfully made a working request that they could share as an example?

For context, my connection (with same credentials) is working fine with Zapier but not with the following code :

import requests

url = "https://dust.tt/api/v1/w/Wid/assistant/conversations"

payload = {
    "message": {
        "context": { "origin": "api" },
        "content": "Can you check if John Doe is still working at Acme? If yes, tell me his current position and department within the company. If not, provide details about his new company, his role, department, and experience level.",
        "mentions": [{ "configurationId": "RBh045O2Ak" }]
    },
    "contentFragment": { "context": { "origin": "api" } },
    "blocking": True,
    "title": "My conversation",
    "visibility": "unlisted"
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "Bearer sk-xxxxxx"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

Documentation here

Thank you

Hi Clément, what’s the error you’re receiving ?

Also your URL is wrong, you need to replace wqid by your actual workspace id (what’s after the w/ in the url when you are on dust)

Hello Alban,
This one

"{
  "error": {
    "type": "invalid_request_error",
    "message": "Invalid request body: Expecting string at 0.contentFragment.0.content but instead got: undefined,Expecting \"application/msword\" at 0.contentFragment.0.contentType.0 but instead got: undefined,Expecting \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\" at 0.contentFragment.0.contentType.1 but instead got: undefined,Expecting \"image/png\" at 0.contentFragment.0.contentType.10 but instead got: undefined,Expecting \"dust-application/slack\" at 0.contentFragment.0.contentType.11 but instead got: undefined,Expecting \"application/pdf\" at 0.contentFragment.0.contentType.2 but instead got: undefined,Expecting \"text/comma-separated-values\" at 0.contentFragment.0.contentType.3 but instead got: undefined,Expecting \"text/csv\" at 0.contentFragment.0.contentType.4 but instead got: undefined,Expecting \"text/markdown\" at 0.contentFragment.0.contentType.5 but instead got: undefined,Expecting \"text/plain\" at 0.contentFragment.0.contentType.6 but instead got: undefined,Expecting \"text/tab-separated-values\" at 0.contentFragment.0.contentType.7 but instead got: undefined,Expecting \"text/tsv\" at 0.contentFragment.0.contentType.8 but instead got: undefined,Expecting \"image/jpeg\" at 0.contentFragment.0.contentType.9 but instead got: undefined,Expecting string at 0.contentFragment.0.context.0.email.0 but instead got: undefined,Expecting null at 0.contentFragment.0.context.0.email.1 but instead got: undefined,Expecting string at 0.contentFragment.0.context.0.fullName.0 but instead got: undefined,Expecting null at 0.contentFragment.0.context.0.fullName.1 but instead got: undefined,Expecting string at 0.contentFragment.0.context.0.profilePictureUrl.0 but instead got: undefined,Expecting null at 0.contentFragment.0.context.0.profilePictureUrl.1 but instead got: undefined,Expecting string at 0.contentFragment.0.context.0.username.0 but instead got: undefined,Expecting null at 0.contentFragment.0.context.0.username.1 but instead got: undefined,Expecting null at 0.contentFragment.0.context.1 but instead got: {\"origin\":\"api\"},Expecting string at 0.contentFragment.0.title but instead got: undefined,Expecting string at 0.contentFragment.0.url.0 but instead got: undefined,Expecting null at 0.contentFragment.0.url.1 but instead got: undefined,Expecting undefined at 0.contentFragment.1 but instead got: {\"context\":{\"origin\":\"api\"}},Expecting string at 0.message.0.0.context.email.0 but instead got: undefined,Expecting null at 0.message.0.0.context.email.1 but instead got: undefined,Expecting string at 0.message.0.0.context.fullName.0 but instead got: undefined,Expecting null at 0.message.0.0.context.fullName.1 but instead got: undefined,Expecting string at 0.message.0.0.context.profilePictureUrl.0 but instead got: undefined,Expecting null at 0.message.0.0.context.profilePictureUrl.1 but instead got: undefined,Expecting Timezone at 0.message.0.0.context.timezone but instead got: undefined,Expecting string at 0.message.0.0.context.username but instead got: undefined,Expecting undefined at 0.message.1 but instead got: {\"context\":{\"origin\":\"api\"},\"content\":\"Can you check if John Doe is still working at Acme? If yes, tell me his current position and department within the company. If not, provide details about his new company, his role, department, and experience level.\",\"mentions\":[{\"configurationId\":\"RBh045O2Ak\"}]}"
  }
}

Yes I do it, but I prefer not to share these infos.

Ok, the error seems pretty explicit : your content fragment is expecting a content string.
If you don’t have a content fragment (which is basically an ‘attached file’ to your message), try to remove it from the payload:

payload = {
    "message": {
        "context": { "origin": "api" },
        "content": "Can you check if John Doe is still working at Acme? If yes, tell me his current position and department within the company. If not, provide details about his new company, his role, department, and experience level.",
        "mentions": [{ "configurationId": "RBh045O2Ak" }]
    },
    "blocking": True,
    "title": "My conversation",
    "visibility": "unlisted"
}
1 Like

Also your message does not have enough info from the context, message object should look like this:

{
  "message": {
    "context": {
      "username": "Clement",
      "timezone": "UTC",
      "fullName": "Clement Lacaille",
      "email": "clem@clem.com",
      "profilePictureUrl": "clem.jpg",
      "origin": "api"
    },
    "content": "My message",
    "mentions": [
      {
        "configurationId": "75415241"
      }
    ]
  },
  "contentFragment": {
    "title": "Title",
    "content": "Content"
  }
}

If you fill in the inputs in the doc, the payload will get populated correctly

Also looks like the contentFragment part was set by default in the doc because of the default “api”. We’ve updated the documentation to avoid this issue, sorry about that!

1 Like

Hello Alban,

Thank you for the hint !

payload = {
    "message": {
        "context": { "origin": "api", "email" : "c.lacaille@ogmentia.ai", "fullName" : "clem", "profilePictureUrl" : "www.test.html", "timezone" : "CET", "username" : "clem"},
        "content": "Can you check if John Doe is still working at Acme? If yes, tell me his current position and department within the company. If not, provide details about his new company, his role, department, and experience level.",
        "mentions": [{ "configurationId": "RBh045O2Ak" }]
    },
    "blocking": True,
    "title": "My conversation",
    "visibility": "unlisted"
}

This is minimum requirement to run API route.

Full call :

import requests

url = "https://dust.tt/api/v1/w/your_working_id/assistant/conversations"

payload = {
    "message": {
        "context": { "origin": "api", "email" : "c.lacaille@ogmentia.ai", "fullName" : "clem", "profilePictureUrl" : "www.test.html", "timezone" : "CET", "username" : "clem"},
        "content": "Can you check if John Doe is still working at Acme? If yes, tell me his current position and department within the company. If not, provide details about his new company, his role, department, and experience level.",
        "mentions": [{ "configurationId": "Sid_from_assistant" }]
    },
    "blocking": True,
    "title": "My conversation",
    "visibility": "unlisted"
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "Bearer sk-xxxxxxxxxxx"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

Thank you !