Jump to content
  • 0

send data to an external database using REST API (Caspio Bridge Database)


Amilcar

Question

var cbIntegrationId = "xxxxx"; //I have this data
var clientId = "xxxxxx"; //I have this data
var clientSecret = "xxxxxxx"; //I have this data
var tableName = "xxxx"; //I have this data

//Get access token
$.post(
  "https://" + cbIntegrationId + ".caspio.com/oauth/token",
  {
    grant_type: "client_credentials",
    client_id: clientId,
    client_secret: clientSecret
  },
  function(cbAuth){
    //Run POST call
    $.ajax({
      url: "https://" + cbIntegrationId + ".caspio.com/rest/v2/tables/" + tableName + "/records?response=rows",
      type: 'POST',
      data: '{ "SubmissionID": null, "Date_of_policy_sold": "13/08/2019","Broker_Code": "Afinidade1004","Drivers_Full_Name": "Amílcar Paco", "Drivers_BI_Number": "123456789012F","Phone_Number": "0258849279489", "Address": "Distrito Municipal 5 Matendene", "Email": "amilcarcpaco@gmail.com", "Type_Of_Cover": "Sedan/Light Duty Vehicle (6 months cover)","Amount_of_Months": "6", "Vehicle_Make_and_Model" : "Toyota Mark X", "Vehicle_Year_Model": "2008", "Vehicle_Registration_No": "AAV123MP", "Engine_Number": "GD028982", "Roadside": "Yes", "Cover_Start_Date": "14/08/2019", "Cover_End_Date": "14/2/20/2020", "Total_Amount": "2800", "Payment_Status":"cancel ", "IP": "127.0.0.0.0" }', //Define record values
      headers: {
        "Authorization": "Bearer " + cbAuth.access_token, //Extracts the access token from the initial authorization call
        "Content-Type": "application/json; harset=utf-8", //Required, otherwise 415 error is returned
        "Accept": "application/json"
      }, 
      dataType: 'json',
      success: function (data) {
        console.log(data.Result); //Check the console to view the new added row
      },
      error: function(data) {
        console.log(data.responseJSON); //Check the console to view error message if any
      }
    });
  }
);

//But I am getting this error
// ------
{Message: "Authorization has been denied for this request."}
Message: "Authorization has been denied for this request."
__proto__: Object

//I'm trying to send data an external database using rest api. I ask for help.
// I have the permissions, I Guess.

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
4 minutes ago, Amilcar said:

var cbIntegrationId = "xxxxx"; //I have this data
var clientId = "xxxxxx"; //I have this data
var clientSecret = "xxxxxxx"; //I have this data
var tableName = "xxxx"; //I have this data

//Get access token
$.post(
  "https://" + cbIntegrationId + ".caspio.com/oauth/token",
  {
    grant_type: "client_credentials",
    client_id: clientId,
    client_secret: clientSecret
  },
  function(cbAuth){
    //Run POST call
    $.ajax({
      url: "https://" + cbIntegrationId + ".caspio.com/rest/v2/tables/" + tableName + "/records?response=rows",
      type: 'POST',
      data: '{ "SubmissionID": null, "Date_of_policy_sold": "13/08/2019","Broker_Code": "Afinidade1004","Drivers_Full_Name": "Amílcar Paco", "Drivers_BI_Number": "123456789012F","Phone_Number": "0258849279489", "Address": "Distrito Municipal 5 Matendene", "Email": "amilcarcpaco@gmail.com", "Type_Of_Cover": "Sedan/Light Duty Vehicle (6 months cover)","Amount_of_Months": "6", "Vehicle_Make_and_Model" : "Toyota Mark X", "Vehicle_Year_Model": "2008", "Vehicle_Registration_No": "AAV123MP", "Engine_Number": "GD028982", "Roadside": "Yes", "Cover_Start_Date": "14/08/2019", "Cover_End_Date": "14/2/20/2020", "Total_Amount": "2800", "Payment_Status":"cancel ", "IP": "127.0.0.0.0" }', //Define record values
      headers: {
        "Authorization": "Bearer " + cbAuth.access_token, //Extracts the access token from the initial authorization call
        "Content-Type": "application/json; harset=utf-8", //Required, otherwise 415 error is returned
        "Accept": "application/json"
      }, 
      dataType: 'json',
      success: function (data) {
        console.log(data.Result); //Check the console to view the new added row
      },
      error: function(data) {
        console.log(data.responseJSON); //Check the console to view error message if any
      }
    });
  }
);

//But I am getting this error
// ------
{Message: "Authorization has been denied for this request."}
Message: "Authorization has been denied for this request."
__proto__: Object

//I'm trying to send data an external database using rest api. I ask for help.
// I have the permissions, I Guess.

 

I dont know why i'm getting this error. I have a website in Wordpress and I'm trying to get data from my form and send it to an external database, not mine.  How can I do That?  I'm in days trying and I can't find the solution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...