[Solved] Post request to gravity form using basic auth in React Native failing

import React from 'react';
import { TextInput, View, Button } from 'react-native';
import base64 from 'react-native-base64';

export default class App extends React.Component{
    
    async onSubmit(){
        try {
            await fetch('https://url', {
                method: 'POST',
                mode: 'no-cors',
                headers: {
                    'Content-Type': 'application/json',
                    'Accept': 'application/json',
                    'Authorization': 'Basic ' + base64.encode('email' + ':' + 'password')
                },
                body: JSON.stringify({
                    'form_id': 2,
                    '2.3': 'john',
                    '2.6': 'doe',
                    '3': 'a@a.com',
                    '7': 'Parent/Guardian',
                    '5.1': 'yes',
                    '6.1': 'yes',
                    '2.2': '',
                    '2.4': '',
                    '2.8': '',
                    '1': '',
                    '4': '',
                    '8': ''
                    //numerical id will be created upon submission
                })
            });
        } catch(e) {
            console.log(e);
        }
        
    }

    onPressSubmit(){
        this.onSubmit();
    }

    render(){
        return(
            <View>
                <TextInput placeholder="First Name" />
                <TextInput placeholder="Last Name" />
                <TextInput placeholder="Email" />
                <TextInput placeholder="Password" secureTextEntry={true} />
                <TextInput placeholder="Confirm Password" secureTextEntry={true} />
                <Button onPress={this.onPressSubmit.bind(this)} title='Submit' color='#35ec90'/>
            </View>
        );
    }
}

(Actual url, email and password changed for obvious reasons. )

When I test this POST request on Postman, it works just fine. But when I try to submit it from my app in a browser, I keep getting a 400 error. The JSON response I see in the dev console says:

{"code":"rest_missing_callback_param",
"message":"Missing parameter(s): form_id",
"data":{"status":400,"params":["form_id"]}}

I don’t understand this error. As you can see, “form_id” is included in the body of my POST request. What am I doing wrong?

Do you really need to stringify the body ?

So this was actually a simple solution. I removed the quotes from Accept, and now it works!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.