Optional parameter in Magento 2 REST APIMagento API - most efficient way to get list of products and their name/url/image_urlMagento 2: Getting a Product URL from the APIMagento 2 API “self” route: pass customer ID as data parameterCustom webapi attribute explanationMagento 2.1.1 Rest API Update price onlyMagento 2.0 REST/SOAP API - how to retrieve Special PriceHow can I create a plugin class for product save method when it is called from API?Magento 2 token integration errorCustom REST API returns duplicate “response” tagI have created A new sample REST Api to GET method, Giving Consumer is not authorized to access the resource error
Boss wants me to falsify a report. How should I document this unethical demand?
Old short story, same personalities, differing planes of existence
What is the most important source of natural gas? coal, oil or other?
What is the object moving across the ceiling in this stock footage?
What is the difference between “/private/var/vm” and “/vm”?
Windows 10 Programs start without visual Interface
Is it possible to play as a necromancer skeleton?
How do I align equations in three columns, justified right, center and left?
Command to Search for Filenames Exceeding 143 Characters?
Employer demanding to see degree after poor code review
Employer asking for online access to bank account - Is this a scam?
Does linking adjectives allow you to talk about multiple variations of something?
Mother abusing my finances
Approximate solution : factorial and exponentials
How to make a crossed out leftrightarrow?
I unknowingly submitted plagiarised work
Placing bypass capacitors after VCC reaches the IC
Binary Search in C++17
Were pens caps holes designed to prevent death by suffocation if swallowed?
What is the difference between nullifying your vote and not going to vote at all?
Array Stutter Implementation
How can people dance around bonfires on Lag Lo'Omer - it's darchei emori?
What are the benefits of cryosleep?
How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?
Optional parameter in Magento 2 REST API
Magento API - most efficient way to get list of products and their name/url/image_urlMagento 2: Getting a Product URL from the APIMagento 2 API “self” route: pass customer ID as data parameterCustom webapi attribute explanationMagento 2.1.1 Rest API Update price onlyMagento 2.0 REST/SOAP API - how to retrieve Special PriceHow can I create a plugin class for product save method when it is called from API?Magento 2 token integration errorCustom REST API returns duplicate “response” tagI have created A new sample REST Api to GET method, Giving Consumer is not authorized to access the resource error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a API route like,
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
As you can see this route has a required parameter productId. Is it possible to add a optional parameter to this route?
Something like,
<route url="/V1/product/:productId/:optionalParam" method="GET">
Thanks in advance!!
magento2 api
add a comment |
I have a API route like,
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
As you can see this route has a required parameter productId. Is it possible to add a optional parameter to this route?
Something like,
<route url="/V1/product/:productId/:optionalParam" method="GET">
Thanks in advance!!
magento2 api
add a comment |
I have a API route like,
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
As you can see this route has a required parameter productId. Is it possible to add a optional parameter to this route?
Something like,
<route url="/V1/product/:productId/:optionalParam" method="GET">
Thanks in advance!!
magento2 api
I have a API route like,
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
As you can see this route has a required parameter productId. Is it possible to add a optional parameter to this route?
Something like,
<route url="/V1/product/:productId/:optionalParam" method="GET">
Thanks in advance!!
magento2 api
magento2 api
edited Feb 15 at 7:06
Vinoth S
asked Feb 14 at 13:32
Vinoth SVinoth S
7510
7510
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
It is possible to pass an optional param but not like this <route url="/V1/product/:productId/:optionalParam" method="GET">
you can pass it with the endpoint by using a question mark(?)
Suppose your endpoint is this: http://www.example.com/rest/V1/product/3 and if you want to pass some optional parameter, you can pass it like this:
http://www.example.com/rest/V1/product/3?optional_param=8
you can retrieve it like this:
$optional = $this->_request->getParam('optional_param');
add a comment |
I may be wrong but I don't think you can declare a specific parameter as optional from within the xml file, though you can declare your routes in such a way that the parameter becomes optional.
For example if you changed your xml to:
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/product/:productId/:optionalParam" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
So long as the underlying method supports it being optional, something like:
public function sample($productId, $optionalParam = null)
This allows the code defined in that method to treat $optionalParam as optional.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261808%2foptional-parameter-in-magento-2-rest-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is possible to pass an optional param but not like this <route url="/V1/product/:productId/:optionalParam" method="GET">
you can pass it with the endpoint by using a question mark(?)
Suppose your endpoint is this: http://www.example.com/rest/V1/product/3 and if you want to pass some optional parameter, you can pass it like this:
http://www.example.com/rest/V1/product/3?optional_param=8
you can retrieve it like this:
$optional = $this->_request->getParam('optional_param');
add a comment |
It is possible to pass an optional param but not like this <route url="/V1/product/:productId/:optionalParam" method="GET">
you can pass it with the endpoint by using a question mark(?)
Suppose your endpoint is this: http://www.example.com/rest/V1/product/3 and if you want to pass some optional parameter, you can pass it like this:
http://www.example.com/rest/V1/product/3?optional_param=8
you can retrieve it like this:
$optional = $this->_request->getParam('optional_param');
add a comment |
It is possible to pass an optional param but not like this <route url="/V1/product/:productId/:optionalParam" method="GET">
you can pass it with the endpoint by using a question mark(?)
Suppose your endpoint is this: http://www.example.com/rest/V1/product/3 and if you want to pass some optional parameter, you can pass it like this:
http://www.example.com/rest/V1/product/3?optional_param=8
you can retrieve it like this:
$optional = $this->_request->getParam('optional_param');
It is possible to pass an optional param but not like this <route url="/V1/product/:productId/:optionalParam" method="GET">
you can pass it with the endpoint by using a question mark(?)
Suppose your endpoint is this: http://www.example.com/rest/V1/product/3 and if you want to pass some optional parameter, you can pass it like this:
http://www.example.com/rest/V1/product/3?optional_param=8
you can retrieve it like this:
$optional = $this->_request->getParam('optional_param');
answered Feb 18 at 4:31
NIDNID
737313
737313
add a comment |
add a comment |
I may be wrong but I don't think you can declare a specific parameter as optional from within the xml file, though you can declare your routes in such a way that the parameter becomes optional.
For example if you changed your xml to:
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/product/:productId/:optionalParam" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
So long as the underlying method supports it being optional, something like:
public function sample($productId, $optionalParam = null)
This allows the code defined in that method to treat $optionalParam as optional.
add a comment |
I may be wrong but I don't think you can declare a specific parameter as optional from within the xml file, though you can declare your routes in such a way that the parameter becomes optional.
For example if you changed your xml to:
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/product/:productId/:optionalParam" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
So long as the underlying method supports it being optional, something like:
public function sample($productId, $optionalParam = null)
This allows the code defined in that method to treat $optionalParam as optional.
add a comment |
I may be wrong but I don't think you can declare a specific parameter as optional from within the xml file, though you can declare your routes in such a way that the parameter becomes optional.
For example if you changed your xml to:
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/product/:productId/:optionalParam" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
So long as the underlying method supports it being optional, something like:
public function sample($productId, $optionalParam = null)
This allows the code defined in that method to treat $optionalParam as optional.
I may be wrong but I don't think you can declare a specific parameter as optional from within the xml file, though you can declare your routes in such a way that the parameter becomes optional.
For example if you changed your xml to:
<route url="/V1/product/:productId" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/product/:productId/:optionalParam" method="GET">
<service class="VendorSampleApiSampleInterface" method="sample"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
So long as the underlying method supports it being optional, something like:
public function sample($productId, $optionalParam = null)
This allows the code defined in that method to treat $optionalParam as optional.
answered May 21 at 12:00
AdamAdam
314
314
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261808%2foptional-parameter-in-magento-2-rest-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown