1

I have a JSON script which at first Search for jobs with a specific attribute and then afterwards Get the job details.

For now the script is like this and is saved as a Postman collection:

{
    "info": {
        "_postman_id": "xxx",
        "name": "JOBAD Service",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "GetJob",
            "request": {
                "method": "POST",
                "header": [
                    {
                        "key": "SOAPAction",
                        "value": "http://xxx",
                        "type": "text"
                    },
                    {
                        "key": "Content-Type",
                        "value": "text/xml",
                        "type": "text"
                    }
                ],
                "body": {
                    "mode": "raw",
                    "raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:job=\"http://jobnet.af.dk/JobAdService\" xmlns:job1=\"http://schemas.datacontract.org/2004/07/JobAdService.DataContract\">\r\n   <soapenv:Header>\r\n      <job:Credentials>\r\n         <job1:Password>xxx</job1:Password>\r\n         <job1:Username>xxx</job1:Username>\r\n      </job:Credentials>\r\n   </soapenv:Header>\r\n   <soapenv:Body>\r\n      <job:GetJobRequestType>\r\n         <!--Optional:-->\r\n         <job:JobAdId>5490138</job:JobAdId>\r\n      </job:GetJobRequestType>\r\n   </soapenv:Body>\r\n</soapenv:Envelope>"
                },
                "url": {
                    "raw": "https://xxx.svc",
                    "protocol": "https",
                    "host": [
                        "xxx",
                        "xxx",
                        "dk"
                    ],
                    "path": [
                        "JobAdService",
                        "v3",
                        "JobAdService.svc"
                    ]
                }
            },
            "response": []
        },
        {
            "name": "SearchJob",
            "request": {
                "method": "POST",
                "header": [
                    {
                        "key": "Content-Type",
                        "value": "text/xml",
                        "type": "text"
                    },
                    {
                        "key": "SOAPAction",
                        "value": "http:xxx",
                        "type": "text"
                    }
                ],
                "body": {
                    "mode": "raw",
                    "raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:job=\"http://xxx" xmlns:job1=\"http://schemas.datacontract.org/2004/07/JobAdService.DataContract\">\r\n   <soapenv:Header>\r\n      <job:Credentials>\r\n         <job1:Password>xxx</job1:Password>\r\n         <job1:Username>xxx</job1:Username>\r\n      </job:Credentials>\r\n   </soapenv:Header>\r\n   <soapenv:Body>\r\n      <job:SearchJobRequestType>\r\n         <job:SearchParameters>\r\n            <job:CreatedFrom>2022-01-01T00:00:00+02:00</job:CreatedFrom>\r\n            <job:CreatedTo>2022-12-31T00:00:00+01:00</job:CreatedTo>\r\n            <job:JobAttributes>\r\n               <job:JobAttribute>Hotjob</job:JobAttribute>\r\n            </job:JobAttributes>\r\n            <job:Status>Publication</job:Status>\r\n         </job:SearchParameters>\r\n      </job:SearchJobRequestType>\r\n   </soapenv:Body>\r\n</soapenv:Envelope>"
                },
                "url": {
                    "raw": "https://xxx.svc",
                    "protocol": "https",
                    "host": [
                        "jobt1",
                        "jobnettest",
                        "dk"
                    ],
                    "path": [
                        "JobAdService",
                        "v3",
                        "JobAdService.svc"
                    ]
                }
            },
            "response": []
        }
    ]
}

How can I make this script fire in WordPress PHP and then store the file locally on the webserver in either XML or JSON with the response?

The Search method finds all the job ID's with the given attribute, and the Get method afterwards has to use these ID's to make a list of all the job details for each job.

1 Answer 1

0

Yeah, I was asking the same question. This is how ended up here. So I dig into it and I'm putting the right answer here to help other find the answer directly from here.

if you want to save the content above as text all you have to do:

file_put_contents( $thisFilename, $thisText );

If you want to save an object, array and so on. all you have to do:

$thisJson = json_encode( $thisObject );
file_put_contents( $thisFilename, $thisJson );

TADA! that's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.