Closed akamuraasai closed 4 years ago
His @akamuraasai
could you please provide a log from your API request, what params you pass etc will help to identify the issue
Sure.
The request:
curl -X POST \
https://api.connectycube.com/chat/Dialog \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'CB-Token: <hidden>' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 155' \
-H 'Content-Type: application/json' \
-H 'Host: api.connectycube.com' \
-H 'cache-control: no-cache' \
-d '{
"type": 2,
"name": "Custom Data Test",
"occupants_ids": "153393",
"data": {
"roles": [
{
"user_id": 153393,
"role": "user"
}
]
}
}'
The response:
{
"_id": "5e1751dbca8bf4060b85a7ed",
"admins_ids": [],
"created_at": "2020-01-09T16:16:27Z",
"description": null,
"last_message": null,
"last_message_date_sent": null,
"last_message_id": null,
"last_message_user_id": null,
"name": "Custom Data Test",
"occupants_ids": [
153393
],
"photo": null,
"pinned_messages_ids": [],
"type": 2,
"updated_at": "2020-01-09T16:16:27Z",
"user_id": 153393,
"unread_messages_count": 0,
"xmpp_room_jid": "896_5e1751dbca8bf4060b85a7ed@muc.chat.connectycube.com"
}
GET /data/roles
{
"class_name": "roles",
"skip": 0,
"limit": 100,
"items": []
}
This creates the Dialog as it can be seen in the response above, but no Custom Data is inserted. Quoting from API docs:
Custom parameters Dialogs can have additional (or custom) parameters to store additional information. These parameters can be used as a value for retriving dialogs.
To start using custom parameters, an additional schema of these parameters should be created first. This is a CustomObjects empty class with all needed fields. These fields will be additional parameters for a dialog.
To set additional parameters to dialog, the following parameters should be used in the request of dialog creation:
data[class_name] - should contain CustomObjects class name created for additional parameters data[field1] data[...] data[fieldN]
So am I doing something wrong? Maybe I've misinterpreted the documentation. Can you send me a example with the correct way to do this?
Instead of passing it as
"data": {
"roles": [
{
"user_id": 153393,
"role": "user"
}
]
}
it should be
"data": {
"class_name": "roles",
"user_id": 153393,
"role": "user"
}
so it will be in convenience with documentation
And here
GET /data/roles
{
"class_name": "roles",
"skip": 0,
"limit": 100,
"items": []
}
it is ok, as it will not create any data records, but instead assign custom parameters to a chat dialog
I see, so I have to send the className as a parameter. Okay, seems fine. This forces me to only send data as object and never as an array, like I was doing before, right? Or is that any way to send an array of users in this specific case? Thanks.
right, just send as object with all your custom parameters + class name , not array
"Or is that any way to send an array of users in this specific case?"
I think you can have a custom field 'users' with a string value of comma separated users ids
Yeah, I've just used an string array in the class and this did the work for me. Thank you for all the help, @DaveLomber. I'm closing this issue.
Hi, I'm trying to insert some extra data into the Dialog based on the API documentation, passing the
data
field to the body's request but no record is inserted into the Custom Data as I can see in the painel. I don't know if I'm missing something or it's something with the API, can someone explain me in details how to do this correctly?