How to go about a “POST” request with a csrf-token
-
Roman MoraruHas successfully completed the online course Basics (100)2 years ago #34468
Hello,
assuming i do have a connector call that does create a new entry in a database which looks something like this (see picture):
How to formulate the business object function so that:
1. csrf token is handed over
2. the “postBody” is also inserted.
Simplifier.Connector.ExampleConnector.createEntry(
“x-csrf-token”: getTokenFromAGETRequest,
“postBody”: oNewEntry
)
doesn’t really work, it produces the error “expected ) instead saw :”.
How to add this two things “x-csrf-token” and “postBody” to a connector call? Should it both be part of the same object ?
Best regards
Attachments:
You must be logged in to view attached files.Jennifer HäfnerHas successfully completed the online course Intermediate (200)Has successfully completed the online course Advanced (300)Has successfully completed the online course Basics (100)Has successfully completed the online course Advanced (310)Has successfully completed the online course Advanced (320)Has successfully completed the Intermediate CertificationHas successfully completed the Advanced Certification2 years ago #34473::Hi Roman,
Have you checked if the data that you are sending in the postBody has a valid JSON format? Instead of sending the complete JSON object as a parameter, you can also split the postBody fields into several string input parameters, e.g., postBody/name, postBody/city etc. I included a screenshot of an example where several postBody parameters are used.
Regarding the csrf token: depending on the API that you’re using, authorization tokens sometimes need to be sent in the header parameters (see screenshot). Please check your API’s specifications.
In general, to execute a Connector call in a Server-Side Business Object function, you need to wrap the input parameters in an object:
var oResult = Simplifier.Connector.ConnectorName.callName({ paramName1: "your parameter value", paramName2: calculateParameterValue() });
I hope this information is helpful.
Attachments:
You must be logged in to view attached files.
You must be logged in to reply to this topic.