1

This is my JSON Response of my Rest API.

{"ListClientResponse": {
   "Header": {"CMMHeader": {"CorrelationId": "cmm:CorrelationId"}},
   "Result":    {
      "ResponseCode": "CM-N-0000",
      "ResponseMessage": "No errors and warnings."
   },
   "ListClient": {"Client":    [
            {
         "OrganizationId": 523,
         "OrganizationName": "OrgX1518521.com",
         "OrganizationDomain": "X1518521.com"

            ],
            "RoleId": "AdminRole",
            "RoleName": "Admin"
         }
      },

I want to save Organization Id and OrganizationDomain from my JSON Response in a variables or something so that I can use these values later in my all JSON requests.

This is my JSON request.

var myCreateUserRequest =  {
                "CreateUserRequest": {
                       "Header": {
                        "CMMHeader": {
                            "CorrelationId": 5454354}},
                       "ClientContext":    {
                          "OrganizationId": **theOrgId,**
                          "OrganizationDomain": **theDomain,**
                       },
                       "User":    {
                          "UserName": aUser.Username,
                          "UserPassword": aUser.Password,
                          "UserStatus": "Active",

                          "RoleId": "Member"
                       }
                    }
                }

In my JSON request, inside the field of OrganizationId and OrganizationDomain I want to pass that organizationID value and OrganizationDomain value that I have saved from my JSON Response in a varibale. I want to save it in a way so that organizationId and OrganizationDomain can be accessible in my whole ANGULAR JS project and I can pass it in my any JSON request. How can I do that. Please tell me any suggestion.

9
  • use some storage methods like $localstorage,Session storage things to store those after the response and use them in making calls....and make sure when ever posting some json the opening and closings should be in correct way Commented Jan 2, 2017 at 7:56
  • @Sa E Chowdary It will be running on server later and different browser will access it. I cannot user local storage. Commented Jan 2, 2017 at 8:14
  • Hard to figure out what you are even asking Commented Jan 2, 2017 at 9:30
  • 1
    so storing in a service is simple too....not sure where your problem is. Then later when you need it you inject the service and get it doing something like myService.ListClientResponse.ListClient.Client[0].OrganizationId Commented Jan 2, 2017 at 9:35
  • 1
    it's the angular service you use to store this object in. Probably same service you make request from Commented Jan 2, 2017 at 9:46

1 Answer 1

1

Best practice in this case tells to create a service. Becouse services are singleton in Angular, you can set a vale and inject in yours services/controllers and have access to the value.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes I am creating a service and my response JSON is actually the response of my service. Now I am calling a http post operation in which I want to send JSON and inside that JSON I want to send value of organizationID that i recieved from my response but how can I store and send it in all JSON requests? How can I set value?
There is an example jsfiddle.net/u5ffkd6q . If your second request it's immediately after the first, then you can make a chain of promise.
Thanks @Giorgio Cerruti but they are two different services and its not working.
Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.