0

I want to send this POST request by amplifyjs

amplify.request.define('createItem', 'ajax', {
    url: baseApiUrl + '/create/?folderid={folderid}',
    dataType: 'json',
    type: 'POST',
    contentType: 'application/json; charset=utf-8'
});

after that, the execution will be something like this:

createItem = function (callbacks, folderid, itemdata) {
    return amplify.request({
        resourceId: 'createItem',
        data : {
            folderid: folderid,
            data: itemdata
        },
        success: callbacks.success,
        error: callbacks.error
    });
};

"itemData" is already a JSON string. I keep getting the Bad Request status code.

If I change the API URL to:

baseApiUrl + '/create

And after that pass:

return amplify.request({
    resourceId: 'createItem',
    data :data,
    success: callbacks.success,
    error: callbacks.error
});

It works just fine, but I need to pass the Id as well. Maybe, I'm missing something here.

kupendra
  • 1,002
  • 1
  • 15
  • 37
mashix
  • 300
  • 3
  • 13

1 Answers1

0

You need to combine folderid and itemdata into a single data object. When Amplify reads your data object it will extract the folderid property and place it in the URL of the request. Then it will POST the remaining properties of the data object.

dave walker
  • 3,058
  • 1
  • 24
  • 30