0

Posting data to api service - Bearer vs Basic (authorization/authentication)

I am trying to post data to a service. It works perfectly with Postman, however, I am still trying to figure out the proper syntax to do the same within a Ninox button script.

Is "Bearer" authorization required to do this? If so, can "Basic" also be used? My end point requires use of "Basic". Also, how do I apply JSON.stringify, or its Ninox equivalent? Below is the current script.

let response := do as server
http("POST", "https://dummy.restapiexample.com/api/v1",
{
Authorization: "Bearer Y2hvaWNlc0BhY29yZHMuY29tOjIwMzQ1M2RE",
Authorization: "Basic  njtnkyrnRHUFFt776jjjty777jjujHLEFFDF",
'Content-Type': "application/json"
},{
company: "ABC Company",
template: "Sample Form",
mailTo: "ralph@beaconsoft.com",
description: "Attached is requested form",
data: {
Contact: "James Brown",
Email: "becky@aiservices.com",
Comments: "This is your email comment."
}}
)
end;
if response.error then
alert(text(response.error))
else
alert(text(response.result))
end

All suggestions are welcome.

Dean

1 reply

null
    • Choices_Software_Dean
    • 10 mths ago
    • Reported - view

    The below works when attached to a button!

    let response := do as server
    let basicKey := "Basic P2hvaBGlc0BhY29yZHMuY29tOjIwMzQ1M5YV";
    let body := {
    company: "ABC Company",
    template: "Sample Form",
    mailTo: "ralph@beaconsoft.com",
    description: "Attached is requested form",
    data: {
    Contact: "James Brown",
    Email: "becky@aiservices.com",
    Comments: "This is your email comment."
    }
    };
    http("POST", "https://example.restapiexample.com/api/v1",
    ", {
    Authorization: basicKey,
    'Content-Type': "application/json"
    }, formatJSON(body))
    end;
    if response.error then
    alert(text(response.error))
    else
    alert(text(response.result))
    end
    

Content aside

  • 10 mths agoLast active
  • 1Replies
  • 88Views
  • 1 Following