0

I am trying to create a conversation server in Twilio. I created the basic authentication header and I am trying to create a conversation service using a post call to the api exactly as the documentation suggested.

enter image description here

I am getting an error (status 400) and a message that says:

Missing required parameter FriendlyName in the post body

I am sending the friendlyName to the body. I tried changing the content-type to x-www-form-urlencoded and to add data before the {friendlyName: 'name'} but I still getting this message. I also tried to change the body to {data: {friendlyName: 'name'}} and to wrap it all with JSON.stringify but I keep getting this message.

Udi Mazor
  • 1,646
  • 2
  • 15
  • 30

1 Answers1

2

The documentation has a CURL example, I tried it and it worked:

It is application/x-www-form-urlencoded.

Create Conversation

curl -X POST https://conversations.twilio.com/v1/Conversations \
--data-urlencode "MessagingServiceSid=MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
--data-urlencode "FriendlyName=Friendly Conversation" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Alan
  • 10,465
  • 2
  • 8
  • 9
  • Thank you so much Alan It worked. But I still cant do it in Angular or even in the Node.js example. It seems that it does not complete the client.conversation.services. I has no "services" autocompletion not does it have users autocompletion. I will mark your answer as best but I will open a new one about the node.js issue. Hope you can help me with that . – Udi Mazor Feb 23 '21 at 07:44
  • This is my second question about the node.js documentation @Alan : https://stackoverflow.com/questions/66329173/twilio-create-a-conversation-service-or-a-conversation-user-the-node-js – Udi Mazor Feb 23 '21 at 07:59
  • There is a Twilio Conversations JavaScript SDK for the front-end. You are looking at the server side node SDK. Take a look here - https://www.twilio.com/docs/conversations/sdk-download-install. – Alan Feb 23 '21 at 12:57
  • I am doing front-end and want to use node.js as the server. I was trying to create a conversation service using node. I was looking at the node.js documentation and I couldnt use the "service" and "users" Object. – Udi Mazor Feb 23 '21 at 15:10
  • So the Twilio Node SDK is running on the backend, like on Express.js or equivalent? The documentation for creating a conversation instance for Node are all detailed with examples here, https://www.twilio.com/docs/conversations (select Node examples - upper right). I've tried them out as well and they work, so not clear where the issue is. – Alan Feb 24 '21 at 12:10
  • Well, I also took this documentation. – Udi Mazor Feb 24 '21 at 13:01
  • Well Alan, I also took this documentation. But some parts didn't work. For example I couldn't add a user to the conversation client. There was no autocompletion for client.users. I could only do it with http calls. When I write in my app.js command.users then I get an underline warning under the "users" word. Did you use cdn: https://media.twiliocdn.com/sdk/js/conversations/releases/1.0.0/twilio-conversations.min.js and then in the app.js you created the client like this: const client = require('twilio')( process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN, ); – Udi Mazor Feb 24 '21 at 13:12