SendPutRequest
PowerScript function
Description
Sends the HTTP PUT request to the server and then gets the content
of the server response. It does not parse the HTTP response code and
content of the server response.
It is not recommended to use this method to process large data (20
MB or 100,000 data rows can be considered as large data based on our
tests).
Applies to
RESTClient objects
Syntax
|
1 |
objectname.SendPutRequest(string urlName, string data, ref string response) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the RESTClient object from which you want to |
|
urlName |
A string value specifying the URL. |
|
data |
A string value specifying the data to send. If the user sets the encoding charset in the Content-Type |
|
response |
The content of the server response. If RESTClient failed to send request or server provides no |
Return value
Integer. Returns 1 if the function succeeds and a negative value if
an error occurs. If any argument’s value is null, the method returns
null.
1 — Success
-1 — General error
-2 — Invalid URL
-3 — Cannot connect to the Internet
-4 — Timeout
-7 — Failed to decompress data
-10 — The token is invalid or has expired
-14 — Code conversion failed
-15 — Unsupported character set
Example
The following example updates the value of Department Name for the
current row via SendPutRequest.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
RestClient lrc_P021 String ls_P021_Response String ls_P021_PostData String ls_P021_Token Integer li_P021_SendReturn Integer li_P021_GetTokenReturn lrc_P021 = Create RestClient //Sets the token parameters TokenRequest ltreq_P021_Appeon ltreq_P021_Appeon.tokenlocation = "https://demo.appeon.com/pb/identityserver/connect/token" ltreq_P021_Appeon.method = "post" ltreq_P021_Appeon.GrantType = "password" ltreq_P021_Appeon.ClientId = "P0VRQ-ddHn/WWd6lcCNJbaO9ny-JCNHirDJkHNgZ0-M=" ltreq_P021_Appeon.ClientSecret = "K7gNU3sdo-OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" ltreq_P021_Appeon.UserName = "TestUser" ltreq_P021_Appeon.PassWord = "TestPassword" //Gets token via RESTClient li_P021_GetTokenReturn = lrc_P021.GetOauthtoken( ltreq_P021_Appeon, ls_P021_Token) If li_P021_GetTokenReturn = 1 Then lrc_P021.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" ) lrc_P021.SetOauthToken( ls_P021_Token ) //Sets the authentication lrc_P021.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve") If dw_Data.GetRow() > 0 Then //Modifies the data in DataWindow dw_Data.SetItem(dw_Data.GetRow(),2,"Update"+String(rand(50))) //Exports a DataWindow row to JSON string ls_P021_PostData=dw_Data.Exportrowasjson( dw_Data.GetRow()) li_P021_SendReturn = lrc_P021.SendPutRequest("https://demo.appeon.com/PB/webapi_client/api/department/update",ls_P021_PostData, ls_P021_Response) If li_P021_SendReturn <> 1 Or lrc_P021.GetResponseStatusCode() <> 200 Then //Checks the error information End If //Finds out if data is modified via https://demo.appeon.com/PB/webapi_client/api/department/retrieve lrc_P021.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve") End If Else //Gets the token failure error End If |
See also