weixin_39776817
weixin_39776817
2021-01-12 16:35

NetSuite API

Create API for access to NetSuite.

该提问来源于开源项目:scribejava/scribejava

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

14条回答

  • weixin_39756192 weixin_39756192 4月前

    change

    ServiceBuilder().apiKey(CONSUMER_KEY)

    to

    ServiceBuilder(CONSUMER_KEY)

    you can upgrade ScribeJava step by step and fix all deprecated warnings with suggested fixes from the javadocs

    点赞 评论 复制链接分享
  • weixin_39776817 weixin_39776817 4月前

    NetSuite provides this super outdated code using scribe. I've been trying to covert it for 2 days to the most recent version. Can't for the life of me figure it out.

    `import org.scribe.builder.ServiceBuilder; import org.scribe.model.OAuthRequest; import org.scribe.model.Response; import org.scribe.model.SignatureType; import org.scribe.model.Token; import org.scribe.model.Verb; import org.scribe.oauth.OAuthService;

    public class TokenAuth{
        private static final String TOKEN_ID = "080eefeb395df81902e18305540a97b5b3524b251772adf769f06e6f0d9dfde5";
        private static final String TOKEN_SECRET = "451f28d17127a3dd427898c6b75546d30b5bd8c8d7e73e23028c497221196ae2";
        private static final String REST_URL = "https://rest.netsuite.com/app/site/hosting/restlet.nl?script=992&deploy=1";
        private static final String CONSUMER_KEY = "504ee7703e1871f22180441563ad9f01f3f18d67ecda580b0fae764ed7c4fd38";
        private static final String CONSUMER_SECRET = "b36d202caf62f889fbd8c306e633a5a1105c3767ba8fc15f2c8246c5f11e500c";
        private static final String REALM = "ACCT123456";
        private static final String CONTENT_TYPE = "content-type";
        private static final String APP_JSON = "application/json";
        private static final String EMPTY_JSON_PAYLOAD = "{}";
    
        private static OAuthService service = getService();
        private static Token accessToken = getToken();
    
    
        public static void main(String[] args) {
    
            Response responseGet = callWithHttpGet();
            System.out.println(responseGet.getBody());
    
            Response responsePost = callWithHttpPost();
            System.out.println(responsePost.getBody());
        }
    
        private static Response callWithHttpGet(){
            OAuthRequest request = new OAuthRequest(Verb.GET, REST_URL);
            request.setRealm(REALM);
            service.signRequest(accessToken, request);
            return request.send();
        }
    
        private static Response callWithHttpPost() {
            OAuthRequest request = new OAuthRequest(Verb.POST, REST_URL);
            request.setRealm(REALM);
            request.addHeader(CONTENT_TYPE, APP_JSON);
            request.addPayload(EMPTY_JSON_PAYLOAD);
            service.signRequest(accessToken, request);
            return request.send();
        }
    
        private static Token getToken() {
            return new Token(TOKEN_ID, TOKEN_SECRET);
        }
    
        private static OAuthService getService() {
            return new ServiceBuilder()
                .provider(DummyService.class)
                .apiKey(CONSUMER_KEY)
                .apiSecret(CONSUMER_SECRET)
                .signatureType(SignatureType.Header)
                .build();
        }
    
    }
    

    `

    点赞 评论 复制链接分享
  • weixin_39959298 weixin_39959298 4月前

    Good start ... I believe that the this package also has changed a lots. The API example provided here does not work any more with the latest scribejava api. But some how I did little coding and was able to connect to NetSuite Restlet. Can you verify the coding that I have done so far. So that we can create a NetSuite API .... Thanks.

    点赞 评论 复制链接分享
  • weixin_39756192 weixin_39756192 4月前

    Sorry for the delay, this issue is in the queue. Hope to get it soon. Sure, you can leave your coding here.

    点赞 评论 复制链接分享
  • weixin_39959298 weixin_39959298 4月前

    Pls find the code that I have done so far. This works fine to call REST Service with POST and GET method. Pls do the modification if you need to do to optimize the capability.

    scribe.zip

    点赞 评论 复制链接分享
  • weixin_39756192 weixin_39756192 4月前

    hi. I had a look on your code. It seems, it's quite good. Thx! Better make a Pull Request or just fork to inspect and comment your code. attaching zip files is not so usable as Pull Requests here, on github.

    look at code in zip. Did it helps you to update your code? Do you still need any assistence?

    点赞 评论 复制链接分享
  • weixin_39776817 weixin_39776817 4月前

    and Thank you so much for jumping in here and making the api for NetSuite. I haven't taken a look at it yet or tried to see if it works since I came up with my own solution and implemented it in production already.

    点赞 评论 复制链接分享
  • weixin_39776817 weixin_39776817 4月前

    I'd like to see a Pull Request for your branch as well.

    点赞 评论 复制链接分享
  • weixin_39756192 weixin_39756192 4月前

    Do we still need this issue open? Any open questions? I'll close this issue in one month in case nobody have interest in it

    点赞 评论 复制链接分享
  • weixin_39683769 weixin_39683769 4月前

    I've been attempting to use code similar to the example provided by , but I'm still getting the very "helpful" response:

    json
    {"error" : {"code" : "UNEXPECTED_ERROR", "message" : "Unexpected Error"}}
    

    I'll look more closely at his solution and see if I can find what I'm missing... But having a baked in "NetSuiteAPI" in the core of Scribe would be nice...

    点赞 评论 复制链接分享
  • weixin_39756192 weixin_39756192 4月前

    :+1:

    点赞 评论 复制链接分享
  • weixin_39683769 weixin_39683769 4月前

    I managed to get things working with:

    1. Making sure I used the right Role (The recent Sandbox changes mean that my sandbox role now ends with "_SB1").
    2. Creating a trivial NetSuiteApi class that just returns null for all 3 abstract methods in DefaultApi10a.
    3. Directly creating an OAuth1AccessToken using the key & secret provided by NetSuite's UI, rather than using the OAuth10aService to create one.
    点赞 评论 复制链接分享
  • weixin_39756192 weixin_39756192 4月前

    Glad to read this. So, do we need any changes to the ScribeJava? Do we need this issue to be open?

    点赞 评论 复制链接分享
  • weixin_39967812 weixin_39967812 4月前

    I tried the solution in your scribe.zip with the latest version scribejava-core-6.2.0.jar and am seeing couple of compiler errors,
    Am seeing The constructor ServiceBuilder() is undefined for the below line final OAuth10aService service = new ServiceBuilder().apiKey(CONSUMER_KEY).apiSecret(CONSUMER_SECRET) .build(NetSuiteApi.instance()); Apparently ServiceBuilder() is expecting a string argument, what should I provide?

    点赞 评论 复制链接分享