Public class BizNodeIntegration_Custom { public static void CreditRatingUpdate (CustTable _custTable) { URL url = strLTrim(@'https://test-integrations-syncoperations.azurewebsites.net/api/companyRating?code=fgfgfgfgfgfg'); //URL url = SysAppUtilities_Custom::getKeyVaultSecret(SysAppUtilities_Custom::IntegrationsFunctionsBaseUrl) + '/api/creditRating?code=' + SysAppUtilities_Custom::getKeyVaultSecret(SysAppUtilities_Custom::IntegrationsFunctionAppMasterKey); System.IO.StringWriter stringWriter; Newtonsoft.Json.JsonTextWriter jsonWriter; System.Byte[] bytes; System.Text.Encoding utf8; stringWriter = new System.IO.StringWriter(); jsonWriter = new Newtonsoft.Json.JsonTextWriter(stringWriter); str jsonString = ""; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("RegistrationNumber"); jsonWriter.WriteValue(_custTable.registrationNumber()); jsonWriter.WritePropertyName("CountryCode"); jsonWriter.WriteValue(strDel(_custTable.VATNum,3,strLen(_custTable.VATNum))); jsonWriter.WriteEndObject(); jsonString = stringWriter.ToString(); str method = 'POST'; str contentType = @'application/json'; RetailWebRequest webRequest = RetailWebRequest::newUrl(url); utf8 = System.Text.Encoding::get_UTF8(); bytes = utf8.GetBytes(jsonString); webRequest.parmMethod(method); webRequest.parmContentType(contentType); webRequest.setContentBytes(bytes); RetailCommonWebAPI webApi = RetailCommonWebAPI::construct(); RetailWebResponse webResponse = webApi.getResponse(webRequest); str responseData = webResponse.parmData(); info(responseData); if (webResponse.parmHttpStatus() == 200) { Map responseMap = RetailCommonWebAPI::getMapFromJsonString(responseData); MapEnumerator mapEnumerator; mapEnumerator = responseMap.getEnumerator(); while (mapEnumerator.moveNext()) { switch (mapEnumerator.currentKey()) { case "payload" : container con = mapEnumerator.currentValue(); CustomerCreditInsuranceUpdate_Custom::updateCustomerCreditInsurance(conPeek(con,conFind(con,'companyRating') + 1),_custTable.registrationNumber()); break; default: break; } } } else { info(responseData); } } }
This blog is contains coding reference related to Microsoft AX 2012 and D365 finance and operations and Power platform
Wednesday, January 17, 2024
Send Http request with JSON payload using X++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment