• i have messenger chatbot and if the user click Get Started i make singel api call POST method with $sender_id as title to add new post to my CPT inquery and when i look to wordpress panel i see 2 of them with same title and when make another api call with $sender_id as title it gives me the old one i can’t figure why it happend from beginning Thanks in advenced

    this my code to get ID of inquiry

    function get_inquiry_id($data){
     $return = []; $title=$data['title'];
     $return = get_page_by_title($title, OBJECT, 'inquiry');
     $return = $return->ID; return new WP_REST_Response($return, 200); 
    } 
    add_action('rest_api_init',function(){ 
         register_rest_route('chatbot/v1','/inquiry/(?P<title>\d+)',array( 
            'methods'=>'GET',
            'callback'=>'get_inquiry_id' 
       ));
     });

    this my code for handel Get Started button

    
    if ( $payload == 'firsthand' ) {
        $sender_id = ''.$sender_id.'';
        $data_array = array( 
          "title"=>$sender_id 
       );
        callAPI('POST','https://alenke.test/wp-json/wp/v2/inquiry',json_encode($data_array));
      //rest of chatbot stuff
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • It’s not clear what your expected and actual results are, but it looks like your code doesn’t match.
    for the register_rest_route call, you have v1 and GET.
    For the callAPI call, you have v2 and POST.

    Thread Starter mohammedalama

    (@mohammedalama)

    ok first code it’s in functions.php of my theme and i use it for get id of inquriy by title of it
    the socend one it’s in my handel file for messenger chatbot
    what i expected when if($payload == 'firsthand') come true i will make POST api call to https://alenke.test/wp-json/wp/v2/inquiry to make a new singel inquriy in my wordpress site
    but it make double inquriy with same title in this case it sender_id form facebook chatbot

    this happend in my table of inquriy when POST call api done well
    2115706638540570 — Draft
    2115706638540570 — Draft

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_api add 2 inquery (my CPT) with single POST request’ is closed to new replies.