Netsuite script 2.0 java.lang.StackOverflowError - erp

I have a script that import / create the orders from a sales channel (shopify) via the API. I create a netsuite module that connects to an API that returns the fedex shipping price to decide best 'ship from' location.
Everything is fine, but when the script populates the sales order (N / record) fields, it throws this error:
"type": "internal error",
"code": "UNEXPECTED_ERROR",
"details": "java.lang.StackOverflowError",
"userEvent": null,
"stackTrace": ....
any ideas, what trigger that error? thx

I solved the problem. The error was triggered by "self-referencing". in the created netsuite module, there was a function that returns the object passed in the parameters. the return of this function was put into property of the same object.
function do_something(_obj){
....
return _obj;
}
var obj = {};
obj.prp = do_something(obj);

Related

google-api-nodejs-client API key - 401 Login required

I am trying to use the google-api-nodejs library to manage some resources in the google Campaign Manager API.
I have confirmed that we currently have a GCP project configured, and that this project has the google Campaign Manager API enabled (screenshot at the bottom).
I have tried several ways of authenticating myself (particularly API keys, OAuth2, and Service account credentials). This question will focus on using an API key though, as theoretically it is the simplest (and I will raise a separate question for the issues I am facing using Service account credentials).
Now, I have generated an API key and I have restricted it to have access to the Campaign Manager API (this is visible in the screenshots below). I configured my code
following the using-api-key section of the library's repo (https://github.com/googleapis/google-api-nodejs-client/#using-api-keys):
import { assert } from "chai";
import { google } from "googleapis";
it("can query userProfiles using API Key", async () => {
try {
const api_key = "AIza ****";
const df = google.dfareporting({
version: "v3.5",
auth: api_key,
});
const res = await df.userProfiles.list({}); // error thrown on this line
console.log("res: ", res);
assert(true);
} catch (e) {
console.error("error: ", e);
assert(false);
}
});
Unfortunately, this code results in an error with the message Login required:
{
"code": 401,
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
]
}
It is worth noting that:
While the API key seems to be correctly configured (that is, it matches what is visible in the Google API), changing the value of the API key in our code does not change the result - the error is still exactly the same
Moreover, changing the auth attribute from google.dfareporting to userProfiles.list results in the same error.
const df = google.dfareporting({
version: "v3.5",
});
const res = await df.userProfiles.list({
auth: api_key, // error thrown on this line
});
If you check the documentation for userProfiles.list
You will find it states
This means in order to access this method you need to be authorized by a user using oauth2 with one of those scopes.
Api keys will only give you access to public data not private user data.
you sould check the Google api node.js client for information on authorization with this library.
const {google} = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
// generate a url that asks permissions access
const scopes = ['https://www.googleapis.com/auth/dfareporting'
];
const url = oauth2Client.generateAuthUrl({
// 'online' (default) or 'offline' (gets refresh_token)
access_type: 'offline',
// If you only need one scope you can pass it as a string
scope: scopes
});

Unable to authenticate on Crypto.com API C# REST API

Crypto.com offers an API where supposedly you could access their exchange platform. However, their documentation is extremely poor and inaccurate in terms of C# examples. I am unable to authenticate my REST calls using C#.
For all the private (account related) calls you need to sign your requests by adding a sig parameter to your payload JSON.
A simplified version of my code that calculates the sig parameter for the private/get-account-summary method looks like this (.net50):
private static string GetSignature()
{
string sigPayload = "private/get-account-summary" + 1 + API_KEY + "currencyCRO" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var hash = new HMACSHA256(Encoding.UTF8.GetBytes(API_SECRET));
var computedHash = hash.ComputeHash(Encoding.UTF8.GetBytes(sigPayload));
return Convert.ToHexString(computedHash);
}
, while the request which makes use of this signature looks like this:
POST https://api.crypto.com/v2/private/get-account-summary
{
"id": "1",
"method": "private/get-account-summary",
"api_key": "[api_key]",
"params": {
"currency": "CRO"
},
"nonce": "1615048530368",
"sig": "1A7C7183CAF2E71F7F7DAB6A5C7F74319E692F2638710292BDB4FDFAC6C864D6"
}
As far as I know, I've correctly applied their algorithm for creating the signature and also used the correct parameters to call the method in question (https://exchange-docs.crypto.com/spot/index.html#private-get-account-summary). However, the response that I get tells me that I'm doing something wrong:
{
"id": 1,
"method": "private/get-account-summary",
"code": 10002,
"message": "UNAUTHORIZED"
}
I'm starting to have doubts that the API even works for private methods. Their support is awful and sent me to read the documentation again. I would appreciate any help in any language. If I at least hear that somebody else did it in another language I could use their example to figure out what I'm doing wrong.
The last line in the sample needs to be changed like this:
Convert.ToHexString(computedHash).ToLower();
In the end I followed my own advice and tried to call the service using one of the other sample languages. When I used JavaScript (which had a way better sample in the documentation) I've noticed the the resulting sig was lower case.

