Skip to content

Conversation

@WillieRuemmele
Copy link
Contributor

@WillieRuemmele WillieRuemmele commented Aug 14, 2024

What does this PR do?
adds api request rest command to send API requests to an org
cloned from Cristian's plugin
in beta state for feedback period

What issues does this PR fix or reference?
@W-16451172@

@WillieRuemmele WillieRuemmele changed the title Wr/org api rest Wr/api request rest Aug 16, 2024
Copy link
Contributor

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure the file-body isn't working. I couldn't get the --body - trick to work, either.

Maybe that's another point in favor of making --file and --body separate flags?

Comment on lines 26 to 31
// TODO: getting a false positive from this eslint rule.
// summary is already set in the org flag.
// eslint-disable-next-line sf-plugin/flag-summary
'target-org': Flags.requiredOrg({
helpValue: 'username',
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: getting a false positive from this eslint rule.
// summary is already set in the org flag.
// eslint-disable-next-line sf-plugin/flag-summary
'target-org': Flags.requiredOrg({
helpValue: 'username',
}),
'target-org': Flags.requiredOrg(),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the suggestion is works ok. I think the help output is fine without the override. Was there something that bothered you about the flag's defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just dropped this in from Cristian's plugin 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, probably something wrong in my plugin or was fixed in latest deps (mine is a bit stale)

}),
};

private static getHeaders(keyValPair: string[]): Headers {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a function and not a static method so its testable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and will likely be useful in other commands!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another benefit of having a fn is that you could put it as the parse prop on the --header flag so that if people have bad headers it fails sooner (avoiding org re-auth, etc)


await org.refreshAuth();

const url = `${org.getField<string>(Org.Fields.INSTANCE_URL)}/${args.endpoint}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anything in rest that's not in services/data/vXX.0 ? If not, why not default those (or use Connection) and only make people type the remaining url fragments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another idea: passing this to Url constructor might do a nice validation that what they typed for endpoint, when combined with the instance, is a valid URL (and maybe do THAT before org re-auth)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, there's opinions on how similar it should be to curl - that's a good point, I'm not sure I'd be annoyed if I would have to type that out every time, or think it makes sense... it's in "beta" so we'll be able to gather feedback and adjust

@mshanemc
Copy link
Contributor

mshanemc commented Aug 20, 2024

QA notes:

✅ bunch of GETs against the various endpoints, including sobject record used below

🎨 it's not obvious, given the addition of the /data/etc how to ask, "what are all the endpoints". the command is sf api request rest / so maybe that should be an example?

🎨 this does what I think it should to the record in the org
sf api request rest -o hub /sobjects/account/0016A00000540lUQAQ --body "{\"Description\": \"foo\"}" --method PATCH
but it doesn't show me the output.

[in that example, there is no response body, but it's not clear that that's actually the case from the command. Maybe a placeholder or warning that there is no body? I can see the empty logline but wouldn't have guessed that was what was happening]

sf api request rest -o hub /sobjects/account --body "{\"Name\": \"TestAcctQA\"}" --method POST
✅ did create, shows expected json response
✅ pipe echo "{\"Name\": \"TestAcctQA\"}" | sf api request rest -o hub /sobjects/account --body - --method POST
✅ json from a file
✅ custom api version

✅ --stream-to-file

@mshanemc mshanemc merged commit ee7b02e into main Aug 20, 2024
@mshanemc mshanemc deleted the wr/orgApiRest branch August 21, 2024 15:24
@iowillhoit iowillhoit changed the title Wr/api request rest W-16451172 Wr/api request rest Jan 27, 2025
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

Successfully merging this pull request may close these issues.

4 participants