Getting 400-bad request error, when post data via table rest api in powershell

zhanglixin
Tera Expert

I try to post data from one PDI to another using powershell(the script is copyed from the rest api explore page). 

 

1.I try to get data from one instance, the data return correctly.

zhanglixin_0-1704764683326.png

 

2.Then I edit the record in returned json and use as the body for the post method to post to another instance.

zhanglixin_2-1704764848569.png

 

3.when I run the powershell script, it returns 400 error code.

zhanglixin_3-1704764933225.png

 

4. However when I run the post method seperately. It runs OK.
I have confirmed the body data format is exactly the same.

zhanglixin_4-1704765034662.png

 

Anyone knows why this happens???


1 ACCEPTED SOLUTION

zhanglixin
Tera Expert

hi guys, thanks for replying. I have found the mistake.(I modified the script lightly.)
As I use a rest api to get some records from one instance and want to user import set rest api to post the other.
so I have to loop the records  as a string  and then  convert the string record to json to use as a body.
so I add the "$body1 = $item | convertto-json" sentence. The result runs OK.

zhanglixin_0-1704846722526.png

 

View solution in original post

5 REPLIES 5

zhanglixin
Tera Expert

hi guys, thanks for replying. I have found the mistake.(I modified the script lightly.)
As I use a rest api to get some records from one instance and want to user import set rest api to post the other.
so I have to loop the records  as a string  and then  convert the string record to json to use as a body.
so I add the "$body1 = $item | convertto-json" sentence. The result runs OK.

zhanglixin_0-1704846722526.png