Help with saving input to a Active Object using rest

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

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

@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

<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

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!

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

{
    '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.

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.