Yotam Ater
05/03/2025, 7:07 AMimport requests, json
query = "SELECT count(*) FROM Transaction"
headers = {
"Content-Type": "application/json",
"Prefer": "respond-async",
}
r = requests.post(
"https://<ACCOUNT_ID>.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql",
auth=auth,
headers=headers,
data=json.dumps({"q": query})
)
The response includes a Location header like:
Location: https://<ACCOUNT_ID>.suitetalk.api.netsuite.com/services/rest/async/v1/job/702
Step 2 – Poll the job status
job_loc = r.headers["Location"]
status_headers = {
"Content-Type": "application/json",
"Prefer": "transient",
}
j = requests.get(job_loc, auth=auth, headers=status_headers, params={"expandSubResources": "true"})
The response JSON contains a structure like:
{
"completed": true,
"progress": "succeeded",
"task": {
"items": [
{
"links": [
{
"rel": "related",
"href": "https://<ACCOUNT_ID>.suitetalk.api.netsuite.com/services/rest/async/v1/job/702/task/702/result"
}
]
}
]
}
}
Step 3 – Attempt to fetch the actual result
result_loc = j.json()['task']['items'][0]['links'][0]['href']
result_headers = {
"Content-Type": "application/json",
"Prefer": "transient",
}
k = requests.get(result_loc, auth=auth, headers=result_headers)
And this is where it always fails. The response:
<Response [400]>
Error body:
{
"o:errorDetails": [
{
"detail": "The required request header 'Prefer' is missing or invalid. Use this header with one of the required values: transient.",
"o:errorHeader": "Prefer",
"o:errorCode": "INVALID_HEADER"
}
]
}
What I’ve Tried:
• Triple-checking the header name and value ("Prefer": "transient").
• Reordering headers, trying both requests.get(url, headers=...) and Session-based calls.
• Adding other optional headers like "Accept" or removing "Content-Type".
• Waiting a few seconds before the final GET request (in case there’s some propagation delay).
• Different NetSuite API domains: restlets, SuiteTalk, etc. (only the async suiteql result fails).
Reference doc
I’m following this official documentation:
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_161251386312.html#subsect_161278579295
Has anyone else encountered this? Any ideas why the API insists the Prefer header is missing, even though it’s clearly present in the request?
Appreciate any insight. Happy to try variations or diagnostics if needed.
Thanks!Celigo AI
05/03/2025, 7:08 AMAI generated answer (using internal Slack threads):Based on the conversations, it seems like the issue you're facing with the 'Prefer' header error when fetching SuiteQL async results is not directly addressed. However, there are some insights that might be helpful: 1. In the first thread, the user was trying to use a placeholder in their SuiteQL query. The responses indicated that REST web services do not support prepared statements, and the user would need to construct their query string manually. 2. The second thread discussed issues with a '401 Unauthorized' error when adding limit and offset parameters to the SuiteQL URL. The responses suggested that URL parameters are part of the base string used to generate the signature for the authorization header when using Token-Based Authentication (TBA). The user resolved their issue by including the query parameters in the encoded URL used to generate the signature. 3. The third thread involved a user encountering an 'InvalidScope' error when trying to use a generated access token in their SuiteQL query. The responses asked about the scopes requested for the token, suggesting that the issue might be related to the token's permissions. While these threads don't directly solve your issue, they do highlight the importance of correctly constructing your SuiteQL queries and properly handling authentication when using the NetSuite REST API. You might want to double-check your query construction and authentication process to ensure they're correct. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Celigo AI
05/03/2025, 7:08 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.800913155
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.797287703
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.792659283
Celigo AI
05/03/2025, 7:08 AM