- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 05:53 PM
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.
2.Then I edit the record in returned json and use as the body for the post method to post to another instance.
3.when I run the powershell script, it returns 400 error code.
4. However when I run the post method seperately. It runs OK.
I have confirmed the body data format is exactly the same.
Anyone knows why this happens???
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 04:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 10:21 PM
Hi @zhanglixin
Can you please post your consolidated script here ? Also, please make use of PowerShell ISE while editing PowerShell scripts as other editors unnecessarily introduces some special characters which create problems afterwards,
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 10:25 PM
Hi @zhanglixin
One more observation - You are converting the response received from a GET call to JSON. This is not required as the response is already in JSON. Request you to remove |Convertto-JSON and try once more.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 10:36 PM
something wrong with the request body
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:05 PM
Yes ,you are right. I missed to convert the string record to json. I corrected the script and post the answer. you can refer it if you are interested.