question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

my endpoint isn't receiving the data parameters from a post

See original GitHub issue

I’ve got an existing form endpoint that works when submitting via a standard ajax/jQuery call, but when I use Axios to post to it, the endpoint is not receiving any of the data from the data attribute.

I am posting to a file on the same server, not a CORS.

Anything I put in the URL reaches the endpoint as expected.

export function selectSubscription(data){
    const url = '/remoting/credits.cfc';
    let params = {};
    const requiredFields = [
        'PRODUCT_PACKAGE_ID', 
        'REPLENISH_PACKAGE_ID', 
        'REPLENISH_THRESHOLD',
        'SCHOOL_SUBSCRIPTION_ID'
    ];
    let validFormData = jsonHasFields(data, requiredFields);

    if (!validFormData.success) {
        return {
            type: 'INVALID_FORM',
            keys: validFormData.keys
        }
    }
    params.method = 'selectSubscription';
    for (let i=0; i < requiredFields.length; i++) {
        let key = requiredFields[i];
        params[key] = data[key];
    }

    //const request = axios.post(url, params); 
    const request = axios({
        method: 'post',
        url: url,
        data: params
    })
    //$.post(url, params, function(result){debugger;});
    return {
        type: 'SELECT_SUBSCRIPTION',
        payload: request
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nickuraltsevcommented, Apr 29, 2016

It looks like your endpoint expects data to be in x-www-form-urlencoded format while axios sends data in JSON format by default. axios does not support x-www-form-urlencoded format at the moment (please see #97), but it will soon. Meanwhile, you can do the following:

axios({
  method: 'post',
  url: url,
  data: 'param1=value1&param2=value2' // Note: values need to be properly encoded
})

Hope this helps!

0reactions
nickuraltsevcommented, Jun 3, 2016

axios v0.12.0 supports x-www-form-urlencoded. Please see this comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST method endpoint not being hit but GET ... - Stack Overflow
I just create a test project. I added a controller with two methods called [HttpGet] void CreateOne() and [HttpPost] void CreateTwo() (you can't ......
Read more >
Step 3: Parameters (API reference tutorial) | Documenting APIs
Parameters are options you can pass with the endpoint (such as specifying the response format or the amount returned) to influence the ...
Read more >
Building requests | Postman Learning Center
You can send requests in Postman to connect to APIs you are working with. Your requests can retrieve, add, delete, and update data....
Read more >
Pass API Gateway REST API parameters to a Lambda ... - AWS
I need my Amazon API Gateway REST API to pass query string parameters to a backend AWS Lambda function and an HTTP endpoint....
Read more >
Troubleshooting Error Messages
This type of error message occurs when the request URL or a request body parameter contains invalid or improperly formatted data. Below you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found