Jump to content
Sign in to follow this  
Bob Baudewyns

REST: Delete an object

Recommended Posts

Looking for some help from Delphi community as I'm blocked with my project.

I am working with SynchroTeam API using their REST API. SynchroTeam API

I can successfully GET and POST data without any problem.
But I can't find out the right way to delete a job.. Delete a job

After downloading all jobs Object, I'm trying to delete some of them. So, I know ID, MyID and NUM properties of each Job.
However, when I'm using the following code:
 

RESTClient:= TRESTClient.Create('https://ws.synchroteam.com/api/v3');
with RESTClient do
begin
  Accept:= 'application/json';
  AcceptCharset:= 'UTF-8';
  Authenticator:= HTTPBasicAuthenticator;
  SecureProtocols := [THTTPSecureProtocol.TLS12];
end;

RESTRequest.Method:= TRESTRequestMethod.rmDELETE;
RESTRequest.Resource:= 'job/delete';
RESTRequest.AddParameter('Content-Type', 'application/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);
RESTRequest.AddParameter('Accept', 'text/json', TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);
RESTRequest.AddParameter('myId', '467925', TRESTRequestParameterKind.pkQUERY, [poDoNotEncode]);

RESTRequest.Execute;

I get the error 404: Job does not exists. I'm 100% sur about myId. I also tried with ID property: same result.
I also tried with all relevant TRESTRequestParameterKind for myId parameter. I always get 404
 

What would be the correct way to delete a record using Delphi REST.Client.TRESTRequest ?
Thank you for your help

Edited by Bob Baudewyns

Share this post


Link to post
Guest
6 hours ago, Bob Baudewyns said:

What would be the correct way to delete a record using Delphi REST.Client.TRESTRequest ?

I think that, in your specific case, the SyncroTeam API site/forum/support would be better choice for learn about this "specific" error message by server.

 

hug

Share this post


Link to post

This is the request captured with Fiddler

DELETE https://ws.synchroteam.com/api/v3/job/delete?myId=467927 HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json
Accept: text/json
Accept-Charset: UTF-8
Authorization: Basic XXXXXXXXXX
Cookie: incap_ses_466_1982613=JG+hNrWzP3ntmaXA4pB3BhU0SmAAAAAArMFLFUXF8+BXuhjHFDJEIA==; visid_incap_1982613=eLvuGVc7ToSqZT5dVRPkcRU0SmAAAAAAQUIPAAAAAADEtuE8tUgs/WIAYTcpXzLh; ASP.NET_SessionId=tpffwpqwj0pphbx5s3llzp3f
User-Agent: Embarcadero RESTClient/1.0
Content-Length: 348
Host: ws.synchroteam.com

And response

HTTP/1.1 404 Not Found
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/10.0
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1615476362
X-Quota-Limit: 15000
X-Quota-Remaining: 14679
Date: Thu, 11 Mar 2021 15:25:02 GMT
Content-Length: 66
X-CDN: Imperva
X-Iinfo: 10-12437416-12437480 SNNN RT(1615476301530 1054) q(0 0 0 -1) r(1 1) U6
{"error":"Not Found","message":"The requested Job does not exist"}

 

Share this post


Link to post

I have found my (stupid) mistake.

I still had another object (me as user) as body from another request. I corrected that using

 
RESTRequest.Body.ClearBody;
RESTRequest.Params.Clear;

Case closed

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×