# Help with saving input to a Active Object using rest

**URL:** <https://community.developer.atlassian.com/t/help-with-saving-input-to-a-active-object-using-rest/11833>\
**Category:** Jira Server\
**Tags:** active-objects, input, rest-api, jira-server\
**Created:** [November 30, 2017, 1:54pm UTC](https://community.developer.atlassian.com/t/help-with-saving-input-to-a-active-object-using-rest/11833 "2017-11-30T13:54:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffrey.peeters](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/jeffrey.peeters/32/36366_2.png) [@jeffrey.peeters](https://community.developer.atlassian.com/u/jeffrey.peeters)\
**Post date:** [November 30, 2017, 1:54pm UTC](https://community.developer.atlassian.com/t/help-with-saving-input-to-a-active-object-using-rest/11833/1 "2017-11-30T13:54:21Z")

</div>

So I have been trying to store some user input into a active object but I can’t seem to get it to work. I have tried all kinds of variations on the code but nothing I try works. Could someone fix my mess or atleast point me in the right direction because I’m at a loss as to what I’m doing wrong?

Basically what I’m doing now is putting a value inside a input field in my velocity file. This value can be changed by the user and when he clicks on the button the input should save to my TestEntity Active Object using the rest API. I think my mistake lies with either the ajax call or the restResource itself.

My query in the .js file

```auto
AJS.$('#searchButton2').click(function (){
        AJS.$.ajax({
            url:"jira/rest/testresource/1.0/test",
            type: "post",
            dataType: 'json',
            async: false,
            data: ({issueKey : document.getElementById("issueKeyInput").value, 
                      content: document.getElementById("passwordInput").value}), 
            success: function(data)
            {
                console.log(data);
            }
        })
    });

```

My rest resource file

```auto
@Path("/test")
public class TestResource{
    @ComponentImport
    private final ActiveObjects ao;

    @Inject
    public PasswordResource(ActiveObjects ao){this.ao = ao;}

    @POST
    @Path("/{issueKey}")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response save(@QueryParam("issueKey") final String issueKey, @QueryParam("content") String passJson)
    {
        return ao.executeInTransaction(new TransactionCallback<Response>() {
            @Override
            public Response doInTransaction() {
                TestEntity[] existingAll = ao.find(TestEntity.class, Query.select().where("ISSUE = ?", issueKey));
                TestEntity existing = existingAll[0];

                if (existing != null){
                    existing.setContent(passJson);
                    existing.save();
                }
                else {
                    TestEntity newTestEntity = ao.create(TestEntity.class);
                    newTestEntity.setIssue(issueKey);
                    newTestEntity.setContent(passJson);
                    newTestEntity.save();
                }
                return null;
            }
        });
    }
}

```

My velocity file

```auto
<head>
    $webResourceManager.requireResourcesForContext("tigTestExtension.resource")
</head>

<div>
    <input id="testInput" name="testInput">$testInput</input>
    <input class="hidden" id="issueKeyInput" name="issueKeyInput">$input</input>
    <button id="searchButton2" class="aui-button" name="searchButton2">Zoeken2</button>
</div>

```

(Dont mind the hidden input field here I have yet to figure out how I can send value like $input into a seperate .js file )

My Entity

```auto
public interface TestEntity extends Entity {

    String getIssue();
    void setIssue(String issue);

    String getContent();
    void setContent(String content);

}

```

Any help you might be able to provide me would be greatly appreaciated!

---

<div class="post-metadata">

**Author:** ![sfbehnke](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/sfbehnke/32/34486_2.png) [@sfbehnke](https://community.developer.atlassian.com/u/sfbehnke)\
**Post date:** [December 2, 2017, 8:59am UTC](https://community.developer.atlassian.com/t/help-with-saving-input-to-a-active-object-using-rest/11833/2 "2017-12-02T08:59:25Z")

</div>

The REST method `save` is expecting `jira/rest/testresource/1.0/test/{issueKey}?issuekey={issueKey}&content={content}`.

Your AJAX method is firing a POST to `jira/rest/testresource/1.0/test` with a payload of

```auto
{
    'issueKey':'{issueKey}',
    'content':'{content}'
}

```

You can’t use a Payload, QueryParams, and PathParams interchangeably like this. They are not the same. You can either update your REST Resource or your AJAX call.

---

<div class="post-metadata">

**Author:** ![jason.wesley.roy](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@jason.wesley.roy](https://community.developer.atlassian.com/u/jason.wesley.roy)\
**Post date:** [July 7, 2019, 10:35pm UTC](https://community.developer.atlassian.com/t/help-with-saving-input-to-a-active-object-using-rest/11833/3 "2019-07-07T22:35:50Z")

</div>

Hi Jeffery, I am wondering if you can provide the code that generates the JSON data from the active object, I am looking to write out @GET methods that return json from Active Objects.
