Watson Workspace will no longer be available after February 28, 2019. Learn more.

Developers

Sending messages and verification in python

Comments

8 comments

  • Avatar
    Jürgen Schmidt

    Hi Marc,

    you mean you were able to authenticate your app and get a jwt and now you want to send a message under this app identity into an existing space.

    You have to send a POST request to <server>/v1/spaces/{space_id}/messages

    Header:

    Authorization: Bearer {access_token}

    Content-Type: application/json

    Body:
    {
        "type": "appMessage",
        "version": 1,
        "annotations": [
            {
                "type": "generic",
                "version": 1,
                "text": "<enter your text here>"         
            }
        ]
    }

    See also https://workspace.ibm.com/developer/docs#message

     

  • Avatar
    Marc Valaee (Edited )

    Hi Jürgen,

     

    that is my code so far: http://pastebin.com/FiF4LUKN

    i still get the http error 400. Which means the body is not properly formatted..

     

    Using a rest client with the json body you provided i get an http error 500.

    I use the following url -> https://api.watsonwork.ibm.com/v1/spaces/58009fdfe4b0590fdf0d0042/messages

  • Avatar
    Jürgen Schmidt

    it looks ok to me on the fist look. Even the slightly different url "teams" versus "v1/spaces" should be ok for now. But I have to confess I am no Python friend and don't use it often.

  • Avatar
    Marc Valaee

    There seams to be a problem with my token, if i use my jwt token from the browser it works...

  • Avatar
    Marc Valaee (Edited )

    I found the error, pretty stupid. Token seams to be invalid, if the app is not added to the space. makes sense.. my bad! Embarrassing D:

    You know how to generate a verification hash ?

  • Avatar
    JARED WALLACE

    Reviving a dead thread here, I know. Marc, did you ever figure this out? I'm using the following, but it's not working, and the error messages are still not quite helpful:

    challenge = body['challenge']
    msg ={}
    msg['response'] = challenge
    json_msg = json.dumps(msg)
    hash = hmac.new(webhook_key, json_msg, hashlib.sha256).hexdigest()

    I send json_msg as the body, and add the headers "X-OUTBOUND_TOKEN: [hash]" and "content-type: application/json"

    Error message from firebug:

    {"timestamp":"Tue Dec 13 20:13:06 UTC 2016","status":500,"reason":"Internal Server Error","errorId":8,"exception":"com.ibm.toscana.micros.appregistry.common.exceptions.OutboundOperationErrorException","message":"internal error on update of outbound-webhook: null","userMessage":"App operation failed because of error on outbound-webhook operation!","path":"/api/v1/apps/7cfa90b9-8aa9-4b2f-abf4-42c347fe7d51"}

     

  • Avatar
    Jürgen Schmidt (Edited )

    Jared, have you reached your code and were you able to debug and able to verify the incoming token already?

  • Avatar
    JARED WALLACE

    Well I was able to grab the reponse via curl, and it was good, but I got tired of fussing with it.

    I ended up standing a new Django instance up, and letting django handle it. Had to do some jiggering to work around IBM java not being updated enough to accept "let's encrypt" root from DST, but I think I have it all in place - waiting on dns changes to propagate.

    I know it was mentioned elsewhere that better error messages are forthcoming, which is awesome.

    I'm still not sure what triggered the issue - I suspect a formatting error of some kind on my part, or a quirk of the python libraries used (baseHTTPserver and the ssl wrap_socket)

Please sign in to leave a comment.