Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

PUT API giving error message

tsoct
Tera Guru

Hello all,

I created a REST Message to create and update the record of SN instance1 to SN instance2.

Information I am storing in instance2 including instance1.table.record.sys_id and I am attempting to Update the record in instance2 based on sys_id as a parameter.

My POST is working fine but PUT is giving me an error msg: {"error":{"message":"Method not Supported","detail":"PUT method not supported for API"},"status":"failure"}

 

Could you help to advise what could be the mistake? 

*note:sys_id is stored as u_correlation_id in instance2

 

REST Message:

tsoct_0-1676309655476.png

PUT 

tsoct_3-1676310146875.png

 

tsoct_2-1676309850827.png

 

AFTER UPDATE business rule

 

(function executeRule(current, previous /*null when async*/ ) {

    var body = {
        "u_organization": gs.getProperty('instance_name'),
        "u_name": current.name.toString(),
    };
    try {
        var r = new sn_ws.RESTMessageV2('my Integration', 'Default PUT');
	r.setStringParameterNoEscape('u_correlationid',current.getUniqueValue());
        r.setRequestBody(JSON.stringify(body));

        var response = r.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        
    } catch (ex) {
        var message = ex.message;
      
    }
})(current, previous);

 

 

 

 

1 ACCEPTED SOLUTION

Thank you Kirby. I need the sys_id to be dynamic and I've managed to achieve what I wanted with staging table and transform map. 

View solution in original post

10 REPLIES 10

tsoct
Tera Guru

The test run result:

tsoct_0-1676310551917.png

Hi @Ankur Bawiskar , could you help to review this. Thank you

@tsoct 

Please use Patch instead of Put

check the explanation here

How to avoid the 405 error { "message": "Method not allowed" } in Rest Message in Put method 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Kirby R
Kilo Sage

Hi @tsoct , 

 

You should be passing the sys_id/correlation id directly after slash in your url parameter. Something like this, u_license/3232323.

I was able to replicate the issue in my testing.

 

KirbyR_1-1676359739206.png

 

Here's a correct URL parameter:

KirbyR_2-1676359814670.png

 

Hi Kirby,

This is the error message i got when trying 

tsoct_0-1676359996038.png

I have also updated the BR in SNinstance2 to dynamically pass the record sysid to endpoint. But still getting the same error

var u_correlationid = current.getUniqueValue(); 
try {
        var r = new sn_ws.RESTMessageV2('Subscription Integration', 'Default PUT');
        r.setStringParameterNoEscape('u_correlationid', current.getUniqueValue());
        r.setEndpoint('https://xxxxx.service-now.com/api/now/table/u_license?sysparm_query=u_correlationid='+u_correlationid);
        r.setRequestBody(JSON.stringify(body));