Node-slack-sdk: invalid_array_arg when trying to change the user status

Created on 30 May 2017  路  6Comments  路  Source: slackapi/node-slack-sdk

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Description

I'm trying to update the status of my bot using the web client, but it fails with an error: invalid_array_arg

Steps to reproduce:

import * as SlackClient from '@slack/client';

const slackWebClient = new SlackClient.WebClient(botToken);
slackWebClient.users.profile.set({ 
  profile: {
     status_text: 'riding a train',
     status_emoji: ':mountain_railway:'
  }
});

Expected result:

Status of my bot is changed

Actual result:

It fails with an error invalid_array_arg

Attachments:

error: Response not OK:  invalid_array_arg
Unhandled rejection Error: invalid_array_arg
    at handleHttpResponse (C:\Projects\slack-app\node_modules\@slack\client\lib\clients\transports\call-transport.js:103:17)
    at handleTransportResponse (C:\Projects\slack-app\node_modules\@slack\client\lib\clients\transports\call-transport.js:153:19)
    at apply (C:\Projects\slack-app\node_modules\lodash\lodash.js:499:17)
    at wrapper (C:\Projects\slack-app\node_modules\lodash\lodash.js:5356:16)
    at Request.handleRequestTranportRes (C:\Projects\slack-app\node_modules\@slack\client\lib\clients\transports\request.js:20:5)
    at apply (C:\Projects\slack-app\node_modules\lodash\lodash.js:499:17)
    at Request.wrapper [as _callback] (C:\Projects\slack-app\node_modules\lodash\lodash.js:5356:16)
    at Request.self.callback (C:\Projects\slack-app\node_modules\request\request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (C:\Projects\slack-app\node_modules\request\request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (C:\Projects\slack-app\node_modules\request\request.js:1091:12)
    at IncomingMessage.g (events.js:291:16)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
bug good first issue

Most helpful comment

thanks for the bug report, i was able to reproduce, so i'm labeling it accordingly.

here is a debug dump i captured while reproducing:

REQUEST { url: 'https://slack.com/api/users.profile.set',
  headers: { 'User-Agent': '@slack:client/3.10.0 darwin/16.6.0 node/4.7.0' },
  form: 
   { profile: 
      { status_text: 'riding a train',
        status_emoji: ':mountain_railway:' },
     token: 'xoxb-REDACTED' },
  callback: [Function: wrapper],
  method: 'POST' }
REQUEST make request https://slack.com/api/users.profile.set
REQUEST onRequestResponse https://slack.com/api/users.profile.set 200 { 'content-type': 'application/json; charset=utf-8',
  'content-length': '40',
  connection: 'close',
  'access-control-allow-origin': '*',
  date: 'Mon, 19 Jun 2017 17:54:16 GMT',
  'referrer-policy': 'no-referrer',
  server: 'Apache',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  vary: 'Accept-Encoding',
  'x-content-type-options': 'nosniff',
  'x-slack-backend': 'h',
  'x-slack-req-id': '783239fc-d103-4511-8616-4afaeb69d4fc',
  'x-xss-protection': '0',
  'x-cache': 'Miss from cloudfront',
  via: '1.1 d5da2738774b6f83465e13845679d084.cloudfront.net (CloudFront)',
  'x-amz-cf-id': 'bsZ50ZBkUjW9AYnqQpvqhtu6N2jqLr4W7kRRPLBXom4f4iQBPr7Fbw==' }
REQUEST reading response's body
REQUEST finish init function https://slack.com/api/users.profile.set
REQUEST response end https://slack.com/api/users.profile.set 200 { 'content-type': 'application/json; charset=utf-8',
  'content-length': '40',
  connection: 'close',
  'access-control-allow-origin': '*',
  date: 'Mon, 19 Jun 2017 17:54:16 GMT',
  'referrer-policy': 'no-referrer',
  server: 'Apache',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  vary: 'Accept-Encoding',
  'x-content-type-options': 'nosniff',
  'x-slack-backend': 'h',
  'x-slack-req-id': '783239fc-d103-4511-8616-4afaeb69d4fc',
  'x-xss-protection': '0',
  'x-cache': 'Miss from cloudfront',
  via: '1.1 d5da2738774b6f83465e13845679d084.cloudfront.net (CloudFront)',
  'x-amz-cf-id': 'bsZ50ZBkUjW9AYnqQpvqhtu6N2jqLr4W7kRRPLBXom4f4iQBPr7Fbw==' }
REQUEST end event https://slack.com/api/users.profile.set
REQUEST has body https://slack.com/api/users.profile.set 40
REQUEST emitting complete https://slack.com/api/users.profile.set
error: Response not OK:  invalid_array_arg
[Error: invalid_array_arg]

it looks like the value for profile is getting serialized as profile[status_text]=...&profile[status_message]=... rather than profile={"status_text":"...","status_message":"..."}. This serialization is done for similar greater-than-one level JSON arguments in the assignApiArgs() function. My suggested fix is to add an additional condition in there for when key === 'profile'. I can probably get around to this in the next week or so, but PRs welcome too!

All 6 comments

I am experiencing the same error, invalid_array_arg while trying to update the profile of an slack user.

The code i am using is this:
var opts = { user : userprofile.user, profile : userprofile.profile }; console.log(opts); web.users.profile.set(opts, function (err, userprofile) { if (err) { console.log("Err: " +err) } else { return callback(info); } });``

thanks for the bug report, i was able to reproduce, so i'm labeling it accordingly.

here is a debug dump i captured while reproducing:

REQUEST { url: 'https://slack.com/api/users.profile.set',
  headers: { 'User-Agent': '@slack:client/3.10.0 darwin/16.6.0 node/4.7.0' },
  form: 
   { profile: 
      { status_text: 'riding a train',
        status_emoji: ':mountain_railway:' },
     token: 'xoxb-REDACTED' },
  callback: [Function: wrapper],
  method: 'POST' }
REQUEST make request https://slack.com/api/users.profile.set
REQUEST onRequestResponse https://slack.com/api/users.profile.set 200 { 'content-type': 'application/json; charset=utf-8',
  'content-length': '40',
  connection: 'close',
  'access-control-allow-origin': '*',
  date: 'Mon, 19 Jun 2017 17:54:16 GMT',
  'referrer-policy': 'no-referrer',
  server: 'Apache',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  vary: 'Accept-Encoding',
  'x-content-type-options': 'nosniff',
  'x-slack-backend': 'h',
  'x-slack-req-id': '783239fc-d103-4511-8616-4afaeb69d4fc',
  'x-xss-protection': '0',
  'x-cache': 'Miss from cloudfront',
  via: '1.1 d5da2738774b6f83465e13845679d084.cloudfront.net (CloudFront)',
  'x-amz-cf-id': 'bsZ50ZBkUjW9AYnqQpvqhtu6N2jqLr4W7kRRPLBXom4f4iQBPr7Fbw==' }
REQUEST reading response's body
REQUEST finish init function https://slack.com/api/users.profile.set
REQUEST response end https://slack.com/api/users.profile.set 200 { 'content-type': 'application/json; charset=utf-8',
  'content-length': '40',
  connection: 'close',
  'access-control-allow-origin': '*',
  date: 'Mon, 19 Jun 2017 17:54:16 GMT',
  'referrer-policy': 'no-referrer',
  server: 'Apache',
  'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
  vary: 'Accept-Encoding',
  'x-content-type-options': 'nosniff',
  'x-slack-backend': 'h',
  'x-slack-req-id': '783239fc-d103-4511-8616-4afaeb69d4fc',
  'x-xss-protection': '0',
  'x-cache': 'Miss from cloudfront',
  via: '1.1 d5da2738774b6f83465e13845679d084.cloudfront.net (CloudFront)',
  'x-amz-cf-id': 'bsZ50ZBkUjW9AYnqQpvqhtu6N2jqLr4W7kRRPLBXom4f4iQBPr7Fbw==' }
REQUEST end event https://slack.com/api/users.profile.set
REQUEST has body https://slack.com/api/users.profile.set 40
REQUEST emitting complete https://slack.com/api/users.profile.set
error: Response not OK:  invalid_array_arg
[Error: invalid_array_arg]

it looks like the value for profile is getting serialized as profile[status_text]=...&profile[status_message]=... rather than profile={"status_text":"...","status_message":"..."}. This serialization is done for similar greater-than-one level JSON arguments in the assignApiArgs() function. My suggested fix is to add an additional condition in there for when key === 'profile'. I can probably get around to this in the next week or so, but PRs welcome too!

@DominikPalo @aoberoi I see same picture with:

var WebClient = require('@slack/client').WebClient;

var web = new WebClient('xoxp-........-18377996225-213988902994-9bf9fc28........');

var message = {
  "text": "Would you like to play a game?",
  "attachments": [
    {
      "text": "Choose a game to play",
      "fallback": "You are unable to choose a game",
      "callback_id": "wopr_game",
      "color": "#3AA3E3",
      "attachment_type": "default",
      "actions": [
        {
          "name": "game",
          "text": "Chess",
          "type": "button",
          "value": "chess"
        },
        {
          "name": "game",
          "text": "Falken's Maze",
          "type": "button",
          "value": "maze"
        }
      ]
    }
  ]
};

web.chat.postMessage('#mychannel', message, function(err, res) {
  if (err) {
    console.log('Error:', err);
  } else {
    console.log('Message sent: ', res);
  }
});

Got Error:

error: Response not OK:  invalid_array_arg
Error: Error: invalid_array_arg
    at handleHttpResponse (/Users/slava/project/GitProFlow-2/node_modules/@slack/client/lib/clients/transports/call-transport.js:103:17)
    at handleTransportResponse (/Users/slava/project/GitProFlow-2/node_modules/@slack/client/lib/clients/transports/call-transport.js:153:19)
    at apply (/Users/slava/project/GitProFlow-2/node_modules/lodash/lodash.js:499:17)
    at wrapper (/Users/slava/project/GitProFlow-2/node_modules/lodash/lodash.js:5356:16)
    at Request.handleRequestTranportRes (/Users/slava/project/GitProFlow-2/node_modules/@slack/client/lib/clients/transports/request.js:20:5)
    at apply (/Users/slava/project/GitProFlow-2/node_modules/lodash/lodash.js:499:17)
    at Request.wrapper [as _callback] (/Users/slava/project/GitProFlow-2/node_modules/lodash/lodash.js:5356:16)
    at Request.self.callback (/Users/slava/project/GitProFlow-2/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/Users/slava/project/GitProFlow-2/node_modules/request/request.js:1171:10)

Version:

  "name": "@slack/client",
  "version": "3.10.0",
  "description": "A library for creating a Slack client",

@aoberoi should I create new issue or is it related?

@slavahatnuke would you be able to capture a similar dump to above by running your script with the environment variable NODE_DEBUG=request set?

@slavahatnuke on closer inspection, i think i see the issue. you're calling the method with the wrong arguments. it should be: web.chat.postMessage('#mychannel, message.text, { attachments: message.attachments }, callback) (text is the second argument, and all optional arguments including attachments are put in the third argument)

I'm experiencing the same issue when updating the status

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aoberoi picture aoberoi  路  12Comments

amkoehler picture amkoehler  路  13Comments

jayjanssen picture jayjanssen  路  13Comments

kurisubrooks picture kurisubrooks  路  36Comments

freder picture freder  路  12Comments