Hi Guys, I'm working on a small project though rec...
# suitetalkapi
w
Hi Guys, I'm working on a small project though recently I've been facing a slight technical issue that I don't seem to get by. I'm using Oauth1.0 to authenticate my requests that I'm sending using python's requests library. I wrote both header and signature creation functions which works perfectly well with a sample base URL as: "https://46xxxx.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder". This helps me retrieve sales order records from my account, however as we know , NetSuite paginates its responses with a limit of 1000 records per page. This now brings me to my main issue where URL parameters are involved. Specifically the limit and offset parameters, for me to send another request to retrieve the next page records, I'll need to specify a limit of 1000 and an offset of 1000 as well. but sending my request with this call_url I get an invalid login error. my thinking is that i have to figure out how to include the parameters in the signature encoding for the authorization header but if I try this it still fails. This is because if I send similar requests using postman software it works perfectly, having checked the checkbox saying "Encode parameters in the authorization header". I've pushed my authentication scripts for this section to this GitHub repo of mine: https://github.com/willywairagu/suitetalk_auth. I'd really appreciate any input that you all could have to this challenge I'm having.
b
same problem as the last thread you found
you are constructing the 3.4.1. Signature Base String wrong
go though the documentation and construct it correctly
or do the easy thing and use Requests-OAuthlib
w
it has finally worked😁... indeed my signature creation function was wrong......
Thank you soo much for that reference
y
Copy code
import requests
import json
from requests_oauthlib import OAuth1

client_key = 'xx'
client_secret = 'xx'
access_token = 'xx'
access_token_secret = 'xx'
realm = 'xx'
oauth = OAuth1(client_key, client_secret, access_token, access_token_secret,
               signature_method='HMAC-SHA256', realm=realm)

    headers = {
      'prefer': 'transient',
      'Content-Type': 'application/json',
      'Cookie': 'NS_ROUTING_VERSION=LAGGING'
    }
    url = f"<https://xxxxxx.suitetalk.api.netsuite.com/services/rest/record/v1/employee/{id}>"
   
 response = requests.request("POST", url = url, auth=oauth, headers=headers, payload=payload)
this simple code works fine, I have been using it at multiple places
w
Hi @Yogi... your script is a life saver man, i think i had over complicated my technique....
🙇‍♂️ 1
i still got to solve the issue i was having earlier, that's why i took long to reply but thank you soo much💯