API Notebooks - passing inline URI parameter values


#1

Hi there

I am busy constructing an API notebook. I am 95% of the way there.
This call works: Notice that the GET parameters are passed as QueryParameters

addressResponse = client.domestic.addresses.get(
  {count:'5', q:'122 Kerwyn'},
  {headers: {
    'Authorization': $1['tokenType'] + ' ' + $1['accessToken'],
    'Accept': 'application/json',
    'Content-Type':'application/x-www-form-urlencoded'
  }});

However this call fails: Notice that the parameter is ‘inline’

addressResponse = client.domestic.addresses.address_id("325595").get
(
  {
    headers:{
      'Authorization': $1['tokenType'] + ' ' + $1['accessToken'],
      'Accept': 'application/json',
      'Content-Type':'application/x-www-form-urlencoded'
    }
  }
);

Now I have tried various different ways to try and make this work but I always get an error.
Here are a few things I have tried …

addressResponse = client.domestic.addresses.address_id.get(
  {address_id:'325595'},
  {headers: {
    'Authorization': $1['tokenType'] + ' ' + $1['accessToken'],
    'Accept': 'application/json',
    'Content-Type':'application/x-www-form-urlencoded'
  }});

I have also tried to replace the ‘.’ with ‘/’ and so forth but I always get the same error.
This is the error I am getting:

"
TypeError: Could not parse response: Unexpected token ↵

at https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:13180
at j (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30058)
at k (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30155)
at https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30264
at j (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30058)
at k (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30155)
at https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:30:30264
at XMLHttpRequest. (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:22:21534)
at XMLHttpRequest. (https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:22:21380)
at https://api-notebook.anypoint.mulesoft.com/scripts/api-notebook.js:22:21754
"

Please could you advise how I go about correctly passing inline parameters.

Thank you


#2

It looks like the response is invalid JSON. Can you check the response in your dev tools and see what it looks like? Most likely you’re just missing a comma or closing double quote.


#3

Hey guys thanks we figured it out:

Missing the first nullable query parameter in the get method…

addressResponse = client.domestic.addresses.address_id(“325595”).get(null,{
headers:{
‘Authorization’: $1[‘tokenType’] + ’ ’ + $1[‘accessToken’],
‘Accept’: ‘application/json’,
‘Content-Type’:‘application/x-www-form-urlencoded’
}
});