0

I am trying to make post a message in a circuit conversation through a Circuit Bot via Rest API call. Please help.

Kamal Garg
  • 107
  • 1
  • 2
  • 9

2 Answers2

0

This is done in two steps :

  1. use the authentication endpoint to obtain a token for your bot
  2. use the messages endpoint (and the token from step 1) to publish the message

Assuming you already have :

  • a bot (client id, client secret)
  • conversation ID (the bot must be a participant of it)

Step 1 : Getting the token

curl -X POST 
  https://<circuitBaseUrl>/oauth/token \
  -H 'Authorization: Basic <base64-encode(<clientId>:<clientSecret>)>' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials&scope=WRITE_CONVERSATIONS'

Get the access_token from the response

Step 2 : Use the REST API to post

curl -X POST \
  https://<circuitBaseUrl>/rest/v2/conversations/<conversationId>/messages \
  -H 'Authorization: Bearer <access_token>' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Host: beta.circuit.com' \
  -d content=hello%20from%20postman

Welcome to the Circuit Developer Community ;-)

samo
  • 354
  • 2
  • 7
0

You have two options:

  1. Use an incoming webhook. This is very simple and does not require OAuth as the webhook url includes token and the specific conversation. Anyone with this url can post to a conversation. There are both option, posting as yourself, or posting as a bot. If you want to post as a bot, then you first need to create a webhook bot using the "Manage Application > Custom Apps" page. For more information see https://www.circuit.com/unifyportalfaqdetail?articleId=164448 and other webhook articles on these FAQ pages.

    Here is s curl example to post a message on an incoming webhook url.

    curl https://circuitsandbox.net/rest/webhooks/incoming/9999999-0b95-4088-b272-5bef80f8e68e -H "Content-Type: application/json" -d '{"text":"hello world"}'

  2. Create an actual OAuth 2.0 bot via "Manage Application > Custom Apps" and use the regular REST API (https://circuitsandbox.net/rest/v2/swagger/ui/index.html). There are several REST examples on github. See https://github.com/circuit/circuit-REST-bot for a simple REST bot example.

Roger Urscheler
  • 774
  • 2
  • 6
  • 11