How-to create an HTTP API webhook
Advanced
This article will guide how to create a webhook in RS Production. A webhook is a way to extend the RS Production HTTP API.
A webhook is a PythonScript object, all PythonScript objects are available as webhooks over the HTTP API. In the following guide, we will create a PythonScript object that can be called
The implemented webhook will create a new article using two parameters:
ArticleNumber : string
ArticleName : string
Instructions
Open RS Start and start to write “pythonscript” and then select the option “Python script”.
Press “Create” to create a new Python script instance.
Give the Python script a Name.
Save the Changes using the “Save”-button and then go to the “Parameters” section to the left.
Create two parameters of type string: ArticleName and ArticleNumber. The parameters will be available to set from the HTTP API and will be available to use from the python script.
Go back to the “Information” section and click on the “Python Code” link in order to open the Python code editor.
Time to write the actual code that creates a new article using the two parameters added previously.
Press save and close!
The PythonScript instance is finished and ready to be invoked over HTTP.
Invoke the Python script as a webhook over HTTP
More details about how to invoke a webhook can be found here: HTTP API / JSON API.
The WebhookId is the same id as the PythonScript instance, get the id by right-clicking the python script instance in the list and select “Copy selected GUID” from the context menu.
Example code
POST /INSTALLATION_NUMBER/api/v1/webhook/ HTTP/1.1
Host: INSTALLATION_NUMBER.rsproduction.se
Authorization: Bearer YOUR_API_AUTHORIZATION_TOKEN
Content-Type: application/json
Content-Length: 133
{
"webhookId": "WEBHOOK_ID",
"ArticleName": "The new article",
"ArticleNumber": "1001-01"
}
Where
INSTALLATION_NUMBER
The installation number of the installation in the RS Production cloud where you want to execute the webhook.
YOUR_API_AUTHORIZATION_TOKEN
Your authorization token in order to access the HTTP API.
WEBHOOK_ID
The id (GUID) of the python script instance.
Result
After posting the example code over HTTP to the RS Production API the following article is added.