Microsoft Graph Calendar API OData filter on start / end date-times

I am trying to retrieve only certain events from a user's calendarView in the Microsoft Graph Calendar API.
I've written the following proof-of-concept code:
start = self.date_to_string(datetime.datetime.now())
end = self.date_to_string(datetime.datetime.now() + datetime.timedelta(days = 365 * 3))
start, end = min(start, end), max(start, end)
data = await self.make_request(url, parameters = {
"startDateTime" : start,
"endDateTime" : end,
"$filter" : "Start/DateTime ge '2017-07-01T08:00'" # and (start/dateTime ge '2020-10-21T16:31:40.5470240')"
})
Though, when I make the request, this is what I'm getting
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
"innerError": {
"date": "2020-10-22T15:20:56",
"request-id": "bef9513d-a5b3-4b23-b37a-8f341f6822ae",
"client-request-id": "bef9513d-a5b3-4b23-b37a-8f341f6822ae"
}
}
}
Removing the $filter helps, but I do need it (I would like to filter events starting in a date-time range and/or ending in a date-time range).
I tried several things:
cast(2017-07-01T08:00 as Edm.DateTimeOffset)
2017-07-01T08:00Z
2017-07-01T08:00Z+00:00
Actually pretty much any combination one can think of, but to no avail. Note that official docs use different formats, including '2017-07-01T08:00' (as in ?$filter=start/dateTime ge '2017-07-01T08:00')
Any ideas?

Contains filter on Microsoft Graph query not working

I'm trying to user the contains filter on a /users query, like this for example:
https://graph.microsoft.com/v1.0/users?$filter=contains(displayName, 'Garth')
However, this results in a BadRequest response saying "An unknown function with name 'contains' was found. This may also be a key lookup on a navigation property, which is not allowed."
According to the OData 4.0 specs, the contains filter should be available though. Is there a way to use a contains filter on a list of users?
The contains function is not available for users. startsWith is available though.
e.g. https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'Garth').
Additionally you can try the people API (this is only available on /beta). This supports $search AND will do fuzzy and phonetic matching.
https://graph.microsoft.com/beta/me/people?$search=Garth
$search can replace $contains
for example to show all the users that their names may contain the string "sa"
https://graph.microsoft.com/v1.0/users?$count=true&$search="givenName:sa"
"value": [
{....
"givenName": "Sammy",
.....
},
{
.....
"givenName": "Sabrina",
.......
},
.....

Web API OData ignore properties added by client-side

I get an error when I call Put to my server using WebApi Odata v4.
{
"error": {
"code": "",
"message": "The request is invalid.",
"innererror": {
"message": "job : The property 'test' does not exist on type 'Model.Temp'. Make sure to only use property names that are defined by the type.\r\n",
"type": "",
"stacktrace": ""
}
}
}
this error happens because the property "test" is not set in the Model "Temp". it is actually added by javascript, and only used in client-side
How do I make so that OData will just ignore properties that are not available in the Model ?
There is a way to deal with your scenario. It is not to ignore the properties, but to accept them by defining the entity type as an open type so that it can accept dynamic properties which are not defined in the model from the client and store them for future queries if necessary.
You can find the following tutorial for implementing an open type support: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4

Resources