# Platform.api.patch

**URL:** <https://community.dreamfactory.com/t/platform-api-patch/1514>\
**Category:** Server-Side Scripting\
**Created:** [September 23, 2015, 8:37am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514 "2015-09-23T08:37:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrjohny](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mrjohny](https://community.dreamfactory.com/u/mrjohny)\
**Post date:** [September 23, 2015, 8:37am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/1 "2015-09-23T08:37:34Z")

</div>

Hello,

I’m struggling with getting my platform.api.patch script working. When trying it in API docs, it’s working:

I’m using: **updateRecordsByFilter() - Update (patch) one or more records**  
Table\_name = Status  
body = {“Status\_status”:“new”,“Status\_approver”:“Johny”}  
filter = Status\_TT = ‘12345’

With this it should update the items with Status\_TT = 12345 with the information in the body. As i said, it works.

When trying to make this server side, i’ve tried many things and the closest i get is:

```
var queryupdate = '{"Status_status":"new","Status_approver":"Johny"}';
var string3 = JSON.parse(queryupdate);
platform.api.patch("db/status?filter=Status_TT = '12345' ", string3);

```

The problem is that it updates all the records in that table, including the ones thatdon’t have 12345 under Status\_TT

I’ve also tried to do something with

```
platform.api.patch("db/status", string3, {"filter" : "Status_TT = '12345' "} );

```

but that doesn’t work at all

It’s probably something very simple and would appreciate if someone could help me with some code examples, i can work out the rest how to apply it to my project

Thanks

---

<div class="post-metadata">

**Author:** ![mrjohny](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mrjohny](https://community.dreamfactory.com/u/mrjohny)\
**Post date:** [September 25, 2015, 7:22am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/2 "2015-09-25T07:22:54Z")

</div>

Someone must be using this :)?

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [November 3, 2015, 9:00pm UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/3 "2015-11-03T21:00:20Z")

</div>

Maybe try URL-encoding the filter like API Docs does for you.

---

<div class="post-metadata">

**Author:** ![LuchoRod](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@LuchoRod](https://community.dreamfactory.com/u/LuchoRod)\
**Post date:** [January 10, 2020, 2:57am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/4 "2020-01-10T02:57:07Z")

</div>

Hi!

I’m trying to do the same and get stuck: when i do the patch through APIDocs, it work well, but when i try patch inside a server-side script, it returns:

> {“error”:{“code”:400,“context”:null,“message”:“The request contains no valid record fields.”,“status\_code”:400}}

I set a **var\_dump** of the request on the pre-patch event and when i run the patch from the APIDocs, it shows the payload, but when i run from the script, it shows nothing inside the payload… what should be happening?

Any thoughs? thanks in advance.

---

<div class="post-metadata">

**Author:** ![mrjohny](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mrjohny](https://community.dreamfactory.com/u/mrjohny)\
**Post date:** [January 10, 2020, 10:24am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/5 "2020-01-10T10:24:12Z")

</div>

What works for me is the following when I do server side scripting

> var updatesomething = platform.api.patch(“mysql/\_table/profile?filter=Profile\_id%20%3D%20” + profile\_id, {“resource”:[{“Profile\_LastUpdate”: newdate}]});

Where profile\_id and data are variables containing some information

---

<div class="post-metadata">

**Author:** ![LuchoRod](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@LuchoRod](https://community.dreamfactory.com/u/LuchoRod)\
**Post date:** [January 10, 2020, 11:16pm UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/6 "2020-01-10T23:16:59Z")

</div>

Hi, when i use what u wrote (assuming the method is: _platform.api.patch(url, payload)_) it returns:  
`{"error":{"message":"callback is not a function","code":500}}`. Is there any other thing to consider?

Thanks for ur advice,

---

<div class="post-metadata">

**Author:** ![mrjohny](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mrjohny](https://community.dreamfactory.com/u/mrjohny)\
**Post date:** [January 13, 2020, 8:38pm UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/7 "2020-01-13T20:38:23Z")

</div>

Are you using a customer scripting service?

Many things can cause that error. Maybe it’s what you send client side, the arguments, that are not understood server side?

Would need to see more code to see what you’re doing to troubleshoot it. What are you using client side to send the request to the server?

---

<div class="post-metadata">

**Author:** ![LuchoRod](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@LuchoRod](https://community.dreamfactory.com/u/LuchoRod)\
**Post date:** [January 14, 2020, 2:16am UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/8 "2020-01-14T02:16:14Z")

</div>

im pasting here all the code inside the method:

```
var url, result, options, tfa, payload;

options = {
    'headers': {
        'X-DreamFactory-Api-Key': platform.session.api_key,
        'X-DreamFactory-Session-Token': platform.session.session_token,
        'Content-Type': 'application/json'
    }
};
 
// update a record using internal URL
url = 'bd/_table/users/{user.id}';
tfa = {
    secret: '',
    nonsecret: ''
};
payload = {
    "tfa" : JSON.stringify(tfa)
};

console.log('paso 4 - url: ' + url);
console.log('paso 4 - payload to be saved on BD: ' + JSON.stringify(payload));
platform.api.patch(url, payload, null, function(body, response) {
    result = JSON.parse(body);
    console.log('paso 4 - BD answer: ' + body);

});

event.setResponse({'result': 'ok'}, 200, 'application/json');

```

This is what prints on the log:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/dreamfactory/original/2X/3/37009d3089fddcdc2113d9255166fb2c7d8b1984.png)

Thanks for any advice

---

<div class="post-metadata">

**Author:** ![mrjohny](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@mrjohny](https://community.dreamfactory.com/u/mrjohny)\
**Post date:** [January 14, 2020, 12:20pm UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/9 "2020-01-14T12:20:18Z")

</div>

Ok, just to be clear how we did this.

First of all we only use POST type of requests that trigger a server side script. We never PATCH the DB directly. If that is what you’re doing, meaning using the API directly to patch… I would need to test if that works as well.

Second, if you would be OK to do a POST to a server side custom script and inside that server side script you patch what you need to patch it works as I suggested, at least for us.

> $.ajax({  
> type: ‘POST’,
> 
> ```
> beforeSend: function(request) {
> request.setRequestHeader('X-DreamFactory-Api-Key', AP_id);
> request.setRequestHeader('X-DreamFactory-Session-Token', UT);
> request.setRequestHeader('Access-Control-Allow-Origin', '*');
> }, 
> 
> url: AP_api + 'UpdateUserDetails?n1=' + variable1+ '&n2=' + variable2 + '&n3=' + variable3,
> dataType: "TEXT", 
> contentType: "JSON",
> 
> success: function(response) {
> console.log(response);
> },
> 
> error: function(xhr, thrownError) { 
> console.log(thrownError); 
> }
> });
> 
> ```

On the server side we do the patch. Seems a bit of an overkill maybe but since we patch mutliple tables / records this is the easiest

---

<div class="post-metadata">

**Author:** ![LuchoRod](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@LuchoRod](https://community.dreamfactory.com/u/LuchoRod)\
**Post date:** [January 14, 2020, 7:25pm UTC](https://community.dreamfactory.com/t/platform-api-patch/1514/10 "2020-01-14T19:25:13Z")

</div>

oh, ur code is about the calling from the client, right? the code i posted is from de server side script. are we talking about the same? thanks for the reply.
