ehmad11 / netsuite-rest

Make requests to Oracle NetSuite REST Web Services.
MIT License
50 stars 18 forks source link

problem with realm and URL #1

Closed pillarshadow closed 4 years ago

pillarshadow commented 4 years ago

My realm needs to look something like this: 1234567_SB1.

If I set that as the realm, it tries to make requests to this url: https://1234567_sb1.suitetalk.api.netsuite.com/

but the URL needs to be 1234567-sb1.suitetalk.api.netsuite.com

The URL needs to have a hyphen in it while the realm needs to have an underscore.

I think there should be an option to specify the url and the realm separately if you want to.

I'm thinking maybe if there were something like a base_url option and then if it isn't specified, continue to just assume it is safe to use the realm in the url but if it is specified, use the base_url.

ehmad11 commented 4 years ago

hi,

this is an interesting case, but i don't have any realms with underscores so i can't test it, i don't know how the signatures will work in your case

can you try modifying netsuite-rest.js locally:

  1. add following line in constructor ( after line 13)

    this.base_url = options.base_url;

  2. replace following line ( # 50)

    let uri = https://${this.realm}.suitetalk.api.netsuite.com/services/rest/${path}${url}

with this:

this.base_url ? uri = `${this.base_url}/services/rest/${path}` : uri = `https://${this.realm}.suitetalk.api.netsuite.com/services/rest/${path}`

^ please try, let me know if it works

pillarshadow commented 4 years ago

Okay, I added this line to the constructor after line 13:

this.base_url = options.base_url;

Then I tried replacing line 50 with the line of code you had but it didn't quite work.

I think it was just because of the way uri was being set with the ternary operator.

I instead used this line and it works:

let uri = this.base_url ? `${this.base_url}/services/rest/${path}` : `https://${this.realm}.suitetalk.api.netsuite.com/services/rest/${path}`

Also, thank you for making this library!

ehmad11 commented 4 years ago

great! it worked, i have committed these changes