How to format url with multiple question marks and ensure that the last query string is used
<p>In my node.js App, I am consuming an API  that accepts a call as follows</p>

<pre><code>http://myapi.com/action?url= https://www.test.com/play?action=jump
</code></pre>

<p>Then based on the parameter passed into the URL parameter(example – ‘action=jump’) the API returns a specific response.</p>

<p>The problem I am experiencing is,  in some cases, the URL sent to the API may already have a question mark with a query string(?song=portrait)</p>

<pre><code>http://myapi.com/action?url= https://www.test.com/play?song=portrait?action=jump
</code></pre>

<p>In this case, the API is sending back the incorrect response because it’s using the very first question mark parameter from the query string. Example <code>?song=portrait</code></p>

<p>Without modifying the API how can I  ensure that the API reads the parameter at the end - example – <code>action=jump</code></p>

<p>Is there a way to escape the first question mark yet keeping a valid URL or how can I use <code>url.format()</code> or <code>url.parse()</code> to solve this problem</p>

<p>I forgot to add that I am already encoding the URL that is passed into the URL parameter.</p>