Cloud Workflows: TypeError: dictionary key must be a string; got: int

1.7k views Asked by At

We have a Cloud Workflows recipe setup like this:

- readWikipedia:
    call: http.post
    args:
        url: https://api-ssl.bitly.com/v4/shorten
        headers:
            Authorization: "Bearer <token>"
            Content-type: "application/json"
        body:
            domain: bit.ly
            long_url: https://cloud.google.com/blog
    result: bitresult
- returnResult:
    return: ${bitresult.body[0]}

And we get an error with: TypeError: dictionary key must be a string; got: int

This is the full response we get:

argument: 'null'
endTime: '2020-10-16T17:40:17.595823493Z'
error:
  context: in step "returnResult"
  payload: '{"message":"TypeError: dictionary key must be a string; got: int","tags":["TypeError"]}'       
name: projects/985596417983/locations/us-central1/workflows/http_post/executions/5bfc56c0-b498-4149-9d28-2c0d51295a9a
startTime: '2020-10-16T17:40:17.297154818Z'
state: FAILED
workflowRevisionId: 000006-e18
1

There are 1 answers

0
Pentium10 On BEST ANSWER

When you get an error, you need to read the error message.

It provides you the context: in step "returnResult"

And the error means that ${bitresult.body[0]} the position 0 doesn't exists in the output.

Bit.ly returns a json document like :

{
   "archived":false,
   "created_at":"2020-10-16T17:40:17+0000",
   "id":"bit.ly/35452TM",
   "link":"//bit .ly/35452TM",
   "long_url":"https://cloud.google.com/blog/",
}

so it doesn't have a body[0] instead it has body.link