Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rank API calls failing #335

Open
Andr3wid opened this issue Jan 20, 2022 · 2 comments
Open

Rank API calls failing #335

Andr3wid opened this issue Jan 20, 2022 · 2 comments

Comments

@Andr3wid
Copy link

Andr3wid commented Jan 20, 2022

Hello there 馃憢

I'm currently trying to use the rankIssues(body) method as follows:

// code exists inside a function that answers an HTTP-request
const jiraClient = new JiraApi({ ... });

    const rankRequestBody = {
      issues: ['ISSUE-10'],
      rankBeforeIssue: 'ISSUE-12',
      rankCustomFieldId: 10057,
    };
	
    return jiraClient.rankIssues(rankRequestBody);

The rankIssues call fails with the following reason:

Error: Can not instantiate value of type [simple type, class com.atlassian.greenhopper.api.rest.bean.IssueRankRequestBean] from JSON String; no single-String constructor/factory method
    at JiraApi.doRequest (/path/to/project/node_modules/jira-client/lib/jira.js:333:15)

The error seems to indicate that the request-body is malformed according to this source. The exact same request-body works when submitted through postman though. After some digging, it seems that the request body gets stringified twice or something. Indeed if I directly pass rankRequestBody without stringifying it (or changing the expected type to object in the corresponding type-declaration), the call works. 馃帀

Is the expected body something different than the stringified request-body, or is this a typing issue?

EDIT:
Intercepted the doRequest() method and inspected the options before they are submitted.

When passing `rankRequestBody` as `object` (--> request works):
{
  "auth": {
    /* Auth related stuff */
  },
  "rejectUnauthorized": true,
  "method": "PUT",
  "uri": "https://my-base-uri.xyz/rest/agile/1.0/issue/rank",
  "json": true,
  "body": {
    "issues": ["ISSUE-10"],
    "rankBeforeIssue": "ISSUE-12",
    "rankCustomFieldId":10057 
  }
}
When passing `rankRequestBody` as `string`ified version (as noted in comments and types; --> request fails):
{
  "auth": {
    /* Auth related stuff */
  },
  "rejectUnauthorized": true,
  "method": "PUT",
  "uri": "https://my-base-uri.xyz/rest/agile/1.0/issue/rank",
  "json": true,
  "body": "{\"issues\":[\"ISSUE-10\"],\"rankBeforeIssue\":\"ISSUE-12\",\"rankCustomFieldId\":10057}"
}
@sawilde
Copy link

sawilde commented Jul 23, 2022

I came to report the same issue but instead I will 馃憤 this

my workaround was to do this

const body = {
  rankBeforeIssue: page.issues[0].key,
  issues: [issueKey],
};
return jira.rankIssues(body as unknown as string)

@Seth10001
Copy link
Contributor

I'm under the impression that it's intended to be passed as a string since the jsdoc indicates that here:

* @param {string} body - value to set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